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

Make dependency files deterministic #11818

Closed
wants to merge 1 commit into from

Conversation

thii
Copy link
Member

@thii thii commented Jul 22, 2020

The dependency file generated by Clang can sometimes contain absolute
paths to system headers, system modules and files generated by Bazel
during the build. These paths can defer between machines and between
Bazel instances, for example:

bazel-out/apl-darwin_x86_64-fastbuild/bin/_objs/B/arc/B.o: B.m \
  /private/var/tmp/_bazel_user/b4422045cf7215be2d3fa4e439c7376a/sandbox/darwin-sandbox/214/execroot/__main__/bazel-out/apl-darwin_x86_64-fastbuild/bin/A.modulemap \
  /Applications/Xcode-11.6.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Modules/module.modulemap

This patch adds a post-process to wrapped_clang to normalize those paths
by:

  • converting absolute paths to relative paths for paths to files under
    the execution root
  • standardizing the paths to system headers, system modules to always
    use the standard location of Xcode (/Applications/Xcode.app). The
    user doesn't need to have Xcode installed to this location as Bazel are
    already mapping them to the correct location locally.

This makes the produced .d files deterministic and can reliably be
shared with the remote cache.

Fixes #11817.

@thii thii force-pushed the deterministic-dep-file branch from cd36dce to fef1f83 Compare July 22, 2020 07:18
The dependency file generated by Clang can sometimes contain absolute
paths to system headers, system modules and files generated by Bazel
during the build.  These paths can defer between machines and between
Bazel instances, for example:

```
bazel-out/apl-darwin_x86_64-fastbuild/bin/_objs/B/arc/B.o: B.m \
  /private/var/tmp/_bazel_user/b4422045cf7215be2d3fa4e439c7376a/sandbox/darwin-sandbox/214/execroot/__main__/bazel-out/apl-darwin_x86_64-fastbuild/bin/A.modulemap \
  /Applications/Xcode-11.6.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Modules/module.modulemap
```

This patch adds a post-process to wrapped_clang to normalize those paths
by:

* converting absolute paths to relative paths for paths to files under
the execution root
* standardizing the paths to system headers, system modules to always
use the standard location of Xcode (`/Applications/Xcode.app`).  The
user doesn't need to have Xcode installed to this location as Bazel are
already mapping them to the correct location locally.

This makes the produced `.d` files deterministic and can reliably be
shared with the remote cache.

Fixes bazelbuild#11817.
@thii thii force-pushed the deterministic-dep-file branch from fef1f83 to 649b7c4 Compare July 22, 2020 07:20
@keith
Copy link
Member

keith commented Jul 22, 2020

So it doesn't matter when downloading these files if these paths are valid? Maybe we should remove the Xcode prefix entirely?

@thii
Copy link
Member Author

thii commented Jul 22, 2020

Removing the Xcode prefix breaks the builds. It seems Bazel needs it for remapping.

@thii
Copy link
Member Author

thii commented Jul 23, 2020

@trybka Hi. Could you take a look or request a review for this?

@oquenchil oquenchil added the team-Rules-CPP Issues for C++ rules label Jul 28, 2020
@jin
Copy link
Member

jin commented Oct 26, 2020

Hi @trybka, @googlewalt and/or @bbarenblat, could you take a brief look and share if this change makes sense?

@trybka
Copy link
Contributor

trybka commented Oct 26, 2020

See comment here: #11817 (comment)

Notably, if these are harmless, it seems wasteful to clean them up in this manner.

@jin jin assigned thii Oct 27, 2020
@thii thii closed this Nov 19, 2020
@thii thii deleted the deterministic-dep-file branch November 19, 2020 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-Rules-CPP Issues for C++ rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Absolute paths embedded in dependency files
6 participants