-
Notifications
You must be signed in to change notification settings - Fork 487
Handle files from external repos (fix breaking change in Bazel 3.7.0) #2138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
2b529aa
c8bbfb8
0a85c6b
d046a6d
b245e57
d216ef9
17c9d01
5b90787
d30367f
e3895d4
4ff6df5
ef26d2f
e9e0a31
bb88bb8
a891183
8d0b467
923ac33
ae8c6ba
d24e2dc
0fa922e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,34 @@ def get_edition(attr, toolchain, label): | |
else: | ||
return toolchain.default_edition | ||
|
||
def _symlink_for_non_generated_source(ctx, src_file, package_root): | ||
"""Creates and returns a symlink for non-generated source files. | ||
|
||
This rule uses the full path to the source files and the rule directory to compute | ||
the relative paths. This is needed, instead of using `short_path`, because of non-generated | ||
source files in external repositories returning relative paths. | ||
|
||
Args: | ||
ctx (struct): The current rule's context. | ||
src_file (File): The source file. | ||
package_root (File): The full path to the directory containing the current rule. | ||
|
||
Returns: | ||
File: The created symlink if a non-generated file, or the file itself. | ||
""" | ||
|
||
if src_file.is_source or src_file.root.path != ctx.bin_dir.path: | ||
src_short_path = paths.relativize(src_file.path, src_file.root.path) | ||
src_symlink = ctx.actions.declare_file(paths.relativize(src_short_path, package_root)) | ||
ctx.actions.symlink( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small nit, can you put the action to symlink back in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly I'm not sure about it, there will be more duplicated logic and more lines. As a newcomer, I find it harder to read (I was not used to the previous implementation). Maybe I'm missing something and you have a much better proposal. I will work on the comment about the tests and come back here later to think about something better/easier. def _symlink_for_non_generated_source(ctx, src_file, package_root):
if src_file.is_source or src_file.root.path != ctx.bin_dir.path:
src_short_path = paths.relativize(src_file.path, src_file.root.path)
src_symlink = ctx.actions.declare_file(paths.relativize(src_short_path, package_root))
return src_symlink
else:
return None
def _transform_sources(ctx, srcs, crate_root):
has_generated_sources = len([src for src in srcs if not src.is_source]) > 0
if not has_generated_sources:
return srcs, crate_root
package_root = paths.dirname(paths.join(ctx.label.workspace_root, ctx.build_file_path))
generated_sources = []
for src_file in srcs:
if src_file == crate_root:
continue
src_symlink = _symlink_for_non_generated_source(ctx, src_file, package_root)
if src_symlink:
ctx.actions.symlink(
output = src_symlink,
target_file = src_file,
progress_message = "Creating symlink to source file: {}".format(src_file.path),
)
generated_sources.append(src_symlink)
else:
generated_sources.append(src_file)
generated_root = crate_root
if crate_root:
src_symlink = _symlink_for_non_generated_source(ctx, crate_root, package_root)
if src_symlink:
ctx.actions.symlink(
output = src_symlink,
target_file = crate_root,
progress_message = "Creating symlink to source file: {}".format(src_file.path),
)
generated_sources.append(src_symlink)
else:
generated_sources.append(crate_root)
return generated_sources, generated_root |
||
output = src_symlink, | ||
target_file = src_file, | ||
progress_message = "Creating symlink to source file: {}".format(src_file.path), | ||
) | ||
return src_symlink | ||
else: | ||
return src_file | ||
|
||
def _transform_sources(ctx, srcs, crate_root): | ||
"""Creates symlinks of the source files if needed. | ||
|
||
|
@@ -151,36 +179,13 @@ def _transform_sources(ctx, srcs, crate_root): | |
if not has_generated_sources: | ||
return srcs, crate_root | ||
|
||
generated_sources = [] | ||
|
||
package_root = paths.dirname(paths.join(ctx.label.workspace_root, ctx.build_file_path)) | ||
generated_sources = [_symlink_for_non_generated_source(ctx, src, package_root) for src in srcs if src != crate_root] | ||
generated_root = crate_root | ||
package_root = paths.dirname(ctx.build_file_path) | ||
|
||
if crate_root and (crate_root.is_source or crate_root.root.path != ctx.bin_dir.path): | ||
generated_root = ctx.actions.declare_file(paths.relativize(crate_root.short_path, package_root)) | ||
ctx.actions.symlink( | ||
output = generated_root, | ||
target_file = crate_root, | ||
progress_message = "Creating symlink to source file: {}".format(crate_root.path), | ||
) | ||
if generated_root: | ||
if crate_root: | ||
generated_root = _symlink_for_non_generated_source(ctx, crate_root, package_root) | ||
generated_sources.append(generated_root) | ||
|
||
for src in srcs: | ||
# We took care of the crate root above. | ||
if src == crate_root: | ||
continue | ||
if src.is_source or src.root.path != ctx.bin_dir.path: | ||
src_symlink = ctx.actions.declare_file(paths.relativize(src.short_path, package_root)) | ||
ctx.actions.symlink( | ||
output = src_symlink, | ||
target_file = src, | ||
progress_message = "Creating symlink to source file: {}".format(src.path), | ||
) | ||
generated_sources.append(src_symlink) | ||
else: | ||
generated_sources.append(src) | ||
|
||
return generated_sources, generated_root | ||
|
||
def _rust_library_impl(ctx): | ||
|
Uh oh!
There was an error while loading. Please reload this page.