I want a Bazel rule which creates a directory, takes a bunch of files, and creates an ISO out of that directory (the ISO is the intended output here, the other files are just byproducts).
# Declare root directory
root_directory = ctx.actions.declare_directory("root_directory")
# Call mkdir to create root directory
create_root_directory_arguments = ctx.actions.args()
create_root_directory_arguments.add(root_directory.path)
ctx.actions.run(
outputs = [root_directory],
arguments = [create_root_directory_arguments],
executable = "mkdir",
)
...
# Declare and collect inner files
copy_output_files = []
for image_file in image_files:
copy_output_file = ctx.actions.declare_file(image_file_path)
copy_output_files.append(copy_output_file)
# Call cp to copy the inner files into the root directory
copy_arguments = ctx.actions.args()
copy_arguments.add("-r")
copy_arguments.add("-t", root_directory.path)
for image_file in image_files:
copy_arguments.add(image_file.path)
ctx.actions.run(
inputs = [root_directory],
outputs = copy_output_files,
arguments = [copy_arguments],
executable = "cp",
)
...
The problem is that if I declare the directory abc
, I cannot declare the file abc/def
- I get an exception.
What is the intended solution here? Should I declare the folder alone? Just the files? How would I achieve the File
object for the run
call other than declaring?