Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROF-8917] Add Ruby helper to get ld_library_path for libdatadog #423

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ruby/lib/libdatadog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ def self.path_to_crashtracking_receiver_binary

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}/../")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust you know what you are doing... 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahaha thanks! To be clear, what this does is take the structure of our binary builds:

% tree
.
├── bin
│   └── libdatadog-crashtracking-receiver
├── cmake
│   └── DatadogConfig.cmake
├── include
│   └── datadog
│       ├── blazesym.h
│       ├── common.h
│       ├── profiling.h
│       └── telemetry.h
├── lib
│   ├── libdatadog_profiling.a
│   ├── libdatadog_profiling.so
│   ├── libdatadog_profiling.so.debug
│   └── pkgconfig
│       ├── datadog_profiling.pc
│       ├── datadog_profiling-static.pc
│       └── datadog_profiling_with_rpath.pc
├── LICENSE
├── LICENSE-3rdparty.yml
└── NOTICE

and encodes the knowledge that the .so file is in the parent folder to the pkgconfig file.

I could've implemented this another way (e.g. search for the so file directly or something), but since this is internal to the libdatadog helper, and we already have another helper that does this relative find thing, I just went with it.

(Since on the Ruby library side we only call these methods and don't encode any assumptions on the folder structure, we can always update the helpers and move stuff around whenever we want to).

end
end
44 changes: 24 additions & 20 deletions ruby/spec/libdatadog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,26 @@
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

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
Expand All @@ -51,13 +59,7 @@
it { expect(Libdatadog.available_binaries).to be_empty }
end

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
it_behaves_like "libdatadog not in usable state"
end

context "when binaries are available in the vendor directory" do
Expand All @@ -71,7 +73,7 @@
end

context "for the current platform" do
let(:pkgconfig_folder) { "#{temporary_directory}/#{Gem::Platform.local}/some/folder/containing/the/pkgconfig/file" }
let(:pkgconfig_folder) { "#{temporary_directory}/#{Gem::Platform.local}/some/folder/containing/the/lib/pkgconfig" }

before do
create_dummy_pkgconfig_file(pkgconfig_folder)
Expand Down Expand Up @@ -130,16 +132,18 @@ def create_dummy_pkgconfig_file(pkgconfig_folder)
)
end
end
end

context "but not for the current platform" do
describe ".pkgconfig_folder" do
it { expect(Libdatadog.pkgconfig_folder).to be nil }
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}/#{Gem::Platform.local}/some/folder/containing/the/lib"
)
end
end
end

describe ".path_to_crashtracking_receiver_binary" do
it { expect(Libdatadog.path_to_crashtracking_receiver_binary).to be nil }
end
context "but not for the current platform" do
it_behaves_like "libdatadog not in usable state"
end
end
end
Expand Down
Loading