Skip to content

Commit 7c977fa

Browse files
authored
Merge pull request #2604 from byroot/ruby-sha
Support building from arbitrary git revision
2 parents d395d1a + 23a3fa9 commit 7c977fa

4 files changed

Lines changed: 54 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ The build process may be configured through the following environment variables:
123123
| `RUBY_MAKE_INSTALL_OPTS` | Additional `make install` options (applies only to Ruby source). |
124124
| `NO_COLOR` | Disable ANSI colors in output. The default is to use colors for output connected to a terminal. |
125125
| `CLICOLOR_FORCE` | Use ANSI colors in output even when not connected to a terminal. |
126+
| `RUBY_REPO` | The URL of the git repository to use when building `ruby-dev` |
127+
| `RUBY_REF` | The git branch (or revision) to use when building `ruby-dev`, e.g. `some-branch@af12decf` |
126128

127129
#### Applying Patches
128130

bin/ruby-build

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,18 @@ fetch_git() {
571571
local git_url="$2"
572572
local git_ref="$3"
573573

574+
local git_branch=${git_ref}
575+
local git_sha=''
576+
if [[ "${git_ref}" = *@* ]]; then
577+
git_branch="$(echo "${git_ref}" | cut -d@ -f 1)"
578+
git_sha="$(echo "${git_ref}" | cut -d@ -f 2)"
579+
fi
580+
581+
local depth_args=("--depth" "1")
582+
if [[ -n "${git_sha}" ]]; then
583+
depth_args=()
584+
fi
585+
574586
log_info "Cloning ${git_url}..."
575587

576588
if ! type git &>/dev/null; then
@@ -582,18 +594,24 @@ fetch_git() {
582594
local cache_dir
583595
cache_dir="$RUBY_BUILD_CACHE_PATH/$(sanitize "$git_url")"
584596
if [ -e "$cache_dir" ]; then
585-
log_command git -C "$cache_dir" fetch --force "$git_url" "+${git_ref}:${git_ref}" 2>&3
597+
log_command git -C "$cache_dir" fetch --force "$git_url" "+${git_branch}:${git_branch}" 2>&3
586598
else
587-
log_command git clone --bare --branch "$git_ref" "$git_url" "$cache_dir" 2>&3
599+
log_command git clone --bare --single-branch --branch "$git_branch" "$git_url" "$cache_dir" 2>&3
588600
fi
589601
git_url="$cache_dir"
590602
fi
591603

592604
if [ -e "$package_name" ]; then
593-
log_command git -C "$package_name" fetch --depth 1 origin "+${git_ref}" 2>&3
594-
log_command git -C "$package_name" checkout -q -B "$git_ref" "origin/${git_ref}" 2>&3
605+
log_command git -C "$package_name" fetch "${depth_args[@]}" origin "+${git_ref}" 2>&3
606+
if [ -z "${git_sha}" ]; then
607+
log_command git -C "$package_name" checkout -q -B "$git_branch" "origin/${git_branch}" 2>&3
608+
fi
595609
else
596-
log_command git clone --depth 1 --branch "$git_ref" "$git_url" "$package_name" 2>&3
610+
log_command git clone "${depth_args[@]}" --single-branch --branch "$git_branch" "$git_url" "$package_name" 2>&3
611+
fi
612+
613+
if [ -n "${git_sha}" ]; then
614+
log_command git -C "$package_name" checkout -q "$git_sha" 2>&3
597615
fi
598616
}
599617

share/ruby-build/ruby-dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
install_package "openssl-3.5.4" "https://github.com/openssl/openssl/releases/download/openssl-3.5.4/openssl-3.5.4.tar.gz#967311f84955316969bdb1d8d4b983718ef42338639c621ec4c34fddef355e99" openssl --if needs_openssl:1.1.1-3.x.x
2-
install_git "ruby-master" "https://github.com/ruby/ruby.git" "master" autoconf enable_shared standard_install_with_bundled_gems
2+
install_git "ruby-master" "${RUBY_REPO:-https://github.com/ruby/ruby.git}" "${RUBY_REF:-master}" autoconf enable_shared standard_install_with_bundled_gems

test/fetch.bats

100644100755
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ setup() {
3838
}
3939

4040
@test "fetching from git repository" {
41-
stub git "clone --depth 1 --branch master http://example.com/packages/package.git package-dev : mkdir package-dev"
41+
stub git "clone --depth 1 --single-branch --branch master http://example.com/packages/package.git package-dev : mkdir package-dev"
4242

4343
run_inline_definition <<DEF
4444
install_git "package-dev" "http://example.com/packages/package.git" master copy
@@ -48,6 +48,19 @@ DEF
4848
unstub git
4949
}
5050

51+
@test "fetching from git repository at specific ref" {
52+
stub git \
53+
"clone --single-branch --branch my-branch http://example.com/packages/package.git package-dev : mkdir package-dev" \
54+
"-C package-dev checkout -q deadbeef : true"
55+
56+
run_inline_definition <<DEF
57+
install_git "package-dev" "http://example.com/packages/package.git" my-branch@deadbeef copy
58+
DEF
59+
assert_success
60+
assert_output_contains "Cloning http://example.com/packages/package.git..."
61+
unstub git
62+
}
63+
5164
@test "updating existing git repository" {
5265
mkdir -p "${RUBY_BUILD_BUILD_PATH}/package-dev"
5366
stub git \
@@ -61,3 +74,17 @@ DEF
6174
assert_output_contains "Cloning http://example.com/packages/package.git..."
6275
unstub git
6376
}
77+
78+
@test "updating existing git repository at specific ref" {
79+
mkdir -p "${RUBY_BUILD_BUILD_PATH}/package-dev"
80+
stub git \
81+
"-C package-dev fetch origin +my-branch@deadbeef : true" \
82+
"-C package-dev checkout -q deadbeef : true"
83+
84+
run_inline_definition <<DEF
85+
install_git "package-dev" "http://example.com/packages/package.git" my-branch@deadbeef copy
86+
DEF
87+
assert_success
88+
assert_output_contains "Cloning http://example.com/packages/package.git..."
89+
unstub git
90+
}

0 commit comments

Comments
 (0)