Module: Everywhere::Builders::NativeSources

Defined in:
lib/everywhere/builders/native_sources.rb

Overview

The half of the native-extension seam that is the same on all three platforms: copy the app repo's native//**/*. into the staged template, preserving relative paths. What the copied files then have to satisfy (a Kotlin package line) and what gets generated alongside them (a registry, mod.rs) is per-platform and stays in the builders.

Class Method Summary collapse

Class Method Details

.copy!(from:, into:, ext:, reserved: nil, label: nil) ⇒ Object

reserved is the generated file's own name: an app shipping one would be overwritten by the generator, so we refuse instead. label is the source dir as the app sees it ("native/ios"), which doubles as the everywhere.yml key it maps to (native.ios). The block, when given, sees each file before it is copied. Returns the source paths, sorted.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/everywhere/builders/native_sources.rb', line 19

def self.copy!(from:, into:, ext:, reserved: nil, label: nil)
  sources = File.directory?(from) ? Dir.glob(File.join(from, "**", "*.#{ext}")).sort : []
  sources.each do |file|
    relative = file.delete_prefix("#{from}/")
    if reserved && File.basename(file) == reserved
      UI.die!("#{label}/#{relative}: #{reserved} is generated by " \
              "`every build` — declare your types under #{label.tr("/", ".")} " \
              "in config/everywhere.yml instead")
    end
    yield(file, relative) if block_given?

    target = File.join(into, relative)
    FileUtils.mkdir_p(File.dirname(target))
    FileUtils.cp(file, target)
  end
  sources
end