prebake 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a9faf240c276429e13f29b8ac1b96042dbe56fbcb22718a1fe8e5a3d87b3647
4
- data.tar.gz: '09075fab2ca5e7e79d1f1dc7c37cb0ab2fe7dba2d95de0526343817ac23ee76a'
3
+ metadata.gz: 7645f2849d29abffb31d44684e5d2e357d4f6c095cfb59b37e18a35f1131ead1
4
+ data.tar.gz: 9c5b61fd58f12b3408ead43220bee71fc2c0044201fa183db19d8742a7a3c95f
5
5
  SHA512:
6
- metadata.gz: e57e53e423306d08e03dd50d8c31646785ca5b9ded9d252a63a343c33607e4653394e0289d3c575599b4424b69fb5d5bad306bac2c2a7678868aa66729cebdd9
7
- data.tar.gz: ee212634e00c97d3b3e084be9f2cfffd7158819a006b965b61bcca3719544d50b5fb34f5e18fa2906c8fb0e65dc50fa7bb383e4c671ead2513876975c2f2b6cc
6
+ metadata.gz: 26a7e944594b6c5b8013a7eb78973b6499edd2591b44e1708c94111760f72975c904d4a8008dd281cbf8c17697b381ff2c1501b972fadf0e10dc3f9eb3764b20
7
+ data.tar.gz: 54218e3b6d08e852a0fd340b1eea1a1e57624e46118e51e2b4d1ef55e480ce2afa6dd037a43cdf20137ceb9d80199e39f4b87a112db86350e02cf83e1e65f20e
@@ -105,7 +105,7 @@ module Prebake
105
105
  count = Extractor.install(gem_path, @spec)
106
106
 
107
107
  if count.zero?
108
- Logger.warn "No binaries found in cached gem for #{@spec.name}, falling back to source build"
108
+ Logger.warn "No files to install in cached gem for #{@spec.name}, falling back to source build"
109
109
  return false
110
110
  end
111
111
 
@@ -7,6 +7,13 @@ module Prebake
7
7
  module ExtensionLayout
8
8
  BINARY_GLOB = "*.{so,bundle,dll}"
9
9
 
10
+ # Where a cached gem carries the non-binary files its build wrote into the
11
+ # extension dir, so they are not mistaken for the gem's own files.
12
+ GENERATED_DIR = "prebake-generated"
13
+
14
+ # RubyGems and prebake write these into the extension dir; they are not build output.
15
+ BUILD_RECORDS = %w[gem.build_complete gem_make.out mkmf.log .prebake].freeze
16
+
10
17
  def self.repair_all
11
18
  Bundler.definition.specs.each { |spec| repair(spec) }
12
19
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "rubygems/package"
4
4
  require "fileutils"
5
+ require_relative "extension_layout"
5
6
  require_relative "logger"
6
7
 
7
8
  module Prebake
@@ -25,13 +26,15 @@ module Prebake
25
26
  restore_in_gem_dir(binary, tmpdir, spec)
26
27
  extracted_count += 1
27
28
  end
29
+
30
+ extracted_count += restore_generated_files(tmpdir, spec)
28
31
  end
29
32
 
30
33
  # Mark this extension_dir as prebake-managed for post-install layout repair
31
34
  FileUtils.touch(File.join(spec.extension_dir, ".prebake")) if extracted_count.positive?
32
35
 
33
36
  Logger.info "Installed precompiled #{File.basename(gem_path)} " \
34
- "(#{extracted_count} binary files)"
37
+ "(#{extracted_count} files)"
35
38
 
36
39
  extracted_count
37
40
  rescue StandardError => e
@@ -39,6 +42,21 @@ module Prebake
39
42
  raise
40
43
  end
41
44
 
45
+ # Files the publisher's build wrote besides compiled libraries come back to
46
+ # the extension dir at the paths the build left them. Returns how many.
47
+ def self.restore_generated_files(tmpdir, spec)
48
+ root = File.join(tmpdir, ExtensionLayout::GENERATED_DIR)
49
+ Dir.glob("**/*", File::FNM_DOTMATCH, base: root).count do |relative|
50
+ source = File.join(root, relative)
51
+ next false unless File.file?(source)
52
+
53
+ dest = File.join(spec.extension_dir, relative)
54
+ FileUtils.mkdir_p(File.dirname(dest))
55
+ FileUtils.cp(source, dest)
56
+ true
57
+ end
58
+ end
59
+
42
60
  # Reject symlinks, empty files, and anything resolving outside tmpdir
43
61
  # (path traversal via a crafted gem).
44
62
  def self.safe_binary?(binary, tmpdir)
@@ -6,6 +6,7 @@ require "digest"
6
6
  require "tempfile"
7
7
  require "securerandom"
8
8
  require_relative "platform"
9
+ require_relative "extension_layout"
9
10
  require_relative "logger"
10
11
 
11
12
  module Prebake
@@ -54,12 +55,14 @@ module Prebake
54
55
  Dir.glob(File.join(build_dir, "**/*.{so,bundle,dll}")).each { |f| File.delete(f) }
55
56
 
56
57
  ext_dir = @spec.extension_dir
57
- copy_installed_binaries(ext_dir, build_dir) if ext_dir && File.directory?(ext_dir)
58
+ installed = ext_dir && File.directory?(ext_dir)
59
+ copy_installed_binaries(ext_dir, build_dir) if installed
60
+ generated = installed ? copy_generated_files(ext_dir, build_dir) : []
58
61
 
59
62
  prefix = "#{build_dir}/"
60
63
  compiled = Dir.glob(File.join(build_dir, "**/*.{so,bundle,dll}"))
61
64
  .map { |f| f.delete_prefix(prefix) }
62
- platform_spec.files = platform_spec.files | compiled
65
+ platform_spec.files = platform_spec.files | compiled | generated
63
66
 
64
67
  platform_spec
65
68
  end
@@ -81,6 +84,29 @@ module Prebake
81
84
  end
82
85
  end
83
86
 
87
+ # Files the build wrote besides compiled libraries (generated Ruby files,
88
+ # executables, data). They go under GENERATED_DIR so the extractor can tell
89
+ # them from the gem's own files. Returns the packaged paths.
90
+ def copy_generated_files(ext_dir, build_dir)
91
+ Dir.glob("**/*", File::FNM_DOTMATCH, base: ext_dir).filter_map do |relative|
92
+ source = File.join(ext_dir, relative)
93
+ next if generated_skipped?(relative) || File.symlink?(source) || !File.file?(source)
94
+
95
+ packaged = File.join(ExtensionLayout::GENERATED_DIR, relative)
96
+ dest = File.join(build_dir, packaged)
97
+ FileUtils.mkdir_p(File.dirname(dest))
98
+ FileUtils.cp(source, dest)
99
+ packaged
100
+ end
101
+ end
102
+
103
+ # extension/ is a dirty-layout copy of the extension dir; binaries have their own path.
104
+ def generated_skipped?(relative)
105
+ relative.start_with?("extension/", "extensions/") ||
106
+ ExtensionLayout::BUILD_RECORDS.include?(relative) ||
107
+ File.fnmatch?(ExtensionLayout::BINARY_GLOB, File.basename(relative), File::FNM_EXTGLOB)
108
+ end
109
+
84
110
  # Binaries at root and one level deep (e.g., nokogiri/nokogiri.so), plus the
85
111
  # extension/<platform>/<abi>/ layout Ruby 4.0+ installs into. A nested
86
112
  # binary is skipped when a root-level one already claims its normalized
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prebake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thejus Paul
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-28 00:00:00.000000000 Z
11
+ date: 2026-11-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Prebake speeds up bundle install by skipping native gem compilation.
14
14
  It fetches precompiled binaries for gems like puma, nokogiri, pg, grpc, and bootsnap