From 88a88b8f8169a634d6ad03a705639f99f7d6130a Mon Sep 17 00:00:00 2001 From: Sergey Avseyev Date: Tue, 8 Sep 2026 13:57:07 -0700 Subject: [PATCH] Point CPM_SOURCE_CACHE at the vendored dependency cache Motivation ---------- The generated ext/cache/extconf_include.rb derives both CPM_SOURCE_CACHE and COUCHBASE_CXX_CLIENT_EMBED_MOZILLA_CA_BUNDLE_ROOT from __dir__, but extconf.rb evaluates that file through eval with no file name, so __FILE__ is "(eval)" and __dir__ is nil. Both flags then resolve against the working directory. Under `gem install` that directory happens to be ext/, so the paths come out right by accident; `rake compile` runs extconf.rb from Dir.tmpdir, where they resolve to a cache under the temporary directory and the dependencies and CA bundle vendored in ext/cache go unused. Modifications ------------- extconf.rb passes the include file's path to eval, so __dir__ inside the snippet names the directory the snippet lives in, and the generator emits that directory instead of expanding a relative 'cache' against it. The path is still computed when extconf runs rather than when the gem is packaged, so a gem unpacked under any prefix finds its own cache. Results ------- Both flags name ext/cache whatever working directory the build is driven from, so a source-tree build consumes the vendored dependencies and the pinned CA bundle rather than fetching its own. A gem packaged from a source tree and installed under a different prefix resolves both flags to its own unpacked cache, so the vendored copy travels with the gem. --- Rakefile | 4 ++-- ext/extconf.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 55f09585..00292744 100644 --- a/Rakefile +++ b/Rakefile @@ -258,8 +258,8 @@ task :cache_cxx_dependencies do cmake_flags << "-DCPM_DOWNLOAD_ALL=OFF" cmake_flags << "-DCPM_USE_NAMED_CACHE_DIRECTORIES=ON" cmake_flags << "-DCPM_USE_LOCAL_PACKAGES=OFF" - cmake_flags << "-DCPM_SOURCE_CACHE=\#{File.expand_path('cache', __dir__)}" - cmake_flags << "-DCOUCHBASE_CXX_CLIENT_EMBED_MOZILLA_CA_BUNDLE_ROOT=\#{File.expand_path('cache', __dir__)}" + cmake_flags << "-DCPM_SOURCE_CACHE=\#{__dir__}" + cmake_flags << "-DCOUCHBASE_CXX_CLIENT_EMBED_MOZILLA_CA_BUNDLE_ROOT=\#{__dir__}" CACHE_FLAGS end end diff --git a/ext/extconf.rb b/ext/extconf.rb index c57089ed..46d6b345 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -108,7 +108,9 @@ def sys(*cmd) extconf_include = File.expand_path("cache/extconf_include.rb", __dir__) if File.exist?(extconf_include) puts "-- include extra cmake options from #{extconf_include}" - eval(File.read(extconf_include)) # rubocop:disable Security/Eval + # Evaluated with the file name so that __dir__ inside the snippet resolves to the + # cache directory on the installing machine rather than nil. + eval(File.read(extconf_include), binding, extconf_include) # rubocop:disable Security/Eval end if ENV["CB_STATIC"] || ENV["CB_STATIC_BORINGSSL"]