From ac72249e04a7b0b78b39e6723ec9c43b1b434d4b Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 26 Jul 2021 15:40:11 +0200 Subject: [PATCH] Ensure it is safe to remove the prefix path for TruffleRuby or error * Only do clean_prefix_path for TruffleRuby and rename for clarity, since the logic is now TruffleRuby-specific. --- bin/ruby-build | 14 +++++++++++--- test/build.bats | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/ruby-build b/bin/ruby-build index ecba71e8a7..f8e29d5b1f 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -747,6 +747,7 @@ fix_jruby_shebangs() { } build_package_truffleruby() { + clean_prefix_path_truffleruby || return $? build_package_copy cd "${PREFIX_PATH}" @@ -754,7 +755,7 @@ build_package_truffleruby() { } build_package_truffleruby_graalvm() { - clean_prefix_path + clean_prefix_path_truffleruby || return $? build_package_copy_to "${PREFIX_PATH}/graalvm" cd "${PREFIX_PATH}/graalvm" @@ -792,7 +793,15 @@ remove_windows_files() { rm -f bin/*.exe bin/*.dll bin/*.bat bin/jruby.sh } -clean_prefix_path() { +clean_prefix_path_truffleruby() { + if [ -d "$PREFIX_PATH" ] && [ ! -e "$PREFIX_PATH/bin/truffleruby" ]; then + echo + echo "ERROR: cannot install TruffleRuby to $PREFIX_PATH, which does not look like a valid TruffleRuby prefix" >&2 + echo "TruffleRuby only supports being installed to a not existing directory or replacing an existing TruffleRuby installation" + echo "See https://github.com/oracle/truffleruby/issues/1389 for details" >&2 + return 1 + fi + # Make sure there are no leftover files in $PREFIX_PATH rm -rf "$PREFIX_PATH" } @@ -804,7 +813,6 @@ build_package_copy_to() { } build_package_copy() { - clean_prefix_path build_package_copy_to "$PREFIX_PATH" } diff --git a/test/build.bats b/test/build.bats index 588341d0d6..9049c6e4ae 100755 --- a/test/build.bats +++ b/test/build.bats @@ -664,6 +664,7 @@ DEF } @test "TruffleRuby post-install hook" { + rmdir "$INSTALL_ROOT" executable "${RUBY_BUILD_CACHE_PATH}/truffleruby-test/lib/truffle/post_install_hook.sh" <