Skip to content

Commit

Permalink
Setup clangd-based native dev env via rake native_dev:setup (#3245)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexJF authored Nov 20, 2023
1 parent 3ef068c commit 5906a20
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
42 changes: 37 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -602,12 +602,44 @@ namespace :changelog do
end
end

Rake::ExtensionTask.new("ddtrace_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
ext.ext_dir = 'ext/ddtrace_profiling_native_extension'
end
NATIVE_EXTS = [
Rake::ExtensionTask.new("ddtrace_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
ext.ext_dir = 'ext/ddtrace_profiling_native_extension'
end,

Rake::ExtensionTask.new("ddtrace_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
ext.ext_dir = 'ext/ddtrace_profiling_loader'
end
].freeze

NATIVE_CLEAN = ::Rake::FileList[]
namespace :native_dev do
compile_commands_tasks = NATIVE_EXTS.map do |ext|
tmp_dir_dd_native_dev = "#{ext.tmp_dir}/dd_native_dev"
directory tmp_dir_dd_native_dev
NATIVE_CLEAN << tmp_dir_dd_native_dev

compile_commands_task = file "#{ext.ext_dir}/compile_commands.json" => [tmp_dir_dd_native_dev] do |t|
puts "Generating #{t.name}"
root_dir = Dir.pwd
cmd = ext.make_makefile_cmd(root_dir, tmp_dir_dd_native_dev, "#{ext.ext_dir}/#{ext.config_script}", nil)
abs_ext_dir = (Pathname.new(root_dir) + ext.ext_dir).realpath
chdir tmp_dir_dd_native_dev do
sh(*cmd)
sh('make clean; bear -- make; make clean')
cp('compile_commands.json', "#{abs_ext_dir}/compile_commands.json")
end
end

NATIVE_CLEAN << compile_commands_task.name

compile_commands_task
end

desc 'Setup dev environment for native extensions.'
task setup: compile_commands_tasks

Rake::ExtensionTask.new("ddtrace_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
ext.ext_dir = 'ext/ddtrace_profiling_loader'
CLEAN.concat(NATIVE_CLEAN)
end

desc 'Runs rubocop + main test suite'
Expand Down
2 changes: 2 additions & 0 deletions ext/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*/compile_commands.json
*/.cache
1 change: 1 addition & 0 deletions ext/ddtrace_profiling_loader/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisableFormat: true
1 change: 1 addition & 0 deletions ext/ddtrace_profiling_native_extension/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisableFormat: true
6 changes: 4 additions & 2 deletions spec/ddtrace/release_gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# It's easy to forget to ship new files, especially when a new paradigm is
# introduced (e.g. introducing native files requires the inclusion `ext/`)
it 'includes all important files' do
single_files_excluded = /
single_files_excluded = %r{
^
(
\.dockerignore
Expand All @@ -23,6 +23,8 @@
|\.semgrepignore
|\.simplecov
|\.yardopts
|ext/\.gitignore
|ext/.*/.clang-format
|Appraisals
|CONTRIBUTING.md
|Gemfile
Expand All @@ -34,7 +36,7 @@
|shell\.nix
)
$
/x
}x

directories_excluded = %r{
^(
Expand Down

0 comments on commit 5906a20

Please sign in to comment.