Skip to content

Commit a612d04

Browse files
committed
CDRIVER-2827 fix uninstall path for DESTDIR
1 parent 522c558 commit a612d04

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,7 @@ tasks:
15981598
script: |
15991599
set -o xtrace
16001600
set -o errexit
1601+
DESTDIR="$(pwd)/dest" sh ./.evergreen/install-uninstall-check.sh
16011602
BSON_ONLY=1 sh ./.evergreen/install-uninstall-check.sh
16021603
sh ./.evergreen/install-uninstall-check.sh
16031604
# }}}

.evergreen/install-uninstall-check.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ fi
1919

2020
if [ "$BSON_ONLY" ]; then
2121
BUILD_DIR=$(pwd)/build-dir-bson
22-
INSTALL_DIR=$(pwd)/install-dir-bson
22+
INSTALL_PREFIX=$(pwd)/install-dir-bson
2323
else
2424
BUILD_DIR=$(pwd)/build-dir-mongoc
25-
INSTALL_DIR=$(pwd)/install-dir-mongoc
25+
INSTALL_PREFIX=$(pwd)/install-dir-mongoc
26+
fi
27+
28+
if [ "$DESTDIR" ]; then
29+
INSTALL_DIR="${DESTDIR}/${INSTALL_PREFIX}"
30+
else
31+
INSTALL_DIR=$INSTALL_PREFIX
2632
fi
2733

2834
rm -rf $BUILD_DIR
@@ -41,9 +47,13 @@ else
4147
fi
4248

4349

44-
$CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCMAKE_PREFIX_PATH=$INSTALL_DIR/lib/cmake $BSON_ONLY_OPTION .
50+
$CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DCMAKE_PREFIX_PATH=$INSTALL_DIR/lib/cmake $BSON_ONLY_OPTION .
4551
make
46-
make install
52+
if [ "$DESTDIR" ]; then
53+
make DESTDIR=$DESTDIR install
54+
else
55+
make install
56+
fi
4757
touch $INSTALL_DIR/lib/canary.txt
4858

4959
ls -l $INSTALL_DIR/share/mongo-c-driver

CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,10 @@ if (WIN32)
341341
else ()
342342
set (UNINSTALL_PROG "uninstall.sh")
343343
endif ()
344-
set (UNINSTALL_PROG_DIR "${CMAKE_INSTALL_FULL_DATADIR}/mongo-c-driver")
344+
set (UNINSTALL_PROG_DIR "${CMAKE_INSTALL_DATADIR}/mongo-c-driver")
345345

346346
# Create uninstall program and associated uninstall target
347347
#
348348
# This needs to be last (after all other add_subdirectory calls) to ensure that
349349
# the generated uninstall program is complete and correct
350-
add_subdirectory (generate_uninstall)
351-
352-
add_custom_target (uninstall
353-
COMMAND "${UNINSTALL_PROG_DIR}/${UNINSTALL_PROG}"
354-
)
350+
add_subdirectory (generate_uninstall)

build/generate-uninstall.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ if [ "${prefix}" = "${prefix%/}" ]; then
5151
prefix="${prefix}/"
5252
fi
5353

54+
# If a DESTDIR is specified, ensure it ends with a trailing slash.
55+
if [ "${DESTDIR}" ]; then
56+
if [ "${DESTDIR}" = "${DESTDIR%/}" ]; then
57+
# Trailing slash was omitted, so add it here
58+
DESTDIR="${DESTDIR}/"
59+
fi
60+
fi
61+
62+
5463
printf "#!/bin/sh\n"
5564
printf "# Mongo C Driver uninstall program, generated with CMake"
5665
printf "\n"
@@ -69,7 +78,7 @@ printf "# See the License for the specific language governing permissions and\n"
6978
printf "# limitations under the License.\n"
7079
printf "\n"
7180
printf "save_pwd=\$(pwd)\n"
72-
printf "cd %s\n" "${prefix}"
81+
printf "cd %s\n" "${DESTDIR}${prefix}"
7382
printf "\n"
7483

7584
dirs=
@@ -96,8 +105,8 @@ echo "${dirs}" | sort -ru | while IFS= read -r dir; do
96105
done
97106

98107
printf "cd ..\n"
99-
printf "printf \"Removing top-level installation directory: \\\"%s\\\"\"\n" "${prefix}"
100-
printf "(rmdir \"%s\" 2>/dev/null && printf \"\\\n\") || printf \" ... not removed (probably not empty)\\\n\"\n" "${prefix}"
108+
printf "printf \"Removing top-level installation directory: \\\"%s\\\"\"\n" "${DESTDIR}${prefix}"
109+
printf "(rmdir \"%s\" 2>/dev/null && printf \"\\\n\") || printf \" ... not removed (probably not empty)\\\n\"\n" "${DESTDIR}${prefix}"
101110
printf "\n"
102111
printf "# Return to the directory from which the program was called\n"
103112
printf "cd \${save_pwd}\n"

generate_uninstall/CMakeLists.txt

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Fabricate our own copy of the install manifest, since the installation has not
22
# generated the final version yet at this point
3-
install (CODE "file (MAKE_DIRECTORY \"${UNINSTALL_PROG_DIR}\")")
3+
4+
set (UNINSTALL_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
45

56
if (WIN32)
67
string (REPLACE "/" "\\\\" CMAKE_INSTALL_PREFIX_WIN32
@@ -23,13 +24,8 @@ if (WIN32)
2324
OUTPUT_FILE
2425
\"${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}\"
2526
)
26-
execute_process (
27-
COMMAND
28-
${CMAKE_COMMAND} -E copy
29-
\"${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}\"
30-
\"${UNINSTALL_PROG_DIR}/${UNINSTALL_PROG}\"
31-
)
3227
")
28+
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}" DESTINATION "${UNINSTALL_PROG_DIR}" PERMISSIONS ${UNINSTALL_PERMISSIONS})
3329
else ()
3430
install (CODE "
3531
string(REPLACE \";\" \"\\n\" MONGOC_INSTALL_MANIFEST_CONTENT
@@ -45,14 +41,10 @@ else ()
4541
OUTPUT_FILE
4642
\"${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}\"
4743
)
48-
execute_process (
49-
COMMAND
50-
chmod a+x \"${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}\"
51-
COMMAND
52-
cp
53-
\"${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}\"
54-
\"${UNINSTALL_PROG_DIR}/${UNINSTALL_PROG}\"
55-
)
5644
")
45+
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}" DESTINATION "${UNINSTALL_PROG_DIR}" PERMISSIONS ${UNINSTALL_PERMISSIONS})
5746
endif ()
5847

48+
add_custom_target (uninstall
49+
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}"
50+
)

0 commit comments

Comments
 (0)