Module: NeriBuild
- Defined in:
- lib/neri/build.rb
Class Method Summary collapse
- .additional_dlls_dependencies ⇒ Object
- .additional_gems_dependencies ⇒ Object
- .additional_libs_dependencies ⇒ Object
- .basename ⇒ Object
- .basepath ⇒ Object
- .bindir ⇒ Object
- .check_dependencies ⇒ Object
- .check_options ⇒ Object
- .copy_files(dependencies) ⇒ Object
- .create_batfile ⇒ Object
- .create_datafile ⇒ Object
- .create_exefile ⇒ Object
- .datafile ⇒ Object
- .dll_dependencies ⇒ Object
- .encoding_dependencies ⇒ Object
- .gem_require_paths(file) ⇒ Object
- .gemspec_dependencies(dependencies) ⇒ Object
- .gemspec_path(file) ⇒ Object
- .load_options(argv) ⇒ Object
- .load_options_from_file(file) ⇒ Object
-
.output_help ⇒ Object
–help.
-
.output_version ⇒ Object
–version.
-
.rb_dependencies ⇒ Object
check dependencies.
- .relative_path(path, basedir = rubydir, prepath = "") ⇒ Object
- .ruby_command(path) ⇒ Object
- .ruby_dependencies ⇒ Object
- .rubydir ⇒ Object
- .rubyexe ⇒ Object
- .run ⇒ Object
- .run_script ⇒ Object
- .scriptfile ⇒ Object
- .select_dependencies(dependencies) ⇒ Object
- .to_winpath(path) ⇒ Object
Class Method Details
.additional_dlls_dependencies ⇒ Object
398 399 400 401 402 403 404 405 406 |
# File 'lib/neri/build.rb', line 398 def additional_dlls_dependencies dependencies = [] @options[:dlls].push("*.dll") if RbConfig::CONFIG["arch"].include?("x64") @options[:dlls].each do |dll| dependencies += Dir.glob(File.join(bindir, "**", dll)) dependencies += Dir.glob(File.join(bindir, "**", "#{dll}.*")) end dependencies.uniq end |
.additional_gems_dependencies ⇒ Object
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/neri/build.rb', line 420 def additional_gems_dependencies dependencies = [] rubygems_dir = File.join(Gem.dir, "gems") @options[:gems].each do |gem| gem.sub!(/:(.+)/, "") targets = Regexp.last_match(1).to_s.split("|") targets.push("lib/**/*") gem += "-*" unless gem.match("-") gemdir = Dir.glob(File.join(rubygems_dir, gem)).max next unless gemdir targets.each do |target| dependencies += Dir.glob(File.join(gemdir, target)) end end dependencies.uniq end |
.additional_libs_dependencies ⇒ Object
408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/neri/build.rb', line 408 def additional_libs_dependencies dependencies = [] @options[:libs].each do |lib| $LOAD_PATH.each do |path| dependencies += Dir.glob(File.join(path, lib)) dependencies += Dir.glob(File.join(path, "#{lib}.*")) dependencies += Dir.glob(File.join(path, lib, "**", "*")) end end dependencies.uniq end |
.basename ⇒ Object
96 |
# File 'lib/neri/build.rb', line 96 def basename ; File.basename(scriptfile, ".*"); end |
.basepath ⇒ Object
97 |
# File 'lib/neri/build.rb', line 97 def basepath ; File.join(@options[:output_dir], basename); end |
.bindir ⇒ Object
92 |
# File 'lib/neri/build.rb', line 92 def bindir ; RbConfig::CONFIG["bindir"] || File.join(rubydir, "bin"); end |
.check_dependencies ⇒ Object
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/neri/build.rb', line 491 def check_dependencies run_script require "rbconfig" dependencies = [] dependencies += rb_dependencies dependencies += dll_dependencies dependencies += ruby_dependencies dependencies += additional_dlls_dependencies dependencies += additional_libs_dependencies dependencies += additional_gems_dependencies dependencies += encoding_dependencies dependencies = select_dependencies(dependencies) dependencies += gemspec_dependencies(dependencies) if @options[:enable_gems] if dependencies.find { |dep| dep.end_with?("/net/https.rb") } dependencies.push("#{rubydir}ssl/cert.pem") end size = dependencies.map { |d| File.size(d) }.inject(&:+) nputs "#{dependencies.size} files, #{size} bytes dependencies." dependencies end |
.check_options ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/neri/build.rb', line 270 def ("~/neri.config") ("./neri.config") tmp_data_files = @data_files @data_files = [] (ARGV.map { |arg| arg.encode(Encoding::UTF_8) }) until ARGV.empty? break if ARGV.shift == "--" end @data_files += tmp_data_files if @data_files.empty? error "No Script File!" output_help exit end @options[:external_encoding] ||= Encoding.default_external.name unless @options[:enable_gems] || @rubyopt.index("--disable-gems") @rubyopt += " --disable-gems" end unless @options[:enable_did_you_mean] || @rubyopt.index("--disable-did_you_mean") @rubyopt += " --disable-did_you_mean" end @rubyopt.sub!(%r{-r\S+/bundler/setup}, "") if @data_files.size > 1 || @options[:encryption_key] @options[:datafile] ||= "#{basename}.dat" end end |
.copy_files(dependencies) ⇒ Object
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/neri/build.rb', line 515 def copy_files(dependencies) nputs "Copying dependencies." require "fileutils" src_dir = rubydir desc_dir = File.join(@options[:output_dir], @options[:system_dir], "") system_files = dependencies.map do |file| [file, file.sub(src_dir, desc_dir)] end unless @options[:enable_gems] system_files.each do |src, desc| paths = gem_require_paths(src) next unless paths desc.sub!(%r{/gems/(\d+\.\d+\.\d+)/gems/.+?-[^/]+/(.+)\z}) do version, file = Regexp.last_match(1), Regexp.last_match(2) paths.each do |path| file = file.sub(path, "#{version}/") if file.start_with?(path) end "/vendor_ruby/#{file}" end end end system_files.each do |src, desc| FileUtils.makedirs(File.dirname(desc)) FileUtils.copy(src, desc) if File.file?(src) end FileUtils.copy(scriptfile, desc_dir) unless @options[:datafile] end |
.create_batfile ⇒ Object
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 |
# File 'lib/neri/build.rb', line 598 def create_batfile nputs "Creating batch_file '#{basepath}.bat'." pause_command = "" if @options[:pause_last] pause_command += "echo.\n" pause_command += if @options[:pause_text] "echo #{@options[:pause_text]}\npause > nul" else "pause" end end chdir = @options[:chdir_first] ? 'cd /d "%~dp0"' : "" File.open("#{basepath}.bat", "w:#{@options[:external_encoding]}") do |f| f.puts <<-BATCH @echo off setlocal set PATH=%~dp0#{@options[:system_dir]}\\#{relative_path(bindir)};%PATH% set NERI_EXECUTABLE=%~0 #{chdir} if %~x0 == .exe ( shift ) #{ruby_command(@options[:chdir_first] ? '' : '%~dp0')} %1 %2 %3 %4 %5 %6 %7 %8 %9 #{pause_command} endlocal BATCH end end |
.create_datafile ⇒ Object
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/neri/build.rb', line 546 def create_datafile return unless @options[:datafile] nputs "Creating datafile '#{datafile}'." data_files = @data_files.select { |file| File.file? file } @data_files.select { |file| File.directory? file }.each do |dir| data_files += Dir.glob("#{dir}/**/*").select { |file| File.file? file } end data_files.uniq! { |file| File.(file) } unless @options[:virtual_directory] dir_pwd = Dir.pwd.encode(Encoding::UTF_8) virtual_directories = Pathname.new(dir_pwd).ascend.to_a.map(&:to_s) data_files.each do |file| fullpath = File.(file) next if fullpath.start_with?(rubydir) || Pathname.new(file).absolute? virtual_directories.shift until fullpath.start_with?(virtual_directories.first) end @options[:virtual_directory] = relative_path(dir_pwd, virtual_directories.first, "/_neri_virtual_directory_/") nputs "virtual_directory: #{@options[:virtual_directory]}" end if @options[:encryption_key] require "digest/sha2" @encryption_key = Digest::SHA2.hexdigest(@options[:encryption_key]) end Neri.key = @encryption_key || "0" * 64 File.open(datafile, "wb") do |f| pos = 0 file_informations = data_files.map do |file| fullpath = File.(file) filename = if fullpath.start_with?(rubydir) relative_path(fullpath, rubydir, "#{@options[:system_dir]}#{File::SEPARATOR}") else file end filedata = [filename, File.size(file), pos].join("\t") pos += File.size(file) pos += Neri::BLOCK_LENGTH - pos % Neri::BLOCK_LENGTH unless pos % Neri::BLOCK_LENGTH == 0 filedata end files_str = file_informations.join("\n").encode(Encoding::UTF_8) f.write(format("%#{Neri::BLOCK_LENGTH}d", files_str.bytesize)) f.write(xor(files_str)) data_files.each do |file| f.write(xor(File.binread(file))) end end end |
.create_exefile ⇒ Object
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 |
# File 'lib/neri/build.rb', line 628 def create_exefile unless system("gcc --version >nul 2>&1 && windres --version >nul 2>&1") error "gcc or windres not found !" create_batfile return end exe_file = to_winpath("#{basepath}.exe" ) c_file = to_winpath("#{basepath}_tmp.c" ) o_file = to_winpath("#{basepath}_tmp.o" ) rc_file = to_winpath("#{basepath}_tmp.rc") system_dir = escape_cstr(to_winpath(File.join(@options[:system_dir], ""))) nputs "Creating exe_file '#{exe_file}'." File.open(c_file, "w:#{@options[:external_encoding]}") do |f| f.puts <<-CFILE #include <stdio.h> #include <stdlib.h> #include <windows.h> #include <unistd.h> int main(int argc, char *argv[]) { char exepath[_MAX_PATH * 2 + 1], drive [_MAX_DRIVE + 1], dir [_MAX_DIR * 2 + 1], fname [_MAX_FNAME * 2 + 1], ext [_MAX_EXT * 2 + 1], paths [_MAX_PATH * 32 + 1], runruby[_MAX_PATH * 32 + 1]; PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(STARTUPINFO)); if(GetModuleFileName(NULL, exepath, MAX_PATH * 2) != 0){ _splitpath_s(exepath, drive, _MAX_DRIVE, dir, _MAX_DIR * 2, fname, _MAX_FNAME * 2, ext, _MAX_EXT * 2); } else { exit(EXIT_FAILURE); } snprintf(paths, sizeof(paths), "NERI_EXECUTABLE=%s", exepath); putenv(paths); snprintf(paths, sizeof(paths), "PATH=%s%s#{system_dir}bin;%s", drive, dir, getenv("PATH")); putenv(paths); #{@options[:chdir_first] ? 'snprintf(paths, sizeof(paths), "%s%s", drive, dir);chdir(paths);' : ''} snprintf(runruby, sizeof(runruby), "#{escape_cstr(ruby_command(@options[:chdir_first] ? '' : '%s%s'))} %s %s %s %s %s %s %s %s %s", #{@options[:chdir_first] ? '' : 'drive, dir,'} argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "", argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "", argc > 5 ? argv[5] : "", argc > 6 ? argv[6] : "", argc > 7 ? argv[7] : "", argc > 8 ? argv[8] : "", argc > 9 ? argv[9] : "" ); CFILE if @options[:invisible] f.puts %[ CreateProcess(NULL, runruby, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, NULL, &si, &pi);] else f.puts %[ system(runruby);] end if @options[:pause_last] f.puts %[ system("echo.");] if @options[:pause_text] f.puts %[ system("echo #{escape_cstr(@options[:pause_text])}");] f.puts %[ system("pause >nul");] else f.puts %[ system("pause");] end end f.puts " return 0;\n}" end File.open(rc_file, "w:#{@options[:external_encoding]}") do |f| f.puts <<-RCFILE #include <winver.h> 1 VERSIONINFO #{@options[:fileversion ] ? "FILEVERSION #{escape_cstr(@options[:fileversion ])}" : ''} #{@options[:productversion] ? "PRODUCTVERSION #{escape_cstr(@options[:productversion])}" : ''} FILETYPE VFT_APP BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "000004b0" BEGIN #{@options[:fileversion ] ? 'VALUE "FileVersion", "' + escape_cstr(@options[:fileversion ]) + '\0"' : ''} #{@options[:productversion ] ? 'VALUE "ProductVersion", "' + escape_cstr(@options[:productversion ]) + '\0"' : ''} #{@options[:productname ] ? 'VALUE "ProductName", "' + escape_cstr(@options[:productname ]) + '\0"' : ''} #{@options[:originalfilename] ? 'VALUE "OriginalFileName", "' + escape_cstr(@options[:originalfilename]) + '\0"' : ''} #{@options[:internalname ] ? 'VALUE "InternalName", "' + escape_cstr(@options[:internalname ]) + '\0"' : ''} #{@options[:description ] ? 'VALUE "FileDescription", "' + escape_cstr(@options[:description ]) + '\0"' : ''} #{@options[:company ] ? 'VALUE "CompanyName", "' + escape_cstr(@options[:company ]) + '\0"' : ''} #{@options[:trademarks ] ? 'VALUE "LegalTrademarks", "' + escape_cstr(@options[:trademarks ]) + '\0"' : ''} #{@options[:copyright ] ? 'VALUE "LegalCopyright", "' + escape_cstr(@options[:copyright ]) + '\0"' : ''} #{@options[:privatebuild ] ? 'VALUE "PrivateBuild", "' + escape_cstr(@options[:privatebuild ]) + '\0"' : ''} #{@options[:specialbuild ] ? 'VALUE "SpecialBuild", "' + escape_cstr(@options[:specialbuild ]) + '\0"' : ''} #{@options[:comments ] ? 'VALUE "Comments", "' + escape_cstr(@options[:comments ]) + '\0"' : ''} END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x0, 0x4b0 END END 2 ICON "#{escape_cstr(@options[:icon])}" RCFILE end nsystem(%(windres -o "#{o_file}" "#{rc_file}")) nsystem(%(gcc#{@options[:invisible] ? ' -mwindows' : ''} -o "#{exe_file}" "#{c_file}" "#{o_file}")) nsystem(%(strip "#{exe_file}")) File.delete(c_file, rc_file, o_file) end |
.datafile ⇒ Object
98 |
# File 'lib/neri/build.rb', line 98 def datafile ; File.join(@options[:output_dir], @options[:system_dir], @options[:datafile]); end |
.dll_dependencies ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/neri/build.rb', line 338 def dll_dependencies require "fiddle/import" psapi = Fiddle.dlopen("psapi.dll") kernel32 = Fiddle.dlopen("kernel32.dll") enumprocessmodules = Fiddle::Function.new( psapi["EnumProcessModules"], [Fiddle::TYPE_UINTPTR_T, Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP], Fiddle::TYPE_LONG, Fiddle::Importer.const_get(:CALL_TYPE_TO_ABI)[:stdcall] ) getmodulefilename = Fiddle::Function.new( kernel32["GetModuleFileNameW"], [Fiddle::TYPE_UINTPTR_T, Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG], Fiddle::TYPE_LONG, Fiddle::Importer.const_get(:CALL_TYPE_TO_ABI)[:stdcall] ) getcurrentprocess = Fiddle::Function.new( kernel32["GetCurrentProcess"], [], Fiddle::TYPE_LONG, Fiddle::Importer.const_get(:CALL_TYPE_TO_ABI)[:stdcall] ) bytes_needed = 4 * 32 module_handle_buffer = nil process_handle = getcurrentprocess.call loop do module_handle_buffer = "\x00" * bytes_needed bytes_needed_buffer = [0].pack("I") enumprocessmodules.call( process_handle, module_handle_buffer, module_handle_buffer.size, bytes_needed_buffer ) bytes_needed = bytes_needed_buffer.unpack1("I") break if bytes_needed <= module_handle_buffer.size end handles = module_handle_buffer.unpack("I*") dependencies = handles.select { |handle| handle > 0 }.map do |handle| str = "\x00\x00" * 256 modulefilename_length = getmodulefilename.call(handle, str, str.size) str[0, modulefilename_length * 2].force_encoding("UTF-16LE").encode("UTF-8") end dependencies.map! { |dep| dep.sub(/^\\\\\?\\/, "") } dependencies.map! { |dep| dep.tr("\\", "/") } dependencies.delete(rubyexe) dependencies.uniq end |
.encoding_dependencies ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/neri/build.rb', line 438 def encoding_dependencies return [] unless @options[:encoding] dependencies = [] enc_dir = Dir.glob(File.join(RbConfig::CONFIG["archdir"] || RbConfig::TOPDIR, "**", "enc")).first @options[:encoding].split(",").map(&:strip).each do |enc| case enc when "ja" %w[windows_31j.so japanese_sjis.so encdb.so].each do |enc_name| dependencies += Dir.glob(File.join(enc_dir, "**", enc_name)) end else dependencies += Dir.glob(File.join(enc_dir, "**", enc)) dependencies += Dir.glob(File.join(enc_dir, "**", "#{enc}.*")) end end dependencies.uniq end |
.gem_require_paths(file) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/neri/build.rb', line 66 def gem_require_paths(file) path = gemspec_path(file) return nil unless path return @require_paths[path] if @require_paths.key?(path) @require_paths[path] = ["lib/"] if File.exist?(path) gemspec = File.binread(path) if gemspec.match(/\.require_paths\s*=\s*\[([^\]]+)\]/) @require_paths[path] = Regexp.last_match(1).scan(/['"]([^'"]+)['"]/).flatten.map do |p| "#{p.delete_suffix('/')}/" end end end @require_paths[path] end |
.gemspec_dependencies(dependencies) ⇒ Object
484 485 486 487 488 489 |
# File 'lib/neri/build.rb', line 484 def gemspec_dependencies(dependencies) default_gemspec_dir = Gem.default_specifications_dir.encode(Encoding::UTF_8) gemspecs = Dir.glob("#{default_gemspec_dir}/**/*") gemspecs += dependencies.map { |depend| gemspec_path(depend) } gemspecs.compact.uniq end |
.gemspec_path(file) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/neri/build.rb', line 58 def gemspec_path(file) return nil unless file.match?(%r{/gems/\d+\.\d+\.\d+/gems/(.+?-[^/]+)/}) file.sub(%r{(/gems/\d+\.\d+\.\d+)/gems/(.+?-[^/]+)/.+\z}) do "#{Regexp.last_match(1)}/specifications/#{Regexp.last_match(2)}.gemspec" end end |
.load_options(argv) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/neri/build.rb', line 156 def (argv) until argv.empty? arg = argv.shift case arg when "--help", "-h" output_help exit when "--version", "-v" output_version exit when "--quiet", "-q" @options[:quiet] = true when "--external-encoding" @options[:external_encoding] = argv.shift when "--dll" @options[:dlls] += argv.shift.split(",").map(&:strip) when "--lib" @options[:libs] += argv.shift.split(",").map(&:strip) when "--gem" @options[:gems] += argv.shift.split(",").map(&:strip) when "--no-enc" @options[:encoding] = nil when "--encoding" @options[:encoding] = argv.shift when "--enable-gems" @options[:enable_gems] = true when "--disale-gems" @options[:enable_gems] = false when "--enable-did-you-mean" @options[:enable_did_you_mean] = true when "--disale-did-you-mean" @options[:enable_did_you_mean] = false when "--no-chdir" @options[:chdir_first] = false when "--chdir-first" # deprecated @options[:chdir_first] = true when "--pause-last" @options[:pause_last] = true when "--no-pause-last" @options[:pause_last] = false when "--pause-text" @options[:pause_text] = argv.shift @options[:pause_last] = true when "--output-dir" @options[:output_dir] = argv.shift when "--system-dir" @options[:system_dir] = argv.shift when "--datafile" @options[:datafile] = argv.shift when "--encryption-key" @options[:encryption_key] = argv.shift when "--virtual-directory" @options[:virtual_directory] = argv.shift when "--no-exe", "--bat" @options[:no_exe] = true when "--icon" @options[:icon] = argv.shift when "--windows", "--invisible" @options[:invisible] = true when "--console", "--visible" @options[:invisible] = false when "--fileversion" @options[:fileversion] = argv.shift when "--productversion" @options[:productversion] = argv.shift when "--productname" @options[:productname] = argv.shift when "--originalfilename" @options[:originalfilename] = argv.shift when "--internalname" @options[:internalname] = argv.shift when "--description" @options[:description] = argv.shift when "--company" @options[:company] = argv.shift when "--trademarks" @options[:trademarks] = argv.shift when "--copyright" @options[:copyright] = argv.shift when "--privatebuild" @options[:privatebuild] = argv.shift when "--specialbuild" @options[:specialbuild] = argv.shift when "--comments" @options[:comments] = argv.shift when "--" break when /^(--.+)/ error "Invalid Option '#{arg}'!" output_help exit else if File.exist?(arg) @data_files.push(arg) else error "File '#{arg}' not found!" exit end end end @args += argv.map { |a| %( "#{a}") }.join("") end |
.load_options_from_file(file) ⇒ Object
260 261 262 263 264 265 266 267 268 |
# File 'lib/neri/build.rb', line 260 def (file) fullpath = File.(file) return unless File.exist?(fullpath) argv = File.read(fullpath, encoding: Encoding::UTF_8).lines.flat_map do |line| line.strip.split(" ", 2) end (argv) end |
.output_help ⇒ Object
–help
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/neri/build.rb', line 101 def output_help puts <<-HELP_MESSAGE usage: neri [options] script.rb (other_files...) -- script_arguments options: --help or -h --version or -v --quiet --external-encoding <encoding> --dll <dll1>,<dll2>,... --lib <lib1>,<lib2>,... --gem <gem1>,<gem2>,... --no-enc --encoding <enc1>,<enc2>,... --enable-gems / --disable-gems --enable-did-you-mean / --disable-did-you-mean --no-chdir --pause-last --no-pause-last --pause-text <text> --output-dir <dirname> --system-dir <dirname> --datafile <filename> --encryption-key <key> --virtual-directory <string> --no-exe or --bat --icon <iconfile> --windows or --invisible --console or --visible --fileversion <string> # ex) 1,2,3,4 --productversion <string> # ex) 1,2,3,4 --productname <string> --originalfilename <string> --internalname <string> --description <string> --company <string> --trademarks <string> --copyright <string> --privatebuild <string> --specialbuild <string> --comments <string> HELP_MESSAGE end |
.output_version ⇒ Object
–version
152 153 154 |
# File 'lib/neri/build.rb', line 152 def output_version puts "Neri #{Neri::VERSION}" end |
.rb_dependencies ⇒ Object
check dependencies
334 335 336 |
# File 'lib/neri/build.rb', line 334 def rb_dependencies $LOADED_FEATURES.uniq end |
.relative_path(path, basedir = rubydir, prepath = "") ⇒ Object
83 84 85 86 |
# File 'lib/neri/build.rb', line 83 def relative_path(path, basedir = rubydir, prepath = "") basedir.concat(File::SEPARATOR) unless basedir.end_with?(File::SEPARATOR) path.start_with?(basedir) ? path.sub(basedir, prepath) : path end |
.ruby_command(path) ⇒ Object
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 |
# File 'lib/neri/build.rb', line 744 def ruby_command(path) system_dir = "#{path}#{File.join(@options[:system_dir], '')}" ruby_code = "" ruby_code = "Neri.key='#{@encryption_key}';" if @encryption_key if @options[:datafile] ruby_code += "Neri.datafile='#{system_dir}' + #{unpack_filename(@options[:datafile])};" if @options[:virtual_directory] ruby_code += "Neri.virtual_directory=#{unpack_filename(@options[:virtual_directory])};" end ruby_code += "load #{unpack_filename(File.basename(scriptfile))}" else ruby_code += "load File.expand_path('#{system_dir}' + #{unpack_filename(scriptfile)})" end r = " -rneri" r += " -rneri/dxruby" if @use_dxruby r += " -rneri/dxruby_tiled" if @use_dxruby_tiled r += " -rneri/ayame" if @use_ayame ruby = to_winpath(relative_path(rubyexe, bindir)) %(#{ruby}#{r} #{@rubyopt} -e "# coding:utf-8" -e "#{ruby_code}" #{@args}) end |
.ruby_dependencies ⇒ Object
392 393 394 395 396 |
# File 'lib/neri/build.rb', line 392 def ruby_dependencies dependencies = Dir.glob(File.join(bindir, "**", "*.manifest")) dependencies.push(rubyexe) dependencies.uniq end |
.rubydir ⇒ Object
93 |
# File 'lib/neri/build.rb', line 93 def rubydir ; File.join(RbConfig::TOPDIR, ""); end |
.rubyexe ⇒ Object
94 |
# File 'lib/neri/build.rb', line 94 def rubyexe ; RbConfig.ruby; end |
.run ⇒ Object
767 768 769 770 771 772 773 774 |
# File 'lib/neri/build.rb', line 767 def run dependencies = check_dependencies copy_files(dependencies) create_datafile @options[:no_exe] ? create_batfile : create_exefile nputs "Neri Finished." end |
.run_script ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/neri/build.rb', line 299 def run_script nputs "Running script '#{scriptfile}' to check dependencies." begin load File.(scriptfile) rescue SystemExit, Interrupt end nputs "Script '#{scriptfile}' end." if defined? DXRuby require "neri/dxruby" @use_dxruby = true end if defined? DXRuby::Tiled require "neri/dxruby_tiled" @use_dxruby_tiled = true end if defined? Ayame require "neri/ayame" @use_ayame = true end if @options[:invisible].nil? if File.extname(scriptfile) == ".rbw" || defined?(DXRuby) || defined?(Gosu) || defined?(LibUI) @options[:invisible] = true end end if @options[:pause_last].nil? && !@options[:invisible] @options[:pause_last] = true end end |
.scriptfile ⇒ Object
95 |
# File 'lib/neri/build.rb', line 95 def scriptfile; @data_files.first; end |
.select_dependencies(dependencies) ⇒ Object
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/neri/build.rb', line 459 def select_dependencies(dependencies) dependencies.select! do |dependency| dependency.start_with?(rubydir) end @data_files.each do |file| dependencies.delete(File.(file)) end unless @options[:enable_gems] dependencies.delete_if do |dependency| File.basename(dependency) == "rubygems.rb" || dependency.split(File::SEPARATOR).index("rubygems") end end unless @options[:enable_did_you_mean] dependencies.delete_if do |dependency| File.basename(dependency) == "did_you_mean.rb" || dependency.split(File::SEPARATOR).index("did_you_mean") end end dependencies.uniq end |
.to_winpath(path) ⇒ Object
88 89 90 |
# File 'lib/neri/build.rb', line 88 def to_winpath(path) File::ALT_SEPARATOR ? path.tr(File::SEPARATOR, File::ALT_SEPARATOR) : path end |