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

NH-92688: refactor extconf #163

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 15 additions & 8 deletions ext/oboe_metal/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,34 @@
init_mkmf(CONFIG)

ext_dir = __dir__
oboe_debug = ENV['OBOE_DEBUG'].to_s.casecmp('true').zero?
non_production = ENV['OBOE_DEV'].to_s.casecmp('true').zero? || ENV['OBOE_STAGING'].to_s.casecmp('true').zero?
ENV['OBOE_DEBUG'].to_s.casecmp('true').zero?
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the above line needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

oboe_env = ENV.fetch('OBOE_ENV', nil)
non_production = %w[dev stg].include? oboe_env.to_s

swo_lib_dir = File.join(ext_dir, 'lib')
version = File.read(File.join(ext_dir, 'src', 'VERSION')).strip

# OBOE_DEBUG has the highest priorities over oboe environment
if oboe_debug
swo_path = File.join('https://agent-binaries.cloud.solarwinds.com/apm/c-lib/', version, 'relwithdebinfo')
puts 'Fetching c-lib from PRODUCTION DEBUG Build'
elsif ENV['OBOE_DEV'].to_s.casecmp('true').zero?
case oboe_env
when 'dev'
swo_path = 'https://solarwinds-apm-staging.s3.us-west-2.amazonaws.com/apm/c-lib/nightly'
puts 'Fetching c-lib from DEVELOPMENT Build'
elsif ENV['OBOE_STAGING'].to_s.casecmp('true').zero?
when 'stg'
swo_path = File.join('https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/', version)
puts 'Fetching c-lib from STAGING Build'
else
swo_path = File.join('https://agent-binaries.cloud.solarwinds.com/apm/c-lib/', version)
puts 'Fetching c-lib from PRODUCTION Build'
end

oboe_debug = ENV['OBOE_DEBUG'].to_s.casecmp('true').zero?

if oboe_debug
swo_path = File.join(swo_path, 'relwithdebinfo')
puts "Fetching DEBUG Build based on #{oboe_env.to_s.empty? ? 'prod' : oboe_env}"
end

puts "final swo_path: #{swo_path}"

swo_arch = 'x86_64'
system_arch = `uname -m` # for mac, the command is `uname` # "Darwin\n"; try `uname -a`
system_arch.delete!("\n")
Expand Down
87 changes: 74 additions & 13 deletions test/ext/extconf_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,100 @@
describe 'extconf test' do
after do
ENV.delete('OBOE_DEBUG')
ENV.delete('OBOE_STAGING')
ENV.delete('OBOE_DEV')
ENV.delete('OBOE_ENV')
end

it 'simple_extconf_test_with_OBOE_DEBUG' do
it 'simple_extconf_test_with_OBOE_DEBUG_and_OBOE_ENV_nil' do
ENV['OBOE_DEBUG'] = 'true'
output = stub_for_mkmf_test
assert_includes output, 'Fetching c-lib from PRODUCTION DEBUG Build'
assert_includes output, 'Fetching c-lib from PRODUCTION Build'
assert_includes output, 'Fetching DEBUG Build based on prod'
assert_match(%r{https://agent-binaries\.cloud\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)/relwithdebinfo}, output)

refute_includes output, 'Checksum Verification Fail'
end

it 'simple_extconf_test_with_OBOE_DEBUG_and_OBOE_ENV_empty' do
ENV['OBOE_DEBUG'] = 'true'
ENV['OBOE_ENV'] = ''
output = stub_for_mkmf_test
assert_includes output, 'Fetching c-lib from PRODUCTION Build'
assert_includes output, 'Fetching DEBUG Build based on prod'
assert_match(%r{https://agent-binaries\.cloud\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)/relwithdebinfo}, output)

refute_includes output, 'Checksum Verification Fail'
end

it 'OBOE_DEBUG_surpass_other_env' do
it 'simple_extconf_test_with_OBOE_DEBUG_and_OBOE_ENV_prod' do
ENV['OBOE_DEBUG'] = 'true'
ENV['OBOE_STAGING'] = 'true'
ENV['OBOE_ENV'] = 'prod'
output = stub_for_mkmf_test
assert_includes output, 'Fetching c-lib from PRODUCTION DEBUG Build'
assert_includes output, 'Fetching c-lib from PRODUCTION Build'
assert_includes output, 'Fetching DEBUG Build based on prod'
assert_match(%r{https://agent-binaries\.cloud\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)/relwithdebinfo}, output)

refute_includes output, 'Checksum Verification Fail'
end

it 'simple_extconf_test_with_OBOE_STAGING' do
ENV['OBOE_STAGING'] = 'true'
it 'simple_extconf_test_with_OBOE_DEBUG_and_OBOE_ENV_stg' do
ENV['OBOE_DEBUG'] = 'true'
ENV['OBOE_ENV'] = 'stg'
output = stub_for_mkmf_test
assert_includes output, 'Fetching c-lib from STAGING Build'
assert_includes output, 'Fetching DEBUG Build based on stg'
assert_match(%r{https://agent-binaries\.global\.st-ssp\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)/relwithdebinfo}, output)

refute_includes output, 'Checksum Verification Fail'
end

it 'simple_extconf_test_with_OBOE_DEV' do
ENV['OBOE_DEV'] = 'true'
it 'simple_extconf_test_with_OBOE_DEBUG_and_OBOE_ENV_dev' do
ENV['OBOE_DEBUG'] = 'true'
ENV['OBOE_ENV'] = 'dev'
output = stub_for_mkmf_test
assert_includes output, 'Fetching c-lib from DEVELOPMENT Build'
assert_includes output, 'Fetching DEBUG Build based on dev'
assert_includes output, 'https://solarwinds-apm-staging.s3.us-west-2.amazonaws.com/apm/c-lib/nightly/relwithdebinfo'

refute_includes output, 'Checksum Verification Fail'
end

it 'simple_extconf_test_with_no_env_variable' do
ENV.delete('OBOE_STAGING')
it 'simple_extconf_test_without_OBOE_DEBUG_and_OBOE_ENV_dev' do
ENV['OBOE_ENV'] = 'dev'
output = stub_for_mkmf_test
assert_includes output, 'Fetching c-lib from DEVELOPMENT Build'
refute_includes output, 'Fetching DEBUG Build based on dev'
assert_includes output, 'https://solarwinds-apm-staging.s3.us-west-2.amazonaws.com/apm/c-lib/nightly'

refute_includes output, 'Checksum Verification Fail'
end

it 'simple_extconf_test_without_OBOE_DEBUG_and_OBOE_ENV_stg' do
ENV['OBOE_ENV'] = 'stg'
output = stub_for_mkmf_test
assert_includes output, 'Fetching c-lib from STAGING Build'
refute_includes output, 'Fetching DEBUG Build based on stg'
assert_match(%r{https://agent-binaries\.global\.st-ssp\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)}, output)

refute_includes output, 'Checksum Verification Fail'
end

it 'simple_extconf_test_without_OBOE_DEBUG_and_OBOE_ENV_prod' do
ENV['OBOE_ENV'] = 'prod'
output = stub_for_mkmf_test
assert_includes output, 'Fetching c-lib from PRODUCTION Build'
refute_includes output, 'Fetching DEBUG Build based on prod'
assert_match(%r{https://agent-binaries\.cloud\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)}, output)

assert_includes output, 'Checksum Verification Fail'
end

it 'simple_extconf_test_without_OBOE_DEBUG_and_OBOE_ENV_nowhere' do
ENV['OBOE_ENV'] = 'nowhere'
output = stub_for_mkmf_test
assert_includes output, 'Fetching c-lib from PRODUCTION Build'
refute_includes output, 'Fetching DEBUG Build based on prod'
assert_match(%r{https://agent-binaries\.cloud\.solarwinds\.com/apm/c-lib/(\d+\.\d+\.\d+)}, output)

assert_includes output, 'Checksum Verification Fail'
end
end