Last active
May 24, 2019 20:46
-
-
Save enriched/52c43de4a668433af83e817f42067ab9 to your computer and use it in GitHub Desktop.
Copy Bazel Output to Workspace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COPY_TEMPLATE = """\ | |
#!/bin/bash | |
FROM_PATH="$PWD/{copy_from}" | |
TO_PATH="$BUILD_WORKSPACE_DIRECTORY/{to}/" | |
echo "Copying from $FROM_PATH to $TO_PATH" | |
cp -f $FROM_PATH $TO_PATH | |
""" | |
def _copy_to_workspace_impl(ctx): | |
copy_file = ctx.file.file | |
copy_runfile_path = copy_file.short_path | |
copy_to = ctx.attr.file.label.package | |
script = ctx.actions.declare_file(ctx.label.name) | |
script_content = COPY_TEMPLATE.format( | |
copy_from = copy_runfile_path, | |
to = copy_to, | |
) | |
ctx.actions.write(script, script_content, is_executable = True) | |
runfiles = ctx.runfiles(files = [copy_file]) | |
return [DefaultInfo(executable = script, runfiles = runfiles)] | |
copy_to_workspace = rule( | |
implementation = _copy_to_workspace_impl, | |
attrs = { | |
"file": attr.label(allow_single_file = True), | |
}, | |
executable = True, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment