Skip to content

Commit

Permalink
python: Fix python-install on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Oct 19, 2023
1 parent a922fb5 commit 72db8e5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cmake/python-install.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ if(DEFINED ENV{DESTDIR})
# If DESTDIR is not absolute path, make it relative to @PROJECT_BINARY_DIR@
# like any install() command.
if(IS_ABSOLUTE $ENV{DESTDIR})
set(ROOT "--root=$ENV{DESTDIR}")
set(ROOT "--root='$ENV{DESTDIR}'")
else()
set(ROOT "--root=@PROJECT_BINARY_DIR@/$ENV{DESTDIR}")
set(ROOT "--root='@PROJECT_BINARY_DIR@/$ENV{DESTDIR}'")
endif()
else()
set(ROOT "")
Expand All @@ -13,7 +13,7 @@ endif()
# Check if we have system Python on Debian/Ubuntu, if so tell setuptools
# to use the deb layout (dist-packages instead of site-packages).
execute_process(
COMMAND @Python3_EXECUTABLE@ -c "import sys; sys.stdout.write(sys.path[-1])"
COMMAND "@Python3_EXECUTABLE@" -c "import sys; sys.stdout.write(sys.path[-1])"
OUTPUT_VARIABLE Python_STDLIB_DIR
)
if(Python_STDLIB_DIR MATCHES ".*/dist-packages$")
Expand All @@ -24,8 +24,8 @@ endif()

execute_process(
WORKING_DIRECTORY @PROJECT_BINARY_DIR@/python
COMMAND @Python3_EXECUTABLE@ setup.py install
COMMAND "@Python3_EXECUTABLE@" setup.py install
${ROOT}
--prefix=@CMAKE_INSTALL_PREFIX@
--prefix="@CMAKE_INSTALL_PREFIX@"
${SETUPTOOLS_INSTALL_LAYOUT}
)

1 comment on commit 72db8e5

@StefanBruens
Copy link
Contributor

Choose a reason for hiding this comment

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

This extraneous quoting breaks install on Linux, it creates paths like:

/home/abuild/rpmbuild/BUILD/or-tools-9.9/build/python/'/home/abuild/rpmbuild/BUILDROOT/google-or-tools-9.9-0.x86_64'/"/usr"/lib64/python3.11/site-packages/ortools-9.9.9999-py3.11.egg-info/PKG-INFO

The correct path would be /home/abuild/rpmbuild/BUILDROOT/google-or-tools-9.9-0.x86_64/usr/lib64/python3.11/site-packages/ortools-9.9.9999-py3.11.egg-info/PKG-INFO

As one can see, both the single quote from the (absolute) DESTDIR is taken verbatim, making the path relative for setup.py (it starts with '/..., not /...) so the CWD is prepended, and the prefix is also quoted.

Suggestions:

  1. Add "COMMAND_ECHO STDERR" to the execute_process invocation
  2. In case the Windows build fails to build due to missing quotes, add escaping where actually needed

This is the current command line executed:
'/usr/bin/python3.11' 'setup.py' 'install' '--root='/home/abuild/rpmbuild/BUILDROOT/google-or-tools-9.9-0.x86_64'' '--prefix="/usr"'

Please sign in to comment.