-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 print module manifest file for macos #122370
Fix print module manifest file for macos #122370
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Bill Hoffman (billhoffman) ChangesThis commit fixes -print-library-module-manifest-path on macos. Currently, this only works on linux systems. This is because on macos systems the library and header files are installed in a different location. The module manifest is next to the libraries and the search function was not looking in both places. There is also a test included. Full diff: https://github.com/llvm/llvm-project/pull/122370.diff 2 Files Affected:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 04f2664ffeaddb..15de7b62adb235 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6380,6 +6380,11 @@ std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const {
if (llvm::sys::fs::exists(Twine(R)))
return std::string(R);
+ SmallString<128> R2(ResourceDir);
+ llvm::sys::path::append(R2, "..", "..", Name);
+ if (llvm::sys::fs::exists(Twine(R2)))
+ return std::string(R2);
+
SmallString<128> P(TC.getCompilerRTPath());
llvm::sys::path::append(P, Name);
if (llvm::sys::fs::exists(Twine(P)))
diff --git a/clang/test/Driver/modules-print-library-module-manifest-path.cpp b/clang/test/Driver/modules-print-library-module-manifest-path.cpp
index 3ba2709ad95cc8..8d17fe1549e34b 100644
--- a/clang/test/Driver/modules-print-library-module-manifest-path.cpp
+++ b/clang/test/Driver/modules-print-library-module-manifest-path.cpp
@@ -18,6 +18,28 @@
// RUN: --target=x86_64-linux-gnu 2>&1 \
// RUN: | FileCheck libcxx.cpp
+// for macos there is a different directory structure
+// where the library and libc++.modules.json file are in lib
+// directly but headers are in clang/ver directory which
+// is the resource directory
+// RUN: mkdir -p %t/Inputs/usr/lib/clang/20
+// RUN: touch %t/Inputs/usr/lib/libc++.so
+// RUN: touch %t/Inputs/usr/lib/libc++.modules.json
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: -resource-dir=%t/Inputs/usr/lib/clang/20 \
+// RUN: --target=arm64-apple-darwin24.1.0 2>&1 \
+// RUN: | FileCheck libcxx.cpp.macos
+
+// RUN: rm %t/Inputs/usr/lib/libc++.so
+// RUN: touch %t/Inputs/usr/lib/libc++.a
+// RUN: touch %t/Inputs/usr/lib/libc++.modules.json
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: -resource-dir=%t/Inputs/usr/lib/clang/20 \
+// RUN: --target=arm64-apple-darwin24.1.0 2>&1 \
+// RUN: | FileCheck libcxx.cpp.macos
+
// RUN: rm %t/Inputs/usr/lib/x86_64-linux-gnu/libc++.so
// RUN: touch %t/Inputs/usr/lib/x86_64-linux-gnu/libc++.a
// RUN: %clang -print-library-module-manifest-path \
@@ -40,6 +62,10 @@
// CHECK: {{.*}}/Inputs/usr/lib/x86_64-linux-gnu{{/|\\}}libc++.modules.json
+//--- libcxx.cpp.macos
+
+// CHECK: {{.*}}libc++.modules.json
+
//--- libcxx-no-shared-lib.cpp
// Note this might find a different path depending whether search path
|
clang/lib/Driver/Driver.cpp
Outdated
SmallString<128> R2(ResourceDir); | ||
llvm::sys::path::append(R2, "..", "..", Name); | ||
if (llvm::sys::fs::exists(Twine(R2))) | ||
return std::string(R2); |
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.
Can you move this in front of return std::string(Name);
?
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.
OK, I just moved it and did a force push. Makes sense to try this as the last thing. Less likely to break something else.
225287d
to
231a1ef
Compare
@billhoffman Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/11/builds/10935 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/4/builds/4570 Here is the relevant piece of the build log for the reference
|
This commit fixes -print-library-module-manifest-path on macos. Currently, this only works on linux systems. This is because on macos systems the library and header files are installed in a different location. The module manifest is next to the libraries and the search function was not looking in both places. There is also a test included.
Should this be backported to older supported releases as well? (FWIW, I think so.) |
/cherry-pick acbd822 |
But I am not sure if there is still release there. |
/pull-request #122844 |
This commit fixes -print-library-module-manifest-path on macos. Currently, this only works on linux systems. This is because on macos systems the library and header files are installed in a different location. The module manifest is next to the libraries and the search function was not looking in both places. There is also a test included. (cherry picked from commit acbd822)
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.
Deontae
This commit fixes -print-library-module-manifest-path on macos. Currently, this only works on linux systems. This is because on macos systems the library and header files are installed in a different location. The module manifest is next to the libraries and the search function was not looking in both places. There is also a test included.