Skip to content

Commit

Permalink
chore: refactor pass2 patching
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Feb 7, 2025
1 parent fe04f30 commit ac5c13f
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 18
CACHE_VER: 19
TZ: "Etc/UTC"
VERBOSE: no

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gem-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 18
CACHE_VER: 19
DEBIAN_FRONTEND: "noninteractive"
TZ: "Etc/UTC"
# show cmake output
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 18
CACHE_VER: 19
VERBOSE: no

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 18
CACHE_VER: 19
DEBIAN_FRONTEND: "noninteractive"
TZ: "Etc/UTC"
# show cmake output (yes/no)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-msys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 18
CACHE_VER: 19
VERBOSE: no

jobs:
Expand Down
5 changes: 3 additions & 2 deletions lib/tebako/packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
require_relative "stripper"
require_relative "packager/pass1_patch"
require_relative "packager/pass1a_patch"
require_relative "packager/pass2"
require_relative "packager/pass2_patch"
require_relative "packager/patch_helpers"

# Tebako - an executable packager
Expand Down Expand Up @@ -150,7 +150,8 @@ def pass1a(ruby_source_dir)
def pass2(ostype, ruby_source_dir, deps_lib_dir, ruby_ver)
puts "-- Running pass2 script"

do_patch(Pass2.get_patch_map(ostype, deps_lib_dir, ruby_ver), ruby_source_dir)
patch = Pass2Patch.new(ostype, deps_lib_dir, ruby_ver).patch_map
do_patch(patch, ruby_source_dir)
end

# Stash
Expand Down
150 changes: 0 additions & 150 deletions lib/tebako/packager/pass2.rb

This file was deleted.

154 changes: 154 additions & 0 deletions lib/tebako/packager/pass2_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# frozen_string_literal: true

# Copyright (c) 2021-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 "patch_literals"
require_relative "patch_main"
require_relative "patch_libraries"
require_relative "patch_helpers"
require_relative "patch_buildsystem"

# Tebako - an executable packager
module Tebako
module Packager
# Ruby patching definitions (pass2)
class Pass2Patch < Patch
def initialize(ostype, deps_lib_dir, ruby_ver)
super()
@ostype = ostype
@scmb = ScenarioManagerBase.new(@ostype)
@deps_lib_dir = deps_lib_dir
@ruby_ver = ruby_ver
end

def patch_map
patch_map = patch_map_base
patch_map.store("thread_pthread.c", LINUX_MUSL_THREAD_PTHREAD_PATCH) if @scmb.musl?
if @scmb.msys?
patch_map.merge!(msys_patches)
elsif @ruby_ver.ruby3x?
patch_map.store("common.mk", COMMON_MK_PATCH)
end
extend_patch_map_r33(patch_map)
patch_map.store("prism_compile.c", PRISM_PATCHES) if @ruby_ver.ruby34?
patch_map
end

private

include Tebako::Packager::PatchBuildsystem
include Tebako::Packager::PatchLiterals
def extend_patch_map_r33(patch_map)
if @ruby_ver.ruby33? || @scmb.msys?
patch_map.store("config.status",
get_config_status_patch(@ostype, @deps_lib_dir, @ruby_ver))
end
patch_map
end

def dir_c_patch
pattern = ScenarioManagerBase.new.msys? ? "/* define system APIs */" : "#ifdef HAVE_GETATTRLIST"
patch = PatchHelpers.patch_c_file_pre(pattern)
patch.merge!(DIR_C_BASE_PATCH)
patch
end

def dln_c_patch
pattern = "#ifndef dln_loaderror"
# Not using substitutions of dlxxx functions on Windows
patch = {
pattern => "#{@scmb.msys? ? C_FILE_SUBST_LESS : C_FILE_SUBST}\n#{pattern}\n"
}

if @scmb.msys?
patch.merge!(@ruby_ver.ruby32? ? DLN_C_MSYS_PATCH : DLN_C_MSYS_PATCH_PRE32)
end

patch
end

def io_c_msys_patch
patch = @ruby_ver.ruby32? ? IO_C_MSYS_PATCH : IO_C_MSYS_PATCH_PRE_32
patch.merge(IO_C_MSYS_BASE_PATCH)
end

def io_c_patch
patch = PatchHelpers.patch_c_file_pre("/* define system APIs */")
patch.merge!(io_c_msys_patch) if @scmb.msys?
patch
end

def util_c_patch
if @ruby_ver.ruby31?
PatchHelpers.patch_c_file_post("#endif /* !HAVE_GNU_QSORT_R */")
else
PatchHelpers.patch_c_file_pre("#ifndef S_ISDIR")
end
end

def tool_mkconfig_rb_patch
subst = @scmb.msys? ? TOOL_MKCONFIG_RB_SUBST_MSYS : TOOL_MKCONFIG_RB_SUBST
{
" if fast[name]" => subst
}
end

def msys_patches
{
"cygwin/GNUmakefile.in" => get_gnumakefile_in_patch_p2(@ruby_ver),
"ruby.c" => RUBY_C_MSYS_PATCHES,
"win32/file.c" => WIN32_FILE_C_MSYS_PATCHES,
"win32/win32.c" => WIN32_WIN32_C_MSYS_PATCHES
}
end

def patch_map_base
{
"template/Makefile.in" => template_makefile_in_patch,
"tool/mkconfig.rb" => tool_mkconfig_rb_patch,
"dir.c" => dir_c_patch, "dln.c" => dln_c_patch,
"io.c" => io_c_patch, "main.c" => PatchMain.get_main_c_patch(@ruby_ver),
"file.c" => PatchHelpers.patch_c_file_pre("/* define system APIs */"),
"util.c" => util_c_patch
}
end

def mlibs_subst
yjit_libs = @ruby_ver.ruby32only? ? "$(YJIT_LIBS) " : ""
{
"MAINLIBS = #{yjit_libs}@MAINLIBS@" =>
"# -- Start of tebako patch -- \n" \
"MAINLIBS = #{yjit_libs}#{PatchLibraries.mlibs(@ostype, @deps_lib_dir, @ruby_ver, true)}\n" \
"# -- End of tebako patch -- \n"
}
end

def template_makefile_in_patch
template_makefile_in_patch_two(@ruby_ver).merge(mlibs_subst)
end
end
end
end
Loading

0 comments on commit ac5c13f

Please sign in to comment.