Skip to content

Commit e83d7ee

Browse files
committed
[Misc #21458] Add post-install-check
1 parent 9598ed9 commit e83d7ee

6 files changed

Lines changed: 103 additions & 4 deletions

File tree

.github/workflows/macos.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ jobs:
111111
run: |
112112
echo IRB::VERSION | make runirb RUNOPT="-- -f"
113113
114+
- name: make install
115+
run: make DESTDIR=../install install-nodoc
116+
114117
- name: Set test options for skipped tests
115118
run: |
116119
set -x

.github/workflows/ubuntu.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ jobs:
103103
run: |
104104
echo IRB::VERSION | $SETARCH make runirb RUNOPT="-- -f"
105105
106+
- name: make install
107+
run: make DESTDIR=../install install-nodoc
108+
106109
- name: Set test options for skipped tests
107110
run: |
108111
set -x

.github/workflows/windows.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ jobs:
176176

177177
- run: nmake
178178

179+
- name: nmake install
180+
run: nmake DESTDIR=../install install-nodoc
181+
179182
- name: Set up Launchable
180183
uses: ./.github/actions/launchable/setup
181184
with:

common.mk

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,18 +493,26 @@ $(ruby_pc): $(srcdir)/template/ruby.pc.in config.status
493493

494494
INSTALL_ALL = all
495495

496-
install-all: pre-install-all do-install-all post-install-all
496+
post-install-check: $(LIBRUBY_RELATIVE)-post-install-check
497+
498+
yes-post-install-check:
499+
$(DESTDIR)$(bindir)/$(PROGRAM) -C $(srcdir) tool/post-install.rb
500+
no-post-install-check:
501+
502+
install-all: pre-install-all do-install-all $(DOT_WAIT) post-install-all
497503
pre-install-all:: all pre-install-local pre-install-ext pre-install-gem pre-install-doc
498504
do-install-all: pre-install-all $(DOT_WAIT) docs
499505
$(INSTRUBY) --make="$(MAKE)" $(INSTRUBY_ARGS) --install=$(INSTALL_ALL) $(INSTALL_DOC_OPTS)
500-
post-install-all:: post-install-local post-install-ext post-install-gem post-install-doc
506+
post-install-all:: post-install-local post-install-ext post-install-gem post-install-doc \
507+
$(DOT_WAIT) $(TEST_RUNNABLE:yes=post-install-check)
501508
@$(NULLCMD)
502509

503-
install-nodoc: pre-install-nodoc do-install-nodoc post-install-nodoc
510+
install-nodoc: pre-install-nodoc do-install-nodoc $(DOT_WAIT) post-install-nodoc
504511
pre-install-nodoc:: pre-install-local pre-install-ext pre-install-gem
505512
do-install-nodoc: main pre-install-nodoc
506513
$(INSTRUBY) --make="$(MAKE)" $(INSTRUBY_ARGS) --install=$(INSTALL_ALL) --exclude=doc
507-
post-install-nodoc:: post-install-local post-install-ext post-install-gem
514+
post-install-nodoc:: post-install-local post-install-ext post-install-gem \
515+
$(DOT_WAIT) $(TEST_RUNNABLE:yes=post-install-check)
508516

509517
install-local: pre-install-local do-install-local post-install-local
510518
pre-install-local:: pre-install-bin pre-install-lib pre-install-man

template/Makefile.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,9 @@ yes-test-syntax-suggest: $(PREPARE_SYNTAX_SUGGEST)
716716
$(ACTIONS_ENDGROUP)
717717
no-test-syntax-suggest:
718718

719+
no-post-install-check:
720+
[ -n "$(DESTDIR)" ] || $(bindir)/$(PROGRAM) -C $(srcdir) tool/post-install.rb
721+
719722
yesterday:
720723
$(GIT) -C $(srcdir) reset --hard \
721724
`$(GIT) -C $(srcdir) log -1 --before=00:00+0900 --format=%H`

tool/post-install.rb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# frozen-string-literal: true
2+
3+
# Based on https://github.com/ruby/ruby-dev-builder/blob/master/cli_test.rb
4+
5+
require 'rbconfig'
6+
7+
module CLITest
8+
class << self
9+
BIN_DIR = RbConfig::CONFIG['bindir']
10+
RUBY_INSTALL_NAME = RbConfig::CONFIG["ruby_install_name"]
11+
abort unless RUBY_INSTALL_NAME.include?("ruby")
12+
13+
ENV["PATH"] = [BIN_DIR, ENV["PATH"]].compact.join(File::PATH_SEPARATOR)
14+
15+
DASH = "\u2500"
16+
PASSED = "\u{2705}"
17+
FAILED = "\u{274c}"
18+
19+
def executable_name(name)
20+
"#{BIN_DIR}/#{RUBY_INSTALL_NAME.sub("ruby", name)}"
21+
end
22+
23+
def chk_cli(cmd, regex)
24+
cmd_name, args = cmd.split(" ", 2)
25+
cmd_str = cmd_name.ljust(10)
26+
exec_name = executable_name(cmd_name)
27+
cmd = [exec_name, args].compact.join(" ")
28+
if File.exist? exec_name
29+
ret = IO.popen(cmd, in: IO::NULL, err: IO::NULL, &:gets).chomp
30+
ret.sub!(exec_name, cmd_name)
31+
if ret[regex]
32+
"#{cmd_str}#{PASSED} #{$1}"
33+
else
34+
@error += 1
35+
"#{cmd_str}#{FAILED} version? (#{ret})"
36+
end
37+
else
38+
@error += 1
39+
"#{cmd_str}#{FAILED} missing binstub"
40+
end
41+
rescue => e
42+
@error += 1
43+
"#{cmd_str}#{FAILED} #{e.class}"
44+
end
45+
46+
def run
47+
re_version = '(\d{1,2}\.\d{1,2}\.\d{1,2}(\.[a-z0-9.]+)?)'
48+
@error = 0
49+
puts "\n#{DASH * 5} CLI Test #{DASH * 17}"
50+
puts chk_cli("bundle -v", /\ABundler version #{re_version}/)
51+
puts chk_cli("gem --version", /\A#{re_version}/)
52+
puts chk_cli("irb --version", /\Airb +#{re_version}/)
53+
puts chk_cli("racc --version", /\Aracc version #{re_version}/)
54+
puts chk_cli("rake -V", /\Arake, version #{re_version}/)
55+
puts chk_cli("rbs -v", /\Arbs #{re_version}\z/)
56+
puts chk_cli("rdbg -v", /\Ardbg #{re_version}\z/)
57+
puts chk_cli("rdoc -v", /\A#{re_version}/)
58+
puts ''
59+
60+
cli_desc = %x[#{executable_name("ruby")} -v][/\A.*/]
61+
if cli_desc == RUBY_DESCRIPTION
62+
puts cli_desc, ''
63+
else
64+
puts "'ruby -v' doesn't match RUBY_DESCRIPTION\n" \
65+
"#{cli_desc} (ruby -v)\n" \
66+
"#{RUBY_DESCRIPTION} (RUBY_DESCRIPTION)", ''
67+
@error += 1
68+
end
69+
70+
unless @error.zero?
71+
abort "bad exit"
72+
end
73+
end
74+
end
75+
end
76+
77+
if $0 == __FILE__
78+
CLITest.run
79+
end

0 commit comments

Comments
 (0)