Module: Tebako::Codegen
- Defined in:
- lib/tebako/codegen.rb
Overview
Code geberation
Constant Summary collapse
- COMMON_C_HEADER =
"/**\n* THIS FILE WAS GENERATED AUTOMATICALLY BY TEBAKO. DO NOT CHANGE IT, PLEASE\n**/\n\n"- COMMON_RUBY_HEADER =
"#!/usr/bin/env ruby\n# frozen_string_literal: true\n\n# THIS FILE WAS GENERATED AUTOMATICALLY BY TEBAKO. DO NOT CHANGE IT, PLEASE\n\n"
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 = " Tebako::Packager.create_implib(\"\#{opt.ruby_src_dir}\", \"\#{opt.data_src_dir}\",\n \"\#{opt.package}\", rv)\n SUBST\n end\n crt\nend\n" |
.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) " Tebako::Packager.deploy(\"\#{opt.data_src_dir}\", \"\#{opt.data_pre_dir}\",\n rv , \"\#{opt.root}\", \"\#{scm.fs_entrance}\", \"\#{opt.cwd}\")\n Tebako::Packager.mkdwarfs(\"\#{opt.deps_bin_dir}\", \"\#{opt.data_bundle_file}\",\n \"\#{opt.data_src_dir}\")\n SUBST\nend\n" |
.deploy_mk_stub(opt) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/tebako/codegen.rb', line 82 def deploy_mk_stub(opt) " Tebako::Packager.deploy(\"\#{opt.data_src_dir}\", \"\#{opt.data_pre_dir}\",\n rv, \"\#{File.join(opt.deps, \"src\", \"tebako\", \"local\")}\", \"stub.rb\", nil)\n Tebako::Packager.mkdwarfs(\"\#{opt.deps_bin_dir}\", \"\#{opt.data_stub_file}\", \"\#{opt.data_src_dir}\")\n SUBST\nend\n" |
.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) " \#{deploy_rq}\n\n begin\n \#{deploy_rb_inner(opt, scm)}\n rescue Tebako::Error => e\n puts \"deploy script failed: \\\#{e.message} [\\\#{e.error_code}]\"\n exit(e.error_code)\n end\n SUBST\nend\n" |
.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) " rv = Tebako::RubyVersion.new(ARGV[0])\n stash = File.join(\"\#{opt.deps}\", \"stash_\\\#{ARGV[0]}\")\n Tebako::Packager::init(stash.to_s, \"\#{opt.data_src_dir}\",\n \"\#{opt.data_pre_dir}\", \"\#{opt.data_bin_dir}\")\n \#{deploy_crt_implib(opt, scm)}\n \#{deploy_mk(opt, scm)}\n SUBST\nend\n" |
.deploy_rq ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/tebako/codegen.rb', line 114 def deploy_rq " require \"\#{File.join(__dir__, \"error.rb\")}\"\n require \"\#{File.join(__dir__, \"package_descriptor.rb\")}\"\n require \"\#{File.join(__dir__, \"packager.rb\")}\"\n require \"\#{File.join(__dir__, \"ruby_version.rb\")}\"\n SUBST\nend\n" |
.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}/#{options_manager.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) " puts \"Copyright (c) 2024-2025 Ribose Inc (https://www.ribose.com)\"\n puts \"Tebako runtime stub v\#{Tebako::VERSION}\"\n puts \"To run your application please call \#{File.basename(opt.package)} --tebako-run <your tebako package>\"\n SUBST\nend\n" |
.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) " #include <limits.h>\n #include <incbin/incbin.h>\n\n namespace tebako {\n const char * fs_log_level = \"\#{options_manager.l_level}\";\n const char * fs_mount_point = \"\#{scenario_manager.fs_mount_point}\";\n const char * fs_entry_point = \"\#{scenario_manager.fs_entry_point}\";\n const char * package_cwd = \#{package_cwd(options_manager, scenario_manager)};\n char original_cwd[PATH_MAX];\n\n INCBIN(fs, \"\#{options_manager.data_bundle_file}\");\n }\n SUBST\nend\n" |
.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) " #include <limits.h>\n #include <incbin/incbin.h>\n\n namespace tebako {\n const char * fs_log_level = \"\#{options_manager.l_level}\";\n const char * fs_mount_point = \"\#{scenario_manager.fs_mount_point}\";\n const char * fs_entry_point = \"/local/stub.rb\";\n const char * package_cwd = nullptr;\n char original_cwd[PATH_MAX];\n\n INCBIN(fs, \"\#{options_manager.data_stub_file}\");\n }\n SUBST\nend\n" |
.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) " #pragma once\n\n const unsigned int tebako_version_major = \#{v_parts[0]};\n const unsigned int tebako_version_minor = \#{v_parts[1]};\n const unsigned int tebako_version_teeny = \#{v_parts[2]};\n SUBST\nend\n" |