From 2f9cb05c9a6dfc0e2ac9805a23a1becf72f7fff6 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Thu, 24 Oct 2024 18:06:44 +0200 Subject: [PATCH] WIP --- .gitlab/install_datadog_deps.rb | 87 ++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/.gitlab/install_datadog_deps.rb b/.gitlab/install_datadog_deps.rb index 1f9b254f163..70ac140266c 100755 --- a/.gitlab/install_datadog_deps.rb +++ b/.gitlab/install_datadog_deps.rb @@ -1,57 +1,57 @@ -require 'open3' -require 'rubygems' -require 'bundler' -require 'fileutils' -require 'pathname' +require "open3" +require "rubygems" +require "bundler" +require "fileutils" +require "pathname" -puts '=== RUBY_VERSION ===' +puts "=== RUBY_VERSION ===" puts RUBY_VERSION -puts '=== RUBY_ENGINE ===' +puts "=== RUBY_ENGINE ===" puts RUBY_ENGINE -puts '=== RUBY_ENGINE_VERSION ===' +puts "=== RUBY_ENGINE_VERSION ===" puts RUBY_ENGINE_VERSION -puts '=== RUBY_PLATFORM ===' +puts "=== RUBY_PLATFORM ===" puts RUBY_PLATFORM -puts '=== GEM PLATFORM ===' +puts "=== GEM PLATFORM ===" puts Gem::Platform.local ruby_api_version = Gem.ruby_api_version -puts '=== RUBY API VERISON ===' +puts "=== RUBY API VERISON ===" puts ruby_api_version current_path = Pathname.new(FileUtils.pwd) -tmp_path = current_path.join('tmp', ENV["ARCH"]) +tmp_path = current_path.join("tmp", ENV["ARCH"]) versioned_path = tmp_path.join(ruby_api_version) FileUtils.mkdir_p(versioned_path, verbose: true) -gemfile_file_path = versioned_path.join('Gemfile') +gemfile_file_path = versioned_path.join("Gemfile") -File.open(gemfile_file_path, 'w') do |file| +File.open(gemfile_file_path, "w") do |file| file.write("source 'https://rubygems.org'\n") - file.write("gem 'datadog', '#{ENV.fetch('RUBY_PACKAGE_VERSION')}', path: '#{current_path}'\n") + file.write("gem 'datadog', '#{ENV.fetch("RUBY_PACKAGE_VERSION")}', path: '#{current_path}'\n") file.write("gem 'ffi', '1.16.3'\n") # Mimick outdated `msgpack` version, uncomment below line to test # file.write("gem 'msgpack', '1.6.0'\n") end -puts '=== Reading Gemfile ===' +puts "=== Reading Gemfile ===" File.foreach(gemfile_file_path) { |x| puts x } puts "=== Reading Gemfile ===\n" -puts '=== bundle lock ===' -output, status = Open3.capture2e({ 'BUNDLE_GEMFILE' => gemfile_file_path.to_s }, 'bundle lock') +puts "=== bundle lock ===" +output, status = Open3.capture2e({"BUNDLE_GEMFILE" => gemfile_file_path.to_s}, "bundle lock") puts output puts "=== bundle lock ===\n" exit 1 unless status.success? -lock_file_path = versioned_path.join('Gemfile.lock') +lock_file_path = versioned_path.join("Gemfile.lock") -puts '=== Reading Lockfile ===' +puts "=== Reading Lockfile ===" File.foreach(lock_file_path) { |x| puts x } puts "=== Reading Lockfile ===\n" @@ -64,35 +64,35 @@ puts gem_version_mapping env = { - 'GEM_HOME' => versioned_path.to_s, + "GEM_HOME" => versioned_path.to_s, # Install `datadog` gem locally without its profiling native extension - 'DD_PROFILING_NO_EXTENSION' => 'true', + "DD_PROFILING_NO_EXTENSION" => "true" } [ - 'datadog-ruby_core_source', - 'ffi', - 'libddwaf', - 'msgpack', - 'libdatadog', # libdatadog MUST be installed before datadog to ensure libdatadog native extension is compiled - 'datadog', + "datadog-ruby_core_source", + "ffi", + "libddwaf", + "msgpack", + "libdatadog", # libdatadog MUST be installed before datadog to ensure libdatadog native extension is compiled + "datadog" ].each do |gem| version = gem_version_mapping.delete(gem) - gem_install_cmd = "gem install #{gem} "\ - "--version #{version} "\ - '--no-document '\ - '--ignore-dependencies ' + gem_install_cmd = "gem install #{gem} " \ + "--version #{version} " \ + "--no-document " \ + "--ignore-dependencies " case gem - when 'ffi' + when "ffi" # Install `ffi` gem with its built-in `libffi` native extension instead of using system's `libffi` - gem_install_cmd << '-- --disable-system-libffi ' - when 'datadog' + gem_install_cmd << "-- --disable-system-libffi " + when "datadog" gem_install_cmd = - "gem install --local #{ENV.fetch('DATADOG_GEM_LOCATION')} "\ - '--no-document '\ - '--ignore-dependencies '\ + "gem install --local #{ENV.fetch("DATADOG_GEM_LOCATION")} " \ + "--no-document " \ + "--ignore-dependencies " \ end puts "Execute: #{gem_install_cmd}" @@ -106,14 +106,21 @@ end end -raise "#{gem_version_mapping.keys.join(',')} are not installed." if gem_version_mapping.any? +raise "#{gem_version_mapping.keys.join(",")} are not installed." if gem_version_mapping.any? -datadog_gem_path = versioned_path.join("gems/datadog-#{ENV.fetch('RUBY_PACKAGE_VERSION')}") +datadog_gem_path = versioned_path.join("gems/datadog-#{ENV.fetch("RUBY_PACKAGE_VERSION")}") libdatadog_so_file = "libdatadog_api.#{RUBY_VERSION[/\d+.\d+/]}_#{RUBY_PLATFORM}.so" unless File.exist?("#{datadog_gem_path}/lib/#{libdatadog_so_file}") raise "Missing #{libdatadog_so_file} in #{datadog_gem_path}." end +FileUtils.rm_r( + [ + versioned_path.join("cache"), + versioned_path.join("gems/ffi-1.16.3/ext/ffi_c/libffi/testsuite") + ] +) + FileUtils.cd(versioned_path.join("extensions/#{Gem::Platform.local}"), verbose: true) do # Symlink those directories to be utilized by Ruby compiled with shared libraries FileUtils.ln_sf Gem.extension_api_version, ruby_api_version