#!/usr/bin/env ruby # frozen_string_literal: true # Copyright (c) 2023-2024 [Ribose Inc](https://www.ribose.com). # All rights reserved. # This file is a part of tebako # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. require_relative "../lib/tebako/packager" require_relative "../lib/tebako/ruby_version" require_relative "../lib/tebako/stripper" require_relative "../lib/tebako/build_helpers" begin unless ARGV.length.positive? raise Tebako::Error, "tebako-packager needs at least 1 argument (command), none has been provided." end case ARGV[0] when "pass1" # ARGV[0] -- command # ARGV[1] -- OSTYPE # ARGV[2] -- RUBY_SOURCE_DIR # ARGV[3] -- FS_MOUNT_POINT # ARGV[4] -- DATA_SRC_DIR # ARGV[5] -- RUBY_VER unless ARGV.length == 6 raise Tebako::Error, "tebako-packager pass1 command expects 6 arguments, #{ARGV.length} has been provided." end ruby_ver = Tebako::RubyVersion.new(ARGV[5]) Tebako::Packager.pass1(ARGV[1], ARGV[2], ARGV[3], ARGV[4], ruby_ver) when "pass2" # ARGV[0] -- command # ARGV[1] -- OSTYPE # ARGV[2] -- RUBY_SOURCE_DIR # ARGV[3] -- DEPS_LIB_DIR # ARGV[4] -- DATA_SRC_DIR # ARGV[5] -- RUBY_STASH_DIR # ARGV[6] -- RUBY_VER unless ARGV.length == 7 raise Tebako::Error, "tebako-packager pass2 command expects 7 arguments, #{ARGV.length} has been provided." end ruby_ver = Tebako::RubyVersion.new(ARGV[6]) Tebako::Packager.pass1a(ARGV[2]) Tebako::Packager.stash(ARGV[4], ARGV[5], ARGV[2], ruby_ver) Tebako::Packager.pass2(ARGV[1], ARGV[2], ARGV[3], ruby_ver) when "finalize" # ARGV[0] -- command # ARGV[1] -- OSTYPE # ARGV[2] -- RUBY_SOURCE_DIR # ARGV[3] -- APP_NAME # ARGV[4] -- RUBY_VER # ARGV[5] -- patchelf executable # ARGV[6] -- WITH_PATHELF unless ARGV.length == 7 raise Tebako::Error, "tebako-packager finalize command expects 7 arguments, #{ARGV.length} has been provided." end ruby_ver = Tebako::RubyVersion.new(ARGV[4]) with_patchelf = ARGV[6].casecmp("ON").zero? || ARGV[6].casecmp("YES").zero? Tebako::Packager.finalize(ARGV[1], ARGV[2], ARGV[3], ruby_ver, with_patchelf ? ARGV[5] : nil) else raise Tebako::Error, "tebako-packager cannot process #{ARGV[0]} command" end rescue Tebako::Error => e puts "tebako-packager failed: #{e.message} [#{e.error_code}]" exit(e.error_code) end exit(0)