Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move patcher to thor command patch #284

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ ExternalProject_Add(${RUBY_PRJ}
SOURCE_DIR ${RUBY_SOURCE_DIR}
BUILD_IN_SOURCE true
CONFIGURE_COMMAND ""
BUILD_COMMAND ruby ${EXE}/tebako-packager pass1 ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${FS_MOUNT_POINT} ${DATA_SRC_DIR} ${RUBY_VER}
BUILD_COMMAND ruby ${EXE}/tebako patch pass1 --ostype=${OSTYPE_TXT} --ruby-source-dir=${RUBY_SOURCE_DIR} --fs-mount-point=${FS_MOUNT_POINT} --data-src-dir=${DATA_SRC_DIR} --ruby-ver=${RUBY_VER}
# Make it for MacOS otherwise LDFLAGS are invalid
# COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_LIB_DIR}
COMMAND ${GNU_BASH} -c "${RUBY_SOURCE_DIR}/configure ${OPENSSL_RUBY_OPTION} ${LIBYAML_RUBY_OPTION} \
Expand All @@ -381,7 +381,7 @@ ExternalProject_Add(${RUBY_PRJ}
--prefix=${DATA_SRC_DIR} \
${C_FLAGS_DEST}=\"${RUBY_C_FLAGS}\" \
LDFLAGS=\"${RUBY_L_FLAGS}\""
COMMAND ruby ${EXE}/tebako-packager pass2 ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${DEPS_LIB_DIR} ${DATA_SRC_DIR} ${RUBY_STASH_DIR} ${RUBY_VER}
COMMAND ruby ${EXE}/tebako patch pass2 --ostype=${OSTYPE_TXT} --ruby-source-dir=${RUBY_SOURCE_DIR} --deps-lib-dir=${DEPS_LIB_DIR} --data-src-dir=${DATA_SRC_DIR} --ruby-stash-dir=${RUBY_STASH_DIR} --ruby-ver=${RUBY_VER}
INSTALL_COMMAND ""
)

Expand Down
8 changes: 8 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ Removes Tebako Ruby artifacts.
`hash`::
Calculates the Tebako script hash for use as a cache key in CI/CD environments.

`patch`::
Ruby patching commands for low-level operations.
+
Subcommands include:
+
* `pass1`: Run pass1 Ruby patching operations for preparing the build environment
* `pass2`: Run pass2 Ruby patching operations for creating the packaging environment

`version`::
Displays the Tebako version.

Expand Down
77 changes: 0 additions & 77 deletions exe/tebako-packager

This file was deleted.

1 change: 1 addition & 0 deletions lib/tebako.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ module Tebako

require_relative "tebako/version"
require_relative "tebako/error"
require_relative "tebako/cli"
4 changes: 4 additions & 0 deletions lib/tebako/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
require_relative "cache_manager"
require_relative "cli_helpers"
require_relative "error"
require_relative "patch_commands"
require_relative "ruby_version"
require_relative "scenario_manager"
require_relative "version"
Expand Down Expand Up @@ -138,6 +139,9 @@ def setup
exit e.error_code
end

desc "patch SUBCOMMAND ...ARGS", "Ruby patching commands"
subcommand "patch", PatchCommands

def self.exit_on_failure?
true
end
Expand Down
8 changes: 4 additions & 4 deletions lib/tebako/cli_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module CliHelpers
* It is not an error but we do not recommend it because it is a way to keep packaging old versions recrsively. *
* *
* For example, ensure that `--root=` differs from `--output=` as described in README.adoc: *
* tebako press --root='~/projects/myproject' --entry=start.rb --output=/temp/myproject.tebako *
* `tebako press --root='~/projects/myproject' --entry=start.rb --output=/temp/myproject.tebako` *
* *
******************************************************************************************************************

Expand All @@ -60,11 +60,11 @@ module CliHelpers
******************************************************************************************************************
* *
* WARNING: You are creating packaging environment inside application root. *
* It is not an error but it means that all build-time artifacts will ne included in tebako package. *
* It is not an error but it means that all build-time artifacts will be included in tebako package. *
* You do not need it unless under very special circumstances like tebako packaging tebako itself. *
* *
* Please consider removing your exisitng `--prefix` folder abd use another one that points outside of `--root` *
* like tebako press --r ~/projects/myproject -e start.rb -o /temp/myproject.tebako -p ~/.tebako *
* Please consider removing your existing `--prefix` folder and use another one that points outside of `--root` *
* like `tebako press --r ~/projects/myproject -e start.rb -o /temp/myproject.tebako -p ~/.tebako` *
* *
******************************************************************************************************************

Expand Down
79 changes: 79 additions & 0 deletions lib/tebako/patch_commands.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

# Copyright (c) 2025 [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 "thor"
require_relative "packager"
require_relative "ruby_version"
require_relative "stripper"
require_relative "build_helpers"

module Tebako
# Thor-based command set for Ruby patching operations
class PatchCommands < Thor
desc "pass1", "Run pass1 Ruby patching operations"
method_option :ostype, type: :string, required: true, desc: "Operating system type"
method_option :ruby_source_dir, type: :string, required: true, desc: "Ruby source directory"
method_option :fs_mount_point, type: :string, required: true, desc: "Filesystem mount point"
method_option :data_src_dir, type: :string, required: true, desc: "Data source directory"
method_option :ruby_ver, type: :string, required: true, desc: "Ruby version string"

# Method to run pass1 operations
def pass1
ostype = options[:ostype]
ruby_source_dir = options[:ruby_source_dir]
mount_point = options[:fs_mount_point]
data_src_dir = options[:data_src_dir]
ruby_ver_str = options[:ruby_ver]

ruby_ver = Tebako::RubyVersion.new(ruby_ver_str)
Tebako::Packager.pass1(ostype, ruby_source_dir, mount_point, data_src_dir, ruby_ver)
end

desc "pass2", "Run pass2 Ruby patching operations"
method_option :ostype, type: :string, required: true, desc: "Operating system type"
method_option :ruby_source_dir, type: :string, required: true, desc: "Ruby source directory"
method_option :deps_lib_dir, type: :string, required: true, desc: "Dependencies library directory"
method_option :data_src_dir, type: :string, required: true, desc: "Data source directory"
method_option :ruby_stash_dir, type: :string, required: true, desc: "Ruby stash directory"
method_option :ruby_ver, type: :string, required: true, desc: "Ruby version string"

# Method to run pass2 operations
def pass2 # rubocop:disable Metrics/AbcSize
ostype = options[:ostype]
ruby_source_dir = options[:ruby_source_dir]
deps_lib_dir = options[:deps_lib_dir]
data_src_dir = options[:data_src_dir]
ruby_stash_dir = options[:ruby_stash_dir]
ruby_ver_str = options[:ruby_ver]

ruby_ver = Tebako::RubyVersion.new(ruby_ver_str)
Tebako::Packager.pass1a(ruby_source_dir)
Tebako::Packager.stash(data_src_dir, ruby_stash_dir, ruby_source_dir, ruby_ver)
Tebako::Packager.pass2(ostype, ruby_source_dir, deps_lib_dir, ruby_ver)
end
end
end
Loading