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

Reapply [libcxx] [modules] Fix relative paths with absolute LIBCXX_INSTALL_MODULES_DIR #86020

Merged
merged 2 commits into from
Mar 21, 2024

Conversation

mstorsjo
Copy link
Member

This reapplies 272d1b4 (from #85756), which was reverted in
4079370.

In the previous attempt, empty CMAKE_INSTALL_PREFIX was handled by quoting them, in d209d13. That made the calls to cmake_path(ABSOLUTE_PATH) succeed, but the output paths of that weren't actually absolute, which was required by file(RELATIVE_PATH).

Avoid this issue by appending a slash to CMAKE_INSTALL_PREFIX, so we always get an absolute path, even if CMAKE_INSTALL_PREFIX was empty.

…STALL_MODULES_DIR

This reapplies 272d1b4
(from llvm#85756), which was reverted in
4079370.

In the previous attempt, empty CMAKE_INSTALL_PREFIX was handled
by quoting them, in d209d13.
That made the calls to cmake_path(ABSOLUTE_PATH) succeed, but the
output paths of that weren't actually absolute, which was
required by file(RELATIVE_PATH).

Avoid this issue by appending a slash to CMAKE_INSTALL_PREFIX,
so we always get an absolute path, even if CMAKE_INSTALL_PREFIX
was empty.
@mstorsjo mstorsjo requested a review from a team as a code owner March 20, 2024 22:22
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 20, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 20, 2024

@llvm/pr-subscribers-libcxx

Author: Martin Storsjö (mstorsjo)

Changes

This reapplies 272d1b4 (from #85756), which was reverted in
4079370.

In the previous attempt, empty CMAKE_INSTALL_PREFIX was handled by quoting them, in d209d13. That made the calls to cmake_path(ABSOLUTE_PATH) succeed, but the output paths of that weren't actually absolute, which was required by file(RELATIVE_PATH).

Avoid this issue by appending a slash to CMAKE_INSTALL_PREFIX, so we always get an absolute path, even if CMAKE_INSTALL_PREFIX was empty.


Full diff: https://github.com/llvm/llvm-project/pull/86020.diff

1 Files Affected:

  • (modified) libcxx/modules/CMakeLists.txt (+11-2)
diff --git a/libcxx/modules/CMakeLists.txt b/libcxx/modules/CMakeLists.txt
index 0dea8cfca94ac3..1d9c7518e9f801 100644
--- a/libcxx/modules/CMakeLists.txt
+++ b/libcxx/modules/CMakeLists.txt
@@ -206,9 +206,18 @@ add_custom_target(generate-cxx-modules
 # Configure the modules manifest.
 # Use the relative path between the installation and the module in the json
 # file. This allows moving the entire installation to a different location.
+#
+# Using a trailing slash in BASE_DIRECTORY, to produce a seemingly valid
+# absolute path, even if CMAKE_INSTALL_PREFIX is empty.
+cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_LIBRARY_DIR
+  BASE_DIRECTORY "${CMAKE_INSTALL_PREFIX}/"
+  OUTPUT_VARIABLE ABS_LIBRARY_DIR)
+cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_MODULES_DIR
+  BASE_DIRECTORY "${CMAKE_INSTALL_PREFIX}/"
+  OUTPUT_VARIABLE ABS_MODULES_DIR)
 file(RELATIVE_PATH LIBCXX_MODULE_RELATIVE_PATH
-  ${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_LIBRARY_DIR}
-  ${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_MODULES_DIR})
+  ${ABS_LIBRARY_DIR}
+  ${ABS_MODULES_DIR})
 configure_file(
   "modules.json.in"
   "${LIBCXX_LIBRARY_DIR}/libc++.modules.json"

Copy link
Contributor

@ilovepi ilovepi left a comment

Choose a reason for hiding this comment

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

LGTM. This seems like a sound approach to me but you may want to double check with Petr.

@mordante mordante self-assigned this Mar 21, 2024
# Using a trailing slash in BASE_DIRECTORY, to produce a seemingly valid
# absolute path, even if CMAKE_INSTALL_PREFIX is empty.
cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_LIBRARY_DIR
BASE_DIRECTORY "${CMAKE_INSTALL_PREFIX}/"
Copy link
Member

Choose a reason for hiding this comment

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

I wonder what happens when ${CMAKE_INSTALL_PREFIX} is "/", then we get "//". I'm not sure whether that is a valid path. How about something like

if(${CMAKE_INSTALL_PREFIX} STREQUAL "")
  set(BASE_DIRECTORY "/" PARENT_SCOPE)
else()
  set(BASE_DIRECTORY ${CMAKE_INSTALL_PREFIX} PARENT_SCOPE)
endif()

Copy link
Member Author

Choose a reason for hiding this comment

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

The double slash path here is effectively harmless; after cmake_path(ABSOLUTE_PATH), the output only has a single leading slash even in that case.

But you're right that it's probably nicer to be explicit about this.

Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

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

Thanks LGTM! Please wait for @petrhosek's approval before landing.

@mstorsjo
Copy link
Member Author

Thanks LGTM! Please wait for @petrhosek's approval before landing.

Sure, although I don't know if we need his extra input here any longer :-)

@mordante
Copy link
Member

Thanks LGTM! Please wait for @petrhosek's approval before landing.

Sure, although I don't know if we need his extra input here any longer :-)

I thought Petr had reported the issue with the previous version. It seems I was mistaken it was @ilovepi. Since @ilovepi has approved I'm happy to land it.

@ilovepi
Copy link
Contributor

ilovepi commented Mar 21, 2024

Yeah I think we’re good here. We definitely use an empty install directory so the fix makes sense to me. I’ll keep an eye on our ci, but I think our buildout should catch this too.

@mstorsjo mstorsjo merged commit 50801f1 into llvm:main Mar 21, 2024
51 checks passed
@mstorsjo mstorsjo deleted the libcxx-modules-abs-path branch March 21, 2024 15:30
@mstorsjo mstorsjo added this to the LLVM 18.X Release milestone Mar 21, 2024
@mstorsjo
Copy link
Member Author

FWIW, the fuchsia build seems to stay green now, so I'll request a backport of this again.

/cherry-pick 50801f1

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Mar 21, 2024
…STALL_MODULES_DIR (llvm#86020)

This reapplies 272d1b4 (from llvm#85756),
which was reverted in
4079370.

In the previous attempt, empty CMAKE_INSTALL_PREFIX was handled by
quoting them, in d209d13. That made the
calls to cmake_path(ABSOLUTE_PATH) succeed, but the output paths of that
weren't actually absolute, which was required by file(RELATIVE_PATH).

Avoid this issue by constructing a non-empty base directory variable
to use for calculating the relative path.

(cherry picked from commit 50801f1)
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 21, 2024

/pull-request #86197

chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
…STALL_MODULES_DIR (llvm#86020)

This reapplies 272d1b4 (from llvm#85756),
which was reverted in
4079370.

In the previous attempt, empty CMAKE_INSTALL_PREFIX was handled by
quoting them, in d209d13. That made the
calls to cmake_path(ABSOLUTE_PATH) succeed, but the output paths of that
weren't actually absolute, which was required by file(RELATIVE_PATH).

Avoid this issue by constructing a non-empty base directory variable
to use for calculating the relative path.
llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Mar 23, 2024
…STALL_MODULES_DIR (llvm#86020)

This reapplies 272d1b4 (from llvm#85756),
which was reverted in
4079370.

In the previous attempt, empty CMAKE_INSTALL_PREFIX was handled by
quoting them, in d209d13. That made the
calls to cmake_path(ABSOLUTE_PATH) succeed, but the output paths of that
weren't actually absolute, which was required by file(RELATIVE_PATH).

Avoid this issue by constructing a non-empty base directory variable
to use for calculating the relative path.

(cherry picked from commit 50801f1)
tstellar pushed a commit to llvmbot/llvm-project that referenced this pull request Mar 28, 2024
…STALL_MODULES_DIR (llvm#86020)

This reapplies 272d1b4 (from llvm#85756),
which was reverted in
4079370.

In the previous attempt, empty CMAKE_INSTALL_PREFIX was handled by
quoting them, in d209d13. That made the
calls to cmake_path(ABSOLUTE_PATH) succeed, but the output paths of that
weren't actually absolute, which was required by file(RELATIVE_PATH).

Avoid this issue by constructing a non-empty base directory variable
to use for calculating the relative path.

(cherry picked from commit 50801f1)
@pointhex pointhex mentioned this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
Development

Successfully merging this pull request may close these issues.

4 participants