|
|
@@ -4,9 +4,7 @@
|
|
|
|
|
|
"""Rule for producing a manifest for a filegroup."""
|
|
|
|
|
|
-def _manifest(ctx):
|
|
|
- out = ctx.actions.declare_file(ctx.label.name)
|
|
|
-
|
|
|
+def _get_files(ctx):
|
|
|
files = []
|
|
|
for src in ctx.attr.srcs:
|
|
|
files.extend([f.path for f in src[DefaultInfo].files.to_list()])
|
|
|
@@ -17,11 +15,16 @@ def _manifest(ctx):
|
|
|
|
|
|
if ctx.attr.strip_package_dir:
|
|
|
package_dir = ctx.label.package + "/"
|
|
|
- content = [f.removeprefix(package_dir) for f in files]
|
|
|
+ files_stripped = [f.removeprefix(package_dir) for f in files]
|
|
|
else:
|
|
|
- content = files
|
|
|
+ files_stripped = files
|
|
|
|
|
|
- ctx.actions.write(out, "\n".join(content) + "\n")
|
|
|
+ return files_stripped
|
|
|
+
|
|
|
+def _manifest(ctx):
|
|
|
+ out = ctx.actions.declare_file(ctx.label.name)
|
|
|
+ files = _get_files(ctx)
|
|
|
+ ctx.actions.write(out, "\n".join(files) + "\n")
|
|
|
|
|
|
return [
|
|
|
DefaultInfo(
|
|
|
@@ -30,6 +33,7 @@ def _manifest(ctx):
|
|
|
),
|
|
|
]
|
|
|
|
|
|
+# Produces the manifest as a series of lines.
|
|
|
manifest = rule(
|
|
|
implementation = _manifest,
|
|
|
attrs = {
|
|
|
@@ -37,3 +41,38 @@ manifest = rule(
|
|
|
"strip_package_dir": attr.bool(default = False),
|
|
|
},
|
|
|
)
|
|
|
+
|
|
|
+def _manifest_as_cpp(ctx):
|
|
|
+ out = ctx.actions.declare_file(ctx.label.name)
|
|
|
+ files = _get_files(ctx)
|
|
|
+ lines = [
|
|
|
+ "// Auto-generated by manifest_as_cpp.",
|
|
|
+ "const char* {0}[] = {{".format(ctx.attr.var_name),
|
|
|
+ ]
|
|
|
+ lines += [
|
|
|
+ " \"{0}\",".format(file)
|
|
|
+ for file in files
|
|
|
+ ]
|
|
|
+ lines += [
|
|
|
+ " nullptr,",
|
|
|
+ "};",
|
|
|
+ ]
|
|
|
+ ctx.actions.write(out, "\n".join(lines) + "\n")
|
|
|
+
|
|
|
+ return [
|
|
|
+ DefaultInfo(
|
|
|
+ files = depset(direct = [out]),
|
|
|
+ runfiles = ctx.runfiles(files = [out]),
|
|
|
+ ),
|
|
|
+ ]
|
|
|
+
|
|
|
+# Produces the manifest as a nullptr-terminated `const char* var_name[]`.
|
|
|
+# Use with `extern const char* var_name[];`.
|
|
|
+manifest_as_cpp = rule(
|
|
|
+ implementation = _manifest_as_cpp,
|
|
|
+ attrs = {
|
|
|
+ "srcs": attr.label_list(allow_files = True, mandatory = True),
|
|
|
+ "strip_package_dir": attr.bool(default = False),
|
|
|
+ "var_name": attr.string(mandatory = True),
|
|
|
+ },
|
|
|
+)
|