Unverified Commit e30482e6 authored by Mislav Marohnić's avatar Mislav Marohnić Committed by GitHub
Browse files

Merge pull request #2296 from rbenv/verify-openssl

Instruct Ruby to fail the build if openssl or psych are missing
parents 4c46e63e 4a3ff7e1
Loading
Loading
Loading
Loading
+19 −42
Original line number Diff line number Diff line
@@ -673,6 +673,11 @@ build_package_standard_build() {
        package_option ruby configure --with-openssl-dir="/usr/local"
      fi
    fi
    if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-ext* &&
          "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--without-ext* ]]; then
      # Fail the `make` step if any of these extensions were not compiled.
      package_option ruby configure --with-ext=openssl,psych,+
    fi
  fi

  ( if [ "${CFLAGS+defined}" ] || [ "${!PACKAGE_CFLAGS+defined}" ]; then
@@ -687,9 +692,20 @@ build_package_standard_build() {
      "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" $CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS}
  ) || return $?

  local status=0
  # make -j <num_cpu_cores>
  # shellcheck disable=SC2086
  capture_command "$MAKE" "${!PACKAGE_MAKE_OPTS_ARRAY}" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS}
  capture_command "$MAKE" "${!PACKAGE_MAKE_OPTS_ARRAY}" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS} || status=$?

  if [[ $status -ne 0 && -z $VERBOSE ]]; then
    # Surface any extension building problems from `make` log to stderr.
    # https://github.com/ruby/ruby/blob/HEAD/ext/extmk.rb
    sed -n '/Following extensions are not compiled/,/Fix the problems/p' "$LOG_PATH" | \
      sed '/remove these directories and try again/d' | \
      sed "s:\\([[:space:]]*Check\\) \\(ext/.*\\):\\1 ${PWD}/\\2:" >&2
  fi

  return $status
}

build_package_standard_install() {
@@ -1214,48 +1230,9 @@ build_package_openssl() {
  fi
}

# Post-install check that the openssl extension was built.
# TODO: explore replacing this implementation with scanning the `make` log
# for the "Following extensions are not compiled" block.
# Kept for backward compatibility with 3rd-party definitions.
build_package_verify_openssl() {
  local msg
  msg="->$(print_command "$RUBY_BIN" -e "<SCRIPT>")"

  colorize 36 "$msg"
  echo

  # shellcheck disable=SC2016
  "$RUBY_BIN" -e '
    manager = ARGV[0]
    packages = {
      "apt-get" => Hash.new {|h,k| "lib#{k}-dev" }.update(
        "openssl" => "libssl-dev",
        "zlib" => "zlib1g-dev"
      ),
      "yum" => Hash.new {|h,k| "#{k}-devel" }.update(
        "yaml" => "libyaml-devel"
      )
    }
    ext_name = Hash.new {|h,k| k }.update("yaml" => "psych")

    failed = %w[openssl readline zlib yaml].reject do |lib|
      begin
        require lib
      rescue LoadError => e
        $stderr.puts "Loading the Ruby #{lib} extension failed (#{e})"
        $stderr.puts "See the extension log at #{Dir.pwd}/ext/#{ext_name[lib]}/mkmf.log"
      end
    end

    if failed.size > 0
      $stderr.puts "ERROR: Ruby install aborted due to missing extensions"
      $stderr.print "Try running `%s install -y %s` to fetch missing dependencies.\n\n" % [
        manager,
        failed.map { |lib| packages.fetch(manager)[lib] }.join(" ")
      ] unless manager.empty?
      exit 1
    end
  ' "$(basename "$(type -p yum apt-get | head -1)")"
  true
}

# Kept for backward compatibility with 3rd-party definitions.
+1 −1
Original line number Diff line number Diff line
@@ -26,5 +26,5 @@ fi

cat > "$file" <<EOS
!TODO! copy openssl line from other release with the same major.minor version
install_package "ruby-${version}" "${url}#${sha256}" enable_shared standard verify_openssl
install_package "ruby-${version}" "${url}#${sha256}" enable_shared standard
EOS
+1 −1
Original line number Diff line number Diff line
install_package "openssl-1.0.2u" "https://www.openssl.org/source/openssl-1.0.2u.tar.gz#ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16" openssl --if needs_openssl:0.9.6-1.0.x
install_git "ruby-2.0.0-dev" "https://github.com/ruby/ruby.git" "ruby_2_0_0" warn_eol autoconf standard verify_openssl
install_git "ruby-2.0.0-dev" "https://github.com/ruby/ruby.git" "ruby_2_0_0" warn_eol autoconf standard
+1 −1
Original line number Diff line number Diff line
install_package "yaml-0.1.6" "http://pyyaml.org/download/libyaml/yaml-0.1.6.tar.gz#7da6971b4bd08a986dd2a61353bc422362bd0edcc67d7ebaac68c95f74182749" --if needs_yaml
install_package "openssl-1.0.2u" "https://www.openssl.org/source/openssl-1.0.2u.tar.gz#ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16" openssl --if needs_openssl:0.9.6-1.0.x
install_package "ruby-2.0.0-p0" "https://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.bz2#c680d392ccc4901c32067576f5b474ee186def2fcd3fcbfa485739168093295f" warn_eol standard verify_openssl
install_package "ruby-2.0.0-p0" "https://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.bz2#c680d392ccc4901c32067576f5b474ee186def2fcd3fcbfa485739168093295f" warn_eol standard
+1 −1
Original line number Diff line number Diff line
install_package "yaml-0.1.6" "http://pyyaml.org/download/libyaml/yaml-0.1.6.tar.gz#7da6971b4bd08a986dd2a61353bc422362bd0edcc67d7ebaac68c95f74182749" --if needs_yaml
install_package "openssl-1.0.2u" "https://www.openssl.org/source/openssl-1.0.2u.tar.gz#ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16" openssl --if needs_openssl:0.9.6-1.0.x
install_package "ruby-2.0.0-p195" "https://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.bz2#0be32aef7a7ab6e3708cc1d65cd3e0a99fa801597194bbedd5799c11d652eb5b" warn_eol standard verify_openssl
install_package "ruby-2.0.0-p195" "https://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.bz2#0be32aef7a7ab6e3708cc1d65cd3e0a99fa801597194bbedd5799c11d652eb5b" warn_eol standard
Loading