Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix symlink collision bug #3

wants to merge 1 commit into from

Conversation

olaaaf
Copy link

@olaaaf olaaaf commented Jul 26, 2024

Resolves #1

Tested with gtkmm

# 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:
Copy link

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.

Copy link

@dstu dstu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had been thinking along similar lines, but I'm not sure a simple fix like this is feasible. The name of the symlink that gets created is a load-bearing decision that affects the include path components.

if dest.exists:
dest = base.get_child(src.basename + src.dirname.basename)
if _symlink_no_duplicate(ctx, src, dest):
result += [str(dest)[rootlen:]]
Copy link

Choose a reason for hiding this comment

The 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 _symlinks is used, you should see that this changes how the strip_include option to the pkg_config rule works.

For example, consider a package with include paths /usr/include/x86_64-linux-gnu/MyPackage and /usr/include/MyPackage. It provides the include files /usr/include/x86_64-linux-gnu/MyPackage/my.h and /usr/include/MyPackage/package.h.

A user of the pkg_config Bazel rule might specify a strip_prefix value of MyPackage, so that they can just #include "my.h" and #include "package.h" directly.

Under this PR, Bazel will create symlinks named includes/MyPackage and includes/include/MyPackage or includes/x86_64-linux-gnu/MyPackage, depending on which gets created first. There is no single strip_prefix value that can correctly strip out both of these. Furthermore, the names of the symlinks that get created depends on the order in which they are created, which is undesirable for multiple reasons.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that makes a lot of sense; a strip_prefix or prefix (for adding a path prefix)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

_symlinks attempts to create multiple symbolic links to .../include
2 participants