Module: Tebako::Codegen
- Defined in:
- lib/tebako/codegen.rb
Overview
Code geberation
Constant Summary collapse
- COMMON_C_HEADER =
<<~SUBST /** * THIS FILE WAS GENERATED AUTOMATICALLY BY TEBAKO. DO NOT CHANGE IT, PLEASE **/ SUBST
- COMMON_RUBY_HEADER =
<<~SUBST #!/usr/bin/env ruby # frozen_string_literal: true # THIS FILE WAS GENERATED AUTOMATICALLY BY TEBAKO. DO NOT CHANGE IT, PLEASE SUBST
Class Method Summary collapse
- .deploy_crt_implib(opt, scm) ⇒ Object
- .deploy_mk(opt, scm) ⇒ Object
- .deploy_mk_bundle(opt, scm) ⇒ Object
- .deploy_mk_stub(opt) ⇒ Object
- .deploy_rb(opt, scm) ⇒ Object
- .deploy_rb_inner(opt, scm) ⇒ Object
- .deploy_rq ⇒ Object
- .generate_deploy_rb(options_manager, scenario_manager) ⇒ Object
- .generate_package_descriptor(options_manager, scenario_manager) ⇒ Object
- .generate_stub_rb(options_manager) ⇒ Object
- .generate_tebako_fs_cpp(options_manager, scenario_manager) ⇒ Object
- .generate_tebako_version_h(options_manager, v_parts) ⇒ Object
- .package_cwd(options_manager, scenario_manager) ⇒ Object
- .stub_rb(opt) ⇒ Object
- .tebako_fs_cpp(options_manager, scenario_manager) ⇒ Object
- .tebako_fs_cpp_bundle(options_manager, scenario_manager) ⇒ Object
- .tebako_fs_cpp_stub(options_manager, scenario_manager) ⇒ Object
- .tebako_version_h(v_parts) ⇒ Object
Class Method Details
.deploy_crt_implib(opt, scm) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tebako/codegen.rb', line 53 def deploy_crt_implib(opt, scm) crt = "" if scm.msys? crt = <<~SUBST Tebako::Packager.create_implib("#{opt.ruby_src_dir}", "#{opt.data_src_dir}", "#{opt.package}", rv) SUBST end crt end |
.deploy_mk(opt, scm) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/tebako/codegen.rb', line 64 def deploy_mk(opt, scm) case opt.mode when "bundle" deploy_mk_bundle(opt, scm) when /runtime|both/ deploy_mk_stub(opt) end end |
.deploy_mk_bundle(opt, scm) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/tebako/codegen.rb', line 73 def deploy_mk_bundle(opt, scm) <<~SUBST Tebako::Packager.deploy("#{opt.data_src_dir}", "#{opt.data_pre_dir}", rv , "#{opt.root}", "#{scm.fs_entrance}", "#{opt.cwd}") Tebako::Packager.mkdwarfs("#{opt.deps_bin_dir}", "#{opt.data_bundle_file}", "#{opt.data_src_dir}") SUBST end |
.deploy_mk_stub(opt) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/tebako/codegen.rb', line 82 def deploy_mk_stub(opt) <<~SUBST Tebako::Packager.deploy("#{opt.data_src_dir}", "#{opt.data_pre_dir}", rv, "#{File.join(opt.deps, "src", "tebako", "local")}", "stub.rb", nil) Tebako::Packager.mkdwarfs("#{opt.deps_bin_dir}", "#{opt.data_stub_file}", "#{opt.data_src_dir}") SUBST end |
.deploy_rb(opt, scm) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/tebako/codegen.rb', line 90 def deploy_rb(opt, scm) <<~SUBST #{deploy_rq} begin #{deploy_rb_inner(opt, scm)} rescue Tebako::Error => e puts "deploy script failed: \#{e.message} [\#{e.error_code}]" exit(e.error_code) end SUBST end |
.deploy_rb_inner(opt, scm) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/tebako/codegen.rb', line 103 def deploy_rb_inner(opt, scm) <<~SUBST rv = Tebako::RubyVersion.new(ARGV[0]) stash = File.join("#{opt.deps}", "stash_\#{ARGV[0]}") Tebako::Packager::init(stash.to_s, "#{opt.data_src_dir}", "#{opt.data_pre_dir}", "#{opt.data_bin_dir}") #{deploy_crt_implib(opt, scm)} #{deploy_mk(opt, scm)} SUBST end |
.deploy_rq ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/tebako/codegen.rb', line 114 def deploy_rq <<~SUBST require "#{File.join(__dir__, "error.rb")}" require "#{File.join(__dir__, "package_descriptor.rb")}" require "#{File.join(__dir__, "packager.rb")}" require "#{File.join(__dir__, "ruby_version.rb")}" SUBST end |
.generate_deploy_rb(options_manager, scenario_manager) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/tebako/codegen.rb', line 143 def generate_deploy_rb(, scenario_manager) puts " ... deploy.rb" fname = File.join(.deps, "bin", "deploy.rb") FileUtils.mkdir_p(File.dirname(fname)) File.open(fname, "w") do |file| file.write(COMMON_RUBY_HEADER) file.write(deploy_rb(, scenario_manager)) end end |
.generate_package_descriptor(options_manager, scenario_manager) ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/tebako/codegen.rb', line 155 def generate_package_descriptor(, scenario_manager) puts " ... package_descriptor" fname = File.join(.deps, "src", "tebako", "package_descriptor") FileUtils.mkdir_p(File.dirname(fname)) descriptor = Tebako::PackageDescriptor.new(.ruby_ver, Tebako::VERSION, scenario_manager.fs_mount_point, scenario_manager.fs_entry_point, .cwd) File.binwrite(fname, descriptor.serialize) fname end |
.generate_stub_rb(options_manager) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/tebako/codegen.rb', line 131 def generate_stub_rb() puts " ... stub.rb" fname = File.join(.deps, "src", "tebako", "local", "stub.rb") FileUtils.mkdir_p(File.dirname(fname)) File.open(fname, "w") do |file| file.write(COMMON_RUBY_HEADER) file.write(stub_rb()) end end |
.generate_tebako_fs_cpp(options_manager, scenario_manager) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/tebako/codegen.rb', line 166 def generate_tebako_fs_cpp(, scenario_manager) puts " ... tebako-fs.cpp" fname = File.join(.deps, "src", "tebako", "tebako-fs.cpp") FileUtils.mkdir_p(File.dirname(fname)) File.open(fname, "w") do |file| file.write(COMMON_C_HEADER) file.write(tebako_fs_cpp(, scenario_manager)) end end |
.generate_tebako_version_h(options_manager, v_parts) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/tebako/codegen.rb', line 178 def generate_tebako_version_h(, v_parts) puts " ... tebako-version.h" fname = File.join(.deps, "include", "tebako", "tebako-version.h") FileUtils.mkdir_p(File.dirname(fname)) File.open(fname, "w") do |file| file.write(COMMON_C_HEADER) file.write(tebako_version_h(v_parts)) end end |
.package_cwd(options_manager, scenario_manager) ⇒ Object
190 191 192 193 194 195 196 |
# File 'lib/tebako/codegen.rb', line 190 def package_cwd(, scenario_manager) if .cwd.nil? "nullptr" else "\"#{scenario_manager.fs_mount_point}/#{.cwd}\"" end end |
.stub_rb(opt) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/tebako/codegen.rb', line 123 def stub_rb(opt) <<~SUBST puts "Copyright (c) 2024-2025 Ribose Inc (https://www.ribose.com)" puts "Tebako runtime stub v#{Tebako::VERSION}" puts "To run your application please call #{File.basename(opt.package)} --tebako-run <your tebako package>" SUBST end |
.tebako_fs_cpp(options_manager, scenario_manager) ⇒ Object
198 199 200 201 202 203 204 205 |
# File 'lib/tebako/codegen.rb', line 198 def tebako_fs_cpp(, scenario_manager) case .mode when "bundle" tebako_fs_cpp_bundle(, scenario_manager) when /runtime|both/ tebako_fs_cpp_stub(, scenario_manager) end end |
.tebako_fs_cpp_bundle(options_manager, scenario_manager) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/tebako/codegen.rb', line 207 def tebako_fs_cpp_bundle(, scenario_manager) <<~SUBST #include <limits.h> #include <incbin/incbin.h> namespace tebako { const char * fs_log_level = "#{.l_level}"; const char * fs_mount_point = "#{scenario_manager.fs_mount_point}"; const char * fs_entry_point = "#{scenario_manager.fs_entry_point}"; const char * package_cwd = #{package_cwd(, scenario_manager)}; char original_cwd[PATH_MAX]; INCBIN(fs, "#{.data_bundle_file}"); } SUBST end |
.tebako_fs_cpp_stub(options_manager, scenario_manager) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/tebako/codegen.rb', line 224 def tebako_fs_cpp_stub(, scenario_manager) <<~SUBST #include <limits.h> #include <incbin/incbin.h> namespace tebako { const char * fs_log_level = "#{.l_level}"; const char * fs_mount_point = "#{scenario_manager.fs_mount_point}"; const char * fs_entry_point = "/local/stub.rb"; const char * package_cwd = nullptr; char original_cwd[PATH_MAX]; INCBIN(fs, "#{.data_stub_file}"); } SUBST end |
.tebako_version_h(v_parts) ⇒ Object
241 242 243 244 245 246 247 248 249 |
# File 'lib/tebako/codegen.rb', line 241 def tebako_version_h(v_parts) <<~SUBST #pragma once const unsigned int tebako_version_major = #{v_parts[0]}; const unsigned int tebako_version_minor = #{v_parts[1]}; const unsigned int tebako_version_teeny = #{v_parts[2]}; SUBST end |