Class: Kompo::MakeFsC
- Inherits:
-
Taski::Task
- Object
- Taski::Task
- Kompo::MakeFsC
- Defined in:
- lib/kompo/tasks/make_fs_c.rb
Overview
Generate fs.c containing embedded file data Required context:
- gems: Array of gem paths to
- ruby_std_libs: Array of Ruby standard library paths to
- bundler_config: Path to .bundle/config (if using Gemfile)
Dependencies provide:
- WorkDir.path
- CopyProjectFiles.entrypoint_path
Defined Under Namespace
Classes: FsCTemplateContext
Constant Summary collapse
- SKIP_EXTENSIONS =
File extensions to skip when embedding
%w[ .so .bundle .c .h .o .java .jar .gz .dat .sqlite3 .exe .gem .out .png .jpg .jpeg .gif .bmp .ico .svg .webp .ttf .data ].freeze
- PRUNE_DIRS =
Directory names to prune when traversing
%w[.git ports logs spec .github docs exe _ruby].freeze
Instance Method Summary collapse
Instance Method Details
#clean ⇒ Object
84 85 86 87 88 89 |
# File 'lib/kompo/tasks/make_fs_c.rb', line 84 def clean return unless @path && File.exist?(@path) FileUtils.rm_f(@path) puts "Cleaned up fs.c" end |
#run ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/kompo/tasks/make_fs_c.rb', line 31 def run @work_dir = WorkDir.path @path = File.join(@work_dir, "fs.c") # Get original paths for Ruby standard library cache support # When Ruby is restored from cache, standard library paths are from the original build # We need to embed Ruby stdlib files with those original paths so the VFS can find them # Project files and gems use current work_dir paths (no replacement needed) @original_ruby_install_dir = InstallRuby.original_ruby_install_dir @current_ruby_install_dir = InstallRuby.ruby_install_dir # Initialize .kompoignore handler project_dir = Taski.args.fetch(:project_dir, Taski.env.working_directory) || Taski.env.working_directory @kompo_ignore = KompoIgnore.new(project_dir) puts "Using .kompoignore from #{project_dir}" if @kompo_ignore.enabled? @file_bytes = [] @paths = [] @file_sizes = [0] @added_paths = Set.new @duplicate_count = 0 @verbose = Taski.args.fetch(:verbose, false) group("Collecting files") do = .each do || = File.() unless File.exist?() warn "warn: #{expand_path} does not exist. Skipping." next end if File.directory?() process_directory() else add_file() end end duplicate_info = @duplicate_count.positive? ? " (#{@duplicate_count} duplicates skipped)" : "" puts "Collected #{@file_sizes.size - 1} files#{duplicate_info}" end group("Generating fs.c") do context = build_template_context template_path = File.join(__dir__, "..", "..", "fs.c.erb") template = ERB.new(File.read(template_path)) File.write(@path, template.result(binding)) puts "Generated: fs.c (#{@file_bytes.size} bytes)" end end |