diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index efc0feb1b6..5ccc7a0a68 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -60,7 +60,6 @@ local-linux.Dockerfile @DataDog/libdatadog NOTICE @DataDog/libdatadog README.md @DataDog/libdatadog repository.datadog.yml @DataDog/apm-common-components-core -ruby/ @DataDog/ruby-guild rustfmt.toml @DataDog/libdatadog-core scripts/check_cargo_metadata.sh @DataDog/libdatadog-core scripts/commits-since-release.sh @DataDog/libdatadog-core diff --git a/.github/workflows/publish-ruby.yml b/.github/workflows/publish-ruby.yml deleted file mode 100644 index b98f918152..0000000000 --- a/.github/workflows/publish-ruby.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Publish Ruby gem -on: workflow_dispatch - -concurrency: "publish-ruby" # Only one publish job at a time - -jobs: - publish-ruby: - name: Build and push gem to RubyGems.org - runs-on: ubuntu-24.04 - environment: "publish-ruby" # see: https://github.com/datadog/libdatadog/settings/environments - permissions: - id-token: write # Required for trusted publishing, see https://github.com/rubygems/release-gem - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Set up publish environment # This is needed to allow the following steps to run from the root of the repository - run: | - echo 'eval_gemfile("ruby/gems.rb")' > Gemfile - cp ruby/publish/rakefile.rb . - ln -sf ruby/pkg/ pkg - - name: Set up Ruby - uses: ruby/setup-ruby@e34163cd15f4bb403dcd72d98e295997e6a55798 # v1.238.0 - with: - ruby-version: 'ruby' - bundler-cache: true - - name: Install dependencies - run: bundle install - - uses: rubygems/release-gem@1c162a739e8b4cb21a676e97b087e8268d8fc40b # v1.1.2 diff --git a/.github/workflows/test-ruby.yml b/.github/workflows/test-ruby.yml deleted file mode 100644 index 386645856f..0000000000 --- a/.github/workflows/test-ruby.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Ruby gem scaffolding -on: - push: - paths: - - 'ruby/**' # Only run action when ruby-related things are touched - -jobs: - test: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest] - # Removed the head line for now because it's throwing CI errors - # ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4', head] - ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4'] - exclude: - # Ruby 2.5 and 2.6 are not available on macos-latest (ARM) - - os: macos-latest - ruby: '2.5' - - os: macos-latest - ruby: '2.6' - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 - - uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # 1.244.0 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - working-directory: ruby/ - - run: cd ruby && bundle exec rake diff --git a/ruby/.gitignore b/ruby/.gitignore deleted file mode 100644 index 334ce71a5b..0000000000 --- a/ruby/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -/.bundle/ -/.yardoc -/_yardoc/ -/coverage/ -/doc/ -/pkg/ -/spec/reports/ -/tmp/ - -# rspec failure tracking -.rspec_status - -gems.locked - -vendor/ diff --git a/ruby/.rspec b/ruby/.rspec deleted file mode 100644 index 34c5164d9b..0000000000 --- a/ruby/.rspec +++ /dev/null @@ -1,3 +0,0 @@ ---format documentation ---color ---require spec_helper diff --git a/ruby/.standard.yml b/ruby/.standard.yml deleted file mode 100644 index 01a5af7696..0000000000 --- a/ruby/.standard.yml +++ /dev/null @@ -1,3 +0,0 @@ -# For available configuration options, see: -# https://github.com/testdouble/standard -ruby_version: 2.1 diff --git a/ruby/README.md b/ruby/README.md deleted file mode 100644 index 29760ac4f6..0000000000 --- a/ruby/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# libdatadog Ruby gem - -`libdatadog` provides a shared library containing common code used in the implementation of Datadog's libraries, -including [Continuous Profilers](https://docs.datadoghq.com/tracing/profiler/). - -**NOTE**: If you're building a new Datadog library/profiler or want to contribute to Datadog's existing tools, you've come to the -right place! -Otherwise, this is possibly not the droid you were looking for. - -## Development - -Run `bundle exec rake` to run the tests and the style autofixer. -You can also run `bundle exec pry` for an interactive prompt that will allow you to experiment. - -### Testing packaging locally - -You can use `bundle exec rake package` to generate packages locally without publishing them. - -TIP: If the test that checks for permissions ("gem release process ... sets the right permissions on the gem files"), fails you -may need to run `umask 0022 && bundle exec rake package` so that the generated packages have the correct permissions. - -## Releasing a new version to rubygems.org - -Note: No Ruby needed to run this! It all runs in CI! - -1. [ ] Locate the new libdatadog release on GitHub: -2. [ ] Update the `LIB_GITHUB_RELEASES` section of the `Rakefile` with the hashes from the new version -3. [ ] In the file: - - [ ] Update `LIB_VERSION` with the new version. Example: Setting "25.0.0" results in the first part of the string "25.0.0.1.0.x" - - [ ] (OPTIONAL) Update `GEM_PRERELEASE_VERSION` with a prerelease descriptor. This is only needed if you want to do a prerelease. Example: Setting ".beta" results in "25.0.0.1.0.beta". -4. [ ] Commit change, open PR, get it merged -5. [ ] Trigger the "Publish Ruby gem" workflow in -6. [ ] Verify that release shows up correctly on: - -## Contributing - -See <../CONTRIBUTING.md>. diff --git a/ruby/Rakefile b/ruby/Rakefile deleted file mode 100644 index 1b739ecf92..0000000000 --- a/ruby/Rakefile +++ /dev/null @@ -1,236 +0,0 @@ -# frozen_string_literal: true - -require "bundler/gem_tasks" -require "rspec/core/rake_task" -require "standard/rake" unless RUBY_VERSION < "2.6" - -require "fileutils" -require "http" unless RUBY_VERSION < "2.5" -require "pry" -require "rubygems/package" - -RSpec::Core::RakeTask.new(:spec) - -# Note: When packaging rc releases and the like, you may need to set this differently from LIB_VERSION -LIB_VERSION_TO_PACKAGE = Libdatadog::LIB_VERSION - -unless LIB_VERSION_TO_PACKAGE.start_with?(Libdatadog::LIB_VERSION) - raise "`LIB_VERSION_TO_PACKAGE` setting in (#{LIB_VERSION_TO_PACKAGE}) does not match " \ - "`LIB_VERSION` setting in (#{Libdatadog::LIB_VERSION})" -end - -LIB_GITHUB_RELEASES = [ - { - file: "libdatadog-aarch64-alpine-linux-musl.tar.gz", - sha256: "0b557141a3accc301d5ffa73d4fe1a90c84b7ceaad45b96c4b573f69170520a7", - ruby_platform: "aarch64-linux-musl" - }, - { - file: "libdatadog-aarch64-unknown-linux-gnu.tar.gz", - sha256: "a61b00551d8e2e2fbc590be08a620c2d6d610c360d94ce8bd4a0283c9ceb3db3", - ruby_platform: "aarch64-linux" - }, - { - file: "libdatadog-x86_64-alpine-linux-musl.tar.gz", - sha256: "5cbde7937d1661cc0483f7cea0c6ec3d0c7bd1540fc4bbe57f9a0a35296c579d", - ruby_platform: "x86_64-linux-musl" - }, - { - file: "libdatadog-x86_64-unknown-linux-gnu.tar.gz", - sha256: "617831c7fb9d0d9e01aa1bc232f89c6a21482d9cfefba4dcc527e8561128eafb", - ruby_platform: "x86_64-linux" - }, - { - file: "libdatadog-aarch64-apple-darwin.tar.gz", - sha256: "298346e13092c057bb2515da5b45e56a34d7a0357589f91e4bb65a375aa23656", - ruby_platform: "arm64-darwin" - } -] - -task default: [ - :spec, - (:standard unless RUBY_VERSION < "2.6") -].compact - -desc "Download lib release from github" -task :fetch do - Helpers.each_github_release_variant do |file:, sha256:, target_directory:, target_file:, **_| - target_url = "https://github.com/datadog/libdatadog/releases/download/v#{LIB_VERSION_TO_PACKAGE}/#{file}" - - if File.exist?(target_file) - target_file_hash = Digest::SHA256.hexdigest(File.read(target_file)) - - if target_file_hash == sha256 - puts "Found #{target_file} matching the expected sha256, skipping download" - next - else - puts "Found #{target_file} with hash (#{target_file_hash}) BUT IT DID NOT MATCH THE EXPECTED sha256 (#{sha256}), downloading it again..." - end - end - - puts "Going to download #{target_url} into #{target_file}" - - File.open(target_file, "wb") do |file| - HTTP.follow.get(target_url).body.each { |chunk| file.write(chunk) } - end - - if Digest::SHA256.hexdigest(File.read(target_file)) == sha256 - puts "Success!" - else - raise "Downloaded file is corrupt, does not match expected sha256" - end - end -end - -desc "Extract lib downloaded releases" -task extract: [:fetch] do - Helpers.each_github_release_variant do |target_directory:, target_file:, **_| - puts "Extracting #{target_file}" - File.open(target_file, "rb") do |file| - Gem::Package.new("").extract_tar_gz(file, target_directory) - end - - # Fix file permissions after extraction - puts "Fixing file permissions in #{target_directory}" - Helpers.fix_file_permissions(target_directory) - end -end - -desc "Package lib downloaded releases as gems" -task package: [ - :spec, - (:"standard:fix" unless RUBY_VERSION < "2.6"), - :extract -] do - gemspec = eval(File.read("libdatadog.gemspec"), nil, "libdatadog.gemspec") # standard:disable Security/Eval - FileUtils.mkdir_p("pkg") - - # Fallback package with all binaries - # This package will get used by (1) platforms that have no matching `ruby_platform` or (2) that have set - # "BUNDLE_FORCE_RUBY_PLATFORM" (or its equivalent via code) to avoid precompiled gems. - # In a previous version of libdatadog, this package had no binaries, but that could mean that we broke customers in case (2). - # For customers in case (1), this package is a no-op, and dd-trace-rb will correctly detect and warn that - # there are no valid binaries for the platform. - Helpers.package_for(gemspec, ruby_platform: nil, files: Helpers.files_for("x86_64-linux", "x86_64-linux-musl", "aarch64-linux", "aarch64-linux-musl", "arm64-darwin")) - - # We include both glibc and musl variants in the same binary gem to avoid the issues - # documented in https://github.com/rubygems/rubygems/issues/3174 - Helpers.package_for(gemspec, ruby_platform: "x86_64-linux", files: Helpers.files_for("x86_64-linux", "x86_64-linux-musl")) - Helpers.package_for(gemspec, ruby_platform: "aarch64-linux", files: Helpers.files_for("aarch64-linux", "aarch64-linux-musl")) - - # macOS package (Apple Silicon) - Helpers.package_for(gemspec, ruby_platform: "arm64-darwin", files: Helpers.files_for("arm64-darwin")) -end - -Rake::Task["package"].enhance { Rake::Task["spec_validate_permissions"].execute } - -task :spec_validate_permissions do - require "rspec" - RSpec.world.reset # If any other tests ran before, flushes them - ret = RSpec::Core::Runner.run(["spec/gem_packaging.rb"]) - raise "Release tests failed! See error output above." if ret != 0 -end - -desc "Release all packaged gems" -task push_to_rubygems: [ - :package, - :"release:guard_clean" -] do - [ - "gem push pkg/libdatadog-#{Libdatadog::VERSION}.gem", - "gem push pkg/libdatadog-#{Libdatadog::VERSION}-x86_64-linux.gem", - "gem push pkg/libdatadog-#{Libdatadog::VERSION}-aarch64-linux.gem", - "gem push pkg/libdatadog-#{Libdatadog::VERSION}-arm64-darwin.gem" - ].each do |command| - puts "Running: #{command}" - abort unless system(command) - end -end - -module Helpers - # Files that should have executable permissions (755) in the gem - # Note: .so for Linux, .dylib for macOS - EXECUTABLE_FILES = ["libdatadog-crashtracking-receiver", "libdatadog_profiling.so", "libdatadog_profiling.dylib"].freeze - - def self.each_github_release_variant - LIB_GITHUB_RELEASES.each do |variant| - file = variant.fetch(:file) - sha256 = variant.fetch(:sha256) - ruby_platform = variant.fetch(:ruby_platform) - - # These two are so common that we just centralize them here - target_directory = "vendor/libdatadog-#{Libdatadog::LIB_VERSION}/#{ruby_platform}" - target_file = "#{target_directory}/#{file}" - - FileUtils.mkdir_p(target_directory) - - yield(file: file, sha256: sha256, ruby_platform: ruby_platform, target_directory: target_directory, target_file: target_file) - end - end - - def self.package_for(gemspec, ruby_platform:, files:) - target_gemspec = gemspec.dup - target_gemspec.files += files - target_gemspec.platform = ruby_platform if ruby_platform - - puts "Building with ruby_platform=#{ruby_platform.inspect} including: (this can take a while)" - pp target_gemspec.files - - package = Gem::Package.build(target_gemspec) - FileUtils.mv(package, "pkg") - puts("-" * 80) - end - - def self.fix_file_permissions(directory) - Dir.glob("#{directory}/**/*").each do |path| - next unless File.file?(path) - - filename = File.basename(path) - current_permissions = File.stat(path).mode & 0o777 - - if EXECUTABLE_FILES.include?(filename) - # Should be executable (755), fix if not - if current_permissions != 0o755 - puts "Fixing permissions for #{filename}: #{current_permissions.to_s(8)} -> 755" - FileUtils.chmod(0o755, path) - end - elsif current_permissions != 0o644 - # Should be non-executable (644), fix if not - puts "Fixing permissions for #{filename}: #{current_permissions.to_s(8)} -> 644" - FileUtils.chmod(0o644, path) - end - end - end - - def self.files_for( - *included_platforms, - excluded_files: [ - "datadog_profiling.pc", # we use the datadog_profiling_with_rpath.pc variant - "libdatadog_profiling.a", "datadog_profiling-static.pc", # We don't use the static library - "libdatadog_profiling.debug", # We don't include debug info - "DatadogConfig.cmake" # We don't compile using cmake - ] - ) - files = [] - - each_github_release_variant do |ruby_platform:, target_directory:, target_file:, **_| - next unless included_platforms.include?(ruby_platform) - - downloaded_release_tarball = target_file - - files += - Dir.glob("#{target_directory}/**/*") - .select { |path| File.file?(path) } - .reject { |path| path == downloaded_release_tarball } - .reject { |path| excluded_files.include?(File.basename(path)) } - end - - files - end -end - -Rake::Task["build"].clear -task(:build) { raise "Build task is disabled, use package instead" } - -Rake::Task["release"].clear -task(:release) { Rake::Task["push_to_rubygems"].invoke } diff --git a/ruby/gems.rb b/ruby/gems.rb deleted file mode 100644 index 72da36b71e..0000000000 --- a/ruby/gems.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -gemspec - -gem "rake", ">= 12.0", "< 14" -gem "rspec", "~> 3.10" -gem "standard", "~> 1.7", ">= 1.7.2" unless RUBY_VERSION < "2.6" -gem "http", "~> 5.0" -gem "pry" -gem "pry-byebug" unless RUBY_VERSION > "3.1" -gem "rubygems-await" unless RUBY_VERSION < "3.1" -gem "irb" diff --git a/ruby/lib/libdatadog.rb b/ruby/lib/libdatadog.rb deleted file mode 100644 index aeaf36b51e..0000000000 --- a/ruby/lib/libdatadog.rb +++ /dev/null @@ -1,81 +0,0 @@ -# frozen_string_literal: true - -require_relative "libdatadog/version" - -module Libdatadog - # This should only be used for debugging/logging - def self.available_binaries - File.directory?(vendor_directory) ? (Dir.entries(vendor_directory) - [".", ".."]) : [] - end - - def self.pkgconfig_folder(pkgconfig_file_name = "datadog_profiling_with_rpath.pc") - current_platform = self.current_platform - - return unless available_binaries.include?(current_platform) - - pkgconfig_file = Dir.glob("#{vendor_directory}/#{current_platform}/**/#{pkgconfig_file_name}").first - - return unless pkgconfig_file - - File.absolute_path(File.dirname(pkgconfig_file)) - end - - private_class_method def self.vendor_directory - ENV["LIBDATADOG_VENDOR_OVERRIDE"] || "#{__dir__}/../vendor/libdatadog-#{Libdatadog::LIB_VERSION}/" - end - - def self.current_platform - platform = Gem::Platform.local.to_s - - if platform.end_with?("-gnu") - # In some cases on Linux with glibc the platform includes a -gnu suffix. We normalize it to not have the suffix. - # - # Note: This should be platform = platform.delete_suffix("-gnu") but it doesn't work on legacy Rubies; once - # dd-trace-rb 2.0 is out we can simplify this. - # - platform = platform[0..-5] - end - - # Normalize macOS/Darwin platform strings by stripping the version number. - # e.g., "arm64-darwin-24" -> "arm64-darwin", "x86_64-darwin-19" -> "x86_64-darwin" - if platform.include?("darwin") - platform = platform.gsub(/-darwin-?\d*$/, "-darwin") - end - - if RbConfig::CONFIG["arch"].include?("-musl") && !platform.include?("-musl") - # Fix/workaround for https://github.com/datadog/dd-trace-rb/issues/2222 - # - # Old versions of rubygems (for instance 3.0.3) don't properly detect alternative libc implementations on Linux; - # in particular for our case, they don't detect musl. (For reference, Rubies older than 2.7 may have shipped with - # an affected version of rubygems). - # In such cases, we fall back to use RbConfig::CONFIG['arch'] instead. - # - # Why not use RbConfig::CONFIG['arch'] always? Because Gem::Platform.local.to_s does some normalization that seemed - # useful in the past, although part of it got removed in https://github.com/rubygems/rubygems/pull/5852. - # For now we only add this workaround in a specific situation where we actually know it is wrong, but in the - # future it may be worth re-evaluating if we should move away from `Gem::Platform` altogether. - # - # See also https://github.com/rubygems/rubygems/pull/2922 and https://github.com/rubygems/rubygems/pull/4082 - - RbConfig::CONFIG["arch"] - else - platform - end - end - - def self.path_to_crashtracking_receiver_binary - pkgconfig_folder = self.pkgconfig_folder - - return unless pkgconfig_folder - - File.absolute_path("#{pkgconfig_folder}/../../bin/libdatadog-crashtracking-receiver") - end - - def self.ld_library_path - pkgconfig_folder = self.pkgconfig_folder - - return unless pkgconfig_folder - - File.absolute_path("#{pkgconfig_folder}/../") - end -end diff --git a/ruby/lib/libdatadog/version.rb b/ruby/lib/libdatadog/version.rb deleted file mode 100644 index fbd1154650..0000000000 --- a/ruby/lib/libdatadog/version.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module Libdatadog - # Current libdatadog version - LIB_VERSION = "28.0.2" - - GEM_MAJOR_VERSION = "1" - GEM_MINOR_VERSION = "0" - GEM_PRERELEASE_VERSION = "" # remember to include dot prefix, if needed! - private_constant :GEM_MAJOR_VERSION, :GEM_MINOR_VERSION, :GEM_PRERELEASE_VERSION - - # The gem version scheme is lib_version.gem_major.gem_minor[.prerelease]. - # This allows a version constraint such as ~> 0.2.0.1.0 in the consumer (dd-trace-rb), in essence pinning libdatadog to - # a specific version like = 0.2.0, but still allow a) introduction of a gem-level breaking change by bumping gem_major - # and b) allow to push automatically picked up bugfixes by bumping gem_minor. - VERSION = "#{LIB_VERSION}.#{GEM_MAJOR_VERSION}.#{GEM_MINOR_VERSION}#{GEM_PRERELEASE_VERSION}" -end diff --git a/ruby/libdatadog.gemspec b/ruby/libdatadog.gemspec deleted file mode 100644 index 2513370736..0000000000 --- a/ruby/libdatadog.gemspec +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -lib = File.expand_path("../lib", __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "libdatadog/version" - -Gem::Specification.new do |spec| - spec.name = "libdatadog" - spec.version = Libdatadog::VERSION - spec.authors = ["Datadog, Inc."] - spec.email = ["dev@datadoghq.com"] - - spec.summary = "Library of common code used by Datadog Continuous Profiler for Ruby" - spec.description = - "libdatadog is a Rust-based utility library for Datadog's ddtrace gem." - spec.homepage = "https://docs.datadoghq.com/tracing/" - spec.license = "Apache-2.0" - spec.required_ruby_version = ">= 2.5.0" - - spec.metadata["allowed_push_host"] = "https://rubygems.org" - - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/datadog/libdatadog/tree/main/ruby" - - # Require releases on rubygems.org to be coming from multi-factor-auth-authenticated accounts - spec.metadata["rubygems_mfa_required"] = "true" - - # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(File.expand_path(__dir__)) do - `git ls-files -z` - .split("\x0") - .reject do |f| - (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|publish)/|\.(?:git|travis|circleci)|appveyor)}) - end - .reject do |f| - [".rspec", ".standard.yml", "Rakefile", "docker-compose.yml", "gems.rb", "README.md"].include?(f) - end - .reject { |f| f.end_with?(".tar.gz") } - end - spec.require_paths = ["lib"] -end diff --git a/ruby/publish/rakefile.rb b/ruby/publish/rakefile.rb deleted file mode 100644 index 0b81eff41f..0000000000 --- a/ruby/publish/rakefile.rb +++ /dev/null @@ -1,8 +0,0 @@ -# This file is used so that the Ruby `rake` command can be used from the root of the repository. -# This is needed for the publish-ruby.yml CI workflow to work. - -require "rake" - -Dir.chdir("ruby") -Rake.application.add_import("Rakefile") -Rake.application.load_imports diff --git a/ruby/spec/gem_packaging.rb b/ruby/spec/gem_packaging.rb deleted file mode 100644 index 86c460169c..0000000000 --- a/ruby/spec/gem_packaging.rb +++ /dev/null @@ -1,51 +0,0 @@ -# Note: This file does not end with _spec on purpose, it should only be run after packaging, e.g. with `rake spec_validate_permissions` - -require "rubygems" -require "rubygems/package" -require "rubygems/package/tar_reader" -require "libdatadog" -require "zlib" - -RSpec.describe "gem release process (after packaging)" do - let(:gem_version) { Libdatadog::VERSION } - let(:packaged_gem_file) { "pkg/libdatadog-#{gem_version}.gem" } - - it "sets the right permissions on the .gem files" do - gem_files = Dir.glob("pkg/*.gem") - expect(gem_files).to include(packaged_gem_file) - - gem_files.each do |gem_file| - Gem::Package::TarReader.new(File.open(gem_file)) do |tar| - data = tar.find { |entry| entry.header.name == "data.tar.gz" } - - Gem::Package::TarReader.new(Zlib::GzipReader.new(StringIO.new(data.read))) do |data_tar| - data_tar.each do |entry| - filename = entry.header.name.split("/").last - octal_permissions = entry.header.mode.to_s(8)[-3..-1] - - expected_permissions = Helpers::EXECUTABLE_FILES.include?(filename) ? "755" : "644" - - expect(octal_permissions).to eq(expected_permissions), - "Unexpected permissions for #{filename} inside #{gem_file} (got #{octal_permissions}, " \ - "expected #{expected_permissions})" - end - end - end - end - end - - it "prefixes all public symbols in .so files" do - so_files = Dir.glob("vendor/libdatadog-#{Libdatadog::LIB_VERSION}/**/*.so") - expect(so_files.size).to be 4 - - so_files.each do |so_file| - raw_symbols = `nm -D --defined-only #{so_file}` - - symbols = raw_symbols.split("\n").map { |symbol| symbol.split(" ").last.downcase }.sort - expect(symbols.size).to be > 20 # Quick sanity check - expect(symbols).to all( - start_with("ddog_").or(start_with("blaze_")) - ) - end - end -end diff --git a/ruby/spec/libdatadog_spec.rb b/ruby/spec/libdatadog_spec.rb deleted file mode 100644 index 2e7e6861dd..0000000000 --- a/ruby/spec/libdatadog_spec.rb +++ /dev/null @@ -1,154 +0,0 @@ -# frozen_string_literal: true - -require "tmpdir" -require "fileutils" - -RSpec.describe Libdatadog do - describe "version constants" do - it "has a version number" do - expect(Libdatadog::VERSION).to_not be nil - end - - it "has an upstream libdatadog version number" do - expect(Libdatadog::LIB_VERSION).to_not be nil - end - end - - describe "binary helper methods" do - let(:temporary_directory) { Dir.mktmpdir } - - before do - allow(ENV).to receive(:[]).and_call_original - allow(ENV).to receive(:[]).with("LIBDATADOG_VENDOR_OVERRIDE").and_return(temporary_directory) - end - - after do - begin - FileUtils.remove_dir(temporary_directory) - rescue Errno::ENOENT, Errno::ENOTDIR - # Do nothing, it's ok - end - end - - shared_examples_for "libdatadog not in usable state" do - describe ".pkgconfig_folder" do - it { expect(Libdatadog.pkgconfig_folder).to be nil } - end - - describe ".path_to_crashtracking_receiver_binary" do - it { expect(Libdatadog.path_to_crashtracking_receiver_binary).to be nil } - end - - describe ".ld_library_path" do - it { expect(Libdatadog.ld_library_path).to be nil } - end - end - - context "when no binaries are available in the vendor directory" do - describe ".available_binaries" do - it { expect(Libdatadog.available_binaries).to be_empty } - end - - it_behaves_like "libdatadog not in usable state" - end - - context "when vendor directory does not exist" do - let(:temporary_directory) { "does/not/exist" } - - describe ".available_binaries" do - it { expect(Libdatadog.available_binaries).to be_empty } - end - - it_behaves_like "libdatadog not in usable state" - end - - context "when binaries are available in the vendor directory" do - before do - Dir.mkdir("#{temporary_directory}/386-freedos") - Dir.mkdir("#{temporary_directory}/mipsel-linux") - end - - describe ".available_binaries" do - it { expect(Libdatadog.available_binaries).to contain_exactly("386-freedos", "mipsel-linux") } - end - - context "for the current platform" do - let(:current_platform) do - platform = Gem::Platform.local.to_s - platform.include?("darwin") ? "arm64-darwin" : platform - end - let(:pkgconfig_folder) { "#{temporary_directory}/#{current_platform}/some/folder/containing/the/lib/pkgconfig" } - - before do - create_dummy_pkgconfig_file(pkgconfig_folder) - end - - def create_dummy_pkgconfig_file(pkgconfig_folder) - begin - FileUtils.mkdir_p(pkgconfig_folder) - rescue Errno::EEXIST - # No problem, a few specs try to create the same folder - end - - File.open("#{pkgconfig_folder}/datadog_profiling_with_rpath.pc", "w+") {} - end - - describe ".pkgconfig_folder" do - it "returns the folder containing the pkgconfig file" do - expect(Libdatadog.pkgconfig_folder).to eq pkgconfig_folder - end - end - - context "when `RbConfig::CONFIG[\"arch\"]` indicates we're on musl libc, but `Gem::Platform.local.to_s` does not detect it" do - # Fix for https://github.com/DataDog/dd-trace-rb/issues/2222 - - before do - allow(RbConfig::CONFIG).to receive(:[]).and_call_original - allow(RbConfig::CONFIG).to receive(:[]).with("arch").and_return("x86_64-linux-musl") - allow(Gem::Platform).to receive(:local).and_return("x86_64-linux") - - ["x86_64-linux", "x86_64-linux-musl"].each do |arch| - create_dummy_pkgconfig_file("#{temporary_directory}/#{arch}/some/folder/containing/the/pkgconfig/file") - end - end - - it "returns the folder containing the pkgconfig file for the musl variant" do - expect(Libdatadog.pkgconfig_folder).to eq "#{temporary_directory}/x86_64-linux-musl/some/folder/containing/the/pkgconfig/file" - end - end - - context "when platform ends with -gnu" do - let(:pkgconfig_folder) { "#{temporary_directory}/aarch64-linux/some/folder/containing/the/pkgconfig/file" } - - before do - allow(Gem::Platform).to receive(:local).and_return(Gem::Platform.new("aarch64-linux-gnu")) - end - - it "chops off the -gnu suffix and returns the folder containing the pkgconfig file for the non-gnu variant" do - expect(Libdatadog.pkgconfig_folder).to eq pkgconfig_folder - end - end - - describe ".path_to_crashtracking_receiver_binary" do - it "returns the full path to the crashtracking_receiver_binary" do - expect(Libdatadog.path_to_crashtracking_receiver_binary).to eq( - "#{temporary_directory}/#{current_platform}/some/folder/containing/the/bin/libdatadog-crashtracking-receiver" - ) - end - end - - describe ".ld_library_path" do - it "returns the full path to the libdatadog lib directory" do - expect(Libdatadog.ld_library_path).to eq( - "#{temporary_directory}/#{current_platform}/some/folder/containing/the/lib" - ) - end - end - end - - context "but not for the current platform" do - it_behaves_like "libdatadog not in usable state" - end - end - end -end diff --git a/ruby/spec/spec_helper.rb b/ruby/spec/spec_helper.rb deleted file mode 100644 index 6557307dd9..0000000000 --- a/ruby/spec/spec_helper.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -require "pry" - -require "libdatadog" - -# This file was generated by the `rspec --init` command + manually tweaked. -# -# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration -RSpec.configure do |config| - config.expect_with :rspec do |expectations| - # This option will default to `true` in RSpec 4. - expectations.include_chain_clauses_in_custom_matcher_descriptions = true - end - - config.mock_with :rspec do |mocks| - # This will default to `true` in RSpec 4. - mocks.verify_partial_doubles = true - end - - # This option will default to `:apply_to_host_groups` in RSpec 4. - config.shared_context_metadata_behavior = :apply_to_host_groups - - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = ".rspec_status" - - # Disable RSpec exposing methods globally on `Module` and `main` - config.disable_monkey_patching! - - # This setting enables warnings. It's recommended, but in some cases may - # be too noisy due to issues in dependencies. - config.warnings = true - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = "doc" - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -end