-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix symlink collision bug #3
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -16,7 +16,9 @@ def _find_binary(ctx, binary_name): | |
return _success(binary) | ||
|
||
def _execute(ctx, binary, args): | ||
result = ctx.execute([binary] + args) | ||
result = ctx.execute( | ||
[binary] + args, | ||
) | ||
if result.return_code != 0: | ||
return _error("Failed execute {} {}".format(binary, args)) | ||
return _success(result.stdout) | ||
|
@@ -86,15 +88,28 @@ def _ignore_opts(opts, ignore_opts): | |
remain += [opt] | ||
return remain | ||
|
||
def _symlink_no_duplicate(ctx, src, dest): | ||
if not dest.exists: | ||
ctx.symlink(src, dest) | ||
return True | ||
return False | ||
|
||
def _symlinks(ctx, basename, srcpaths): | ||
result = [] | ||
root = ctx.path("") | ||
base = root.get_child(basename) | ||
rootlen = len(str(base)) - len(basename) | ||
for src in [ctx.path(p) for p in srcpaths]: | ||
dest = base.get_child(src.basename) | ||
ctx.symlink(src, dest) | ||
result += [str(dest)[rootlen:]] | ||
# if the directory already exists then: | ||
# 1) attempt to modify the name with the parent directory name | ||
# 2) if that fails don't create the symlink at all | ||
# we can sometimes skip symlink creation because of ocassional | ||
# duplicates in pkg_config output | ||
if dest.exists: | ||
dest = base.get_child(src.basename + src.dirname.basename) | ||
if _symlink_no_duplicate(ctx, src, dest): | ||
result += [str(dest)[rootlen:]] | ||
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. Modifying the name of the symlink that is created like this may lead to nondeterministic include path naming (or spooky action at a distance, where include path names depend on the order in which symlinks are created). Moreover, if you look at how the return value of For example, consider a package with include paths A user of the Under this PR, Bazel will create symlinks named 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. yes, that makes a lot of sense; a |
||
return result | ||
|
||
def _deps(ctx, pkg_config, pkg_name): | ||
|
@@ -192,3 +207,4 @@ pkg_config = repository_rule( | |
local = True, | ||
implementation = _pkg_config_impl, | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of just looking up 1 level in the directory tree, what do you think about generating unique identifiers from the complete srcpath? (For example:
s.replace("_", "__").replace("/", "_slash_")
?) This will be more robust to collisions in file paths.