Skip to content

Commit f56f318

Browse files
authored
Make installation relocatable, and the installation testable (verilator#4927)
Fixes verilator#4893
1 parent 3af0eb7 commit f56f318

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+504
-362
lines changed

.github/workflows/build.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ env:
1717
CCACHE_COMPRESS: 1
1818
CCACHE_DIR: ${{ github.workspace }}/.ccache
1919
CCACHE_LIMIT_MULTIPLE: 0.95
20+
INSTALL_DIR: ${{ github.workspace }}/install
21+
RELOC_DIR: ${{ github.workspace }}/relloc
2022

2123
defaults:
2224
run:
@@ -94,6 +96,7 @@ jobs:
9496
compiler:
9597
- { cc: clang, cxx: clang++ }
9698
- { cc: gcc, cxx: g++ }
99+
reloc: [0]
97100
suite: [dist-vlt-0, dist-vlt-1, dist-vlt-2, vltmt-0, vltmt-1]
98101
include:
99102
# Test with GCC 10 on ubuntu-20.04
@@ -102,14 +105,21 @@ jobs:
102105
- {os: ubuntu-20.04, compiler: { cc: gcc-10, cxx: g++-10 }, suite: dist-vlt-2}
103106
- {os: ubuntu-20.04, compiler: { cc: gcc-10, cxx: g++-10 }, suite: vltmt-0}
104107
- {os: ubuntu-20.04, compiler: { cc: gcc-10, cxx: g++-10 }, suite: vltmt-1}
108+
# Test relocated installation - on most common platform only
109+
- {os: ubuntu-22.04, compiler: { cc: gcc, cxx: g++ }, reloc: 1, suite: dist-vlt-0}
110+
- {os: ubuntu-22.04, compiler: { cc: gcc, cxx: g++ }, reloc: 1, suite: dist-vlt-1}
111+
- {os: ubuntu-22.04, compiler: { cc: gcc, cxx: g++ }, reloc: 1, suite: dist-vlt-2}
112+
- {os: ubuntu-22.04, compiler: { cc: gcc, cxx: g++ }, reloc: 1, suite: vltmt-0}
113+
- {os: ubuntu-22.04, compiler: { cc: gcc, cxx: g++ }, reloc: 1, suite: vltmt-1}
105114
runs-on: ${{ matrix.os }}
106-
name: Test | ${{ matrix.os }} | ${{ matrix.compiler.cc }} | ${{ matrix.suite }}
115+
name: Test | ${{ matrix.os }} | ${{ matrix.compiler.cc }} | ${{ matrix.reloc && 'reloc | ' || '' }} ${{ matrix.suite }}
107116
env:
108117
CI_BUILD_STAGE_NAME: test
109118
CI_RUNS_ON: ${{ matrix.os }}
119+
CI_RELOC: ${{ matrix.reloc }}
110120
CC: ${{ matrix.compiler.cc }}
111121
CXX: ${{ matrix.compiler.cxx }}
112-
CACHE_BASE_KEY: test-${{ matrix.os }}-${{ matrix.compiler.cc }}-${{ matrix.suite }}
122+
CACHE_BASE_KEY: test-${{ matrix.os }}-${{ matrix.compiler.cc }}-${{ matrix.reloc }}-${{ matrix.suite }}
113123
CCACHE_MAXSIZE: 100M # Per build per suite (* 5 * 5 = 2500M in total)
114124
VERILATOR_ARCHIVE: verilator-${{ github.sha }}-${{ matrix.os }}-${{ matrix.compiler.cc }}.tar.gz
115125
steps:

Makefile.in

+48-20
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,21 @@ verilator.html:
203203
verilator.pdf: Makefile
204204
$(MAKE) -C docs verilator.pdf
205205

206-
# See uninstall also - don't put wildcards in this variable, it might uninstall other stuff
207-
VL_INST_BIN_FILES = verilator verilator_bin$(EXEEXT) verilator_bin_dbg$(EXEEXT) verilator_coverage_bin_dbg$(EXEEXT) \
208-
verilator_ccache_report verilator_coverage verilator_difftree verilator_gantt verilator_includer verilator_profcfunc
209-
# Some scripts go into both the search path and pkgdatadir,
210-
# so they can be found by the user, and under $VERILATOR_ROOT.
206+
# Public executables intended to be invoked directly by the user
207+
# Don't put wildcards in these variables, it might cause an uninstall of other stuff
208+
VL_INST_PUBLIC_SCRIPT_FILES = verilator \
209+
verilator_coverage \
210+
verilator_gantt \
211+
verilator_profcfunc \
212+
213+
VL_INST_PUBLIC_BIN_FILES = verilator_bin$(EXEEXT) \
214+
verilator_bin_dbg$(EXEEXT) \
215+
verilator_coverage_bin_dbg$(EXEEXT) \
216+
217+
# Private executabels intended to be invoked by internals
218+
# Don't put wildcards in these variables, it might cause an uninstall of other stuff
219+
VL_INST_PRIVATE_SCRIPT_FILES = verilator_ccache_report \
220+
verilator_includer \
211221

212222
VL_INST_INC_BLDDIR_FILES = \
213223
include/verilated_config.h \
@@ -226,19 +236,34 @@ VL_INST_DATA_SRCDIR_FILES = \
226236
examples/*/Makefile* \
227237
examples/*/vl_* \
228238

229-
installbin:
230-
$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
231-
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator $(DESTDIR)$(bindir)/verilator )
232-
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_coverage $(DESTDIR)$(bindir)/verilator_coverage )
233-
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_gantt $(DESTDIR)$(bindir)/verilator_gantt )
234-
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_profcfunc $(DESTDIR)$(bindir)/verilator_profcfunc )
235-
( cd bin ; $(INSTALL_PROGRAM) verilator_bin$(EXEEXT) $(DESTDIR)$(bindir)/verilator_bin$(EXEEXT) )
236-
( cd bin ; $(INSTALL_PROGRAM) verilator_bin_dbg$(EXEEXT) $(DESTDIR)$(bindir)/verilator_bin_dbg$(EXEEXT) )
237-
( cd bin ; $(INSTALL_PROGRAM) verilator_coverage_bin_dbg$(EXEEXT) $(DESTDIR)$(bindir)/verilator_coverage_bin_dbg$(EXEEXT) )
239+
mkbindirs:
238240
$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/bin
239-
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_includer $(DESTDIR)$(pkgdatadir)/bin/verilator_includer )
240-
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_ccache_report $(DESTDIR)$(pkgdatadir)/bin/verilator_ccache_report )
241-
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_difftree $(DESTDIR)$(pkgdatadir)/bin/verilator_difftree )
241+
$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
242+
243+
installbin: | mkbindirs
244+
cd $(srcdir)/bin; \
245+
for p in $(VL_INST_PUBLIC_SCRIPT_FILES) ; do \
246+
$(INSTALL_PROGRAM) $$p $(DESTDIR)$(pkgdatadir)/bin/$$p; \
247+
done
248+
cd bin; \
249+
for p in $(VL_INST_PUBLIC_BIN_FILES) ; do \
250+
$(INSTALL_PROGRAM) $$p $(DESTDIR)$(pkgdatadir)/bin/$$p; \
251+
done
252+
cd $(srcdir)/bin; \
253+
for p in $(VL_INST_PRIVATE_SCRIPT_FILES) ; do \
254+
$(INSTALL_PROGRAM) $$p $(DESTDIR)$(pkgdatadir)/bin/$$p; \
255+
done
256+
257+
installredirect: installbin | mkbindirs
258+
cp ${srcdir}/bin/redirect ${srcdir}/bin/redirect.tmp
259+
perl -p -i -e 'use File::Spec;' \
260+
-e' $$path = File::Spec->abs2rel("$(realpath $(DESTDIR)$(pkgdatadir)/bin)", "$(realpath $(DESTDIR)$(bindir))");' \
261+
-e 's/RELPATH.*/"$$path";/g' -- "${srcdir}/bin/redirect.tmp"
262+
cd $(srcdir)/bin; \
263+
for p in $(VL_INST_PUBLIC_SCRIPT_FILES) $(VL_INST_PUBLIC_BIN_FILES) ; do \
264+
$(INSTALL_PROGRAM) redirect.tmp $(DESTDIR)$(bindir)/$$p; \
265+
done
266+
rm ${srcdir}/bin/redirect.tmp
242267

243268
# Man files can either be part of the original kit, or built in current directory
244269
# So important we use $^ so VPATH is searched
@@ -281,8 +306,11 @@ installdata:
281306

282307
# We don't trust rm -rf, so rmdir instead as it will fail if user put in other files
283308
uninstall:
284-
-cd $(DESTDIR)$(bindir) && rm -f $(VL_INST_BIN_FILES)
285-
-cd $(DESTDIR)$(pkgdatadir)/bin && rm -f $(VL_INST_BIN_FILES)
309+
-cd $(DESTDIR)$(bindir) && rm -f $(VL_INST_PUBLIC_SCRIPT_FILES)
310+
-cd $(DESTDIR)$(bindir) && rm -f $(VL_INST_PUBLIC_BIN_FILES)
311+
-cd $(DESTDIR)$(pkgdatadir)/bin && rm -f $(VL_INST_PUBLIC_SCRIPT_FILES)
312+
-cd $(DESTDIR)$(pkgdatadir)/bin && rm -f $(VL_INST_PUBLIC_BIN_FILES)
313+
-cd $(DESTDIR)$(pkgdatadir)/bin && rm -f $(VL_INST_PRIVATE_SCRIPT_FILES)
286314
-cd $(DESTDIR)$(mandir)/man1 && rm -f $(VL_INST_MAN_FILES)
287315
-cd $(DESTDIR)$(pkgdatadir) && rm -f $(VL_INST_INC_BLDDIR_FILES)
288316
-cd $(DESTDIR)$(pkgdatadir) && rm -f $(VL_INST_INC_SRCDIR_FILES)
@@ -311,7 +339,7 @@ uninstall:
311339
-rmdir $(DESTDIR)$(pkgconfigdir)
312340

313341
install: all_nomsg install-all
314-
install-all: installbin installman installdata install-msg
342+
install-all: installbin installredirect installman installdata install-msg
315343

316344
install-here: installman info
317345

bin/redirect

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env perl
2+
######################################################################
3+
#
4+
# Copyright 2003-2024 by Wilson Snyder. This program is free software; you
5+
# can redistribute it and/or modify it under the terms of either the GNU
6+
# Lesser General Public License Version 3 or the Perl Artistic License
7+
# Version 2.0.
8+
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
9+
#
10+
######################################################################
11+
12+
require 5.006_001;
13+
use warnings;
14+
use FindBin qw($RealBin $RealScript);
15+
use strict;
16+
17+
my $relpath = RELPATH; # Substituted during Verilator 'make install'
18+
19+
unshift @ARGV, $RealScript;
20+
21+
exec { "$RealBin/$relpath/$RealScript" } @ARGV;
22+
die "%Error: Exec failed,";

bin/verilator

+16-20
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use Getopt::Long;
1515
use FindBin qw($RealBin $RealScript);
1616
use IO::File;
1717
use Pod::Usage;
18+
use Cwd qw(realpath);
1819

1920
use strict;
2021
use vars qw($Debug @Opt_Verilator_Sw);
@@ -67,6 +68,18 @@ if (! GetOptions(
6768
pod2usage(-exitstatus => 2, -verbose => 0);
6869
}
6970

71+
my $verilator_root = realpath("$RealBin/..");
72+
if (defined $ENV{VERILATOR_ROOT}) {
73+
if ((!-d $ENV{VERILATOR_ROOT}) || $verilator_root ne realpath($ENV{VERILATOR_ROOT})) {
74+
warn "%Error: verilator: VERILATOR_ROOT is set to inconsistent path. Suggest leaving it unset.\n";
75+
warn "%Error: VERILATOR_ROOT=$ENV{VERILATOR_ROOT}\n";
76+
exit 1;
77+
}
78+
} else {
79+
print "export VERILATOR_ROOT='$verilator_root'\n" if $Debug;
80+
$ENV{VERILATOR_ROOT} = $verilator_root;
81+
}
82+
7083
if ($opt_gdbbt && !gdb_works()) {
7184
warn "-Info: --gdbbt ignored: gdb doesn't seem to be working\n" if $Debug;
7285
$opt_gdbbt = 0;
@@ -151,30 +164,13 @@ sub debug {
151164
# Builds
152165

153166
sub verilator_bin {
154-
my $bin = "";
155-
# Use VERILATOR_ROOT if defined, else assume verilator_bin is in the search path
156167
my $basename = ($ENV{VERILATOR_BIN}
157168
|| ($Debug ? "verilator_bin_dbg" : "verilator_bin"));
158-
if (defined($ENV{VERILATOR_ROOT})) {
159-
my $dir = $ENV{VERILATOR_ROOT};
160-
if (-x "$dir/bin/$basename"
161-
|| -x "$dir/bin/$basename.exe") { # From a "make install" into VERILATOR_ROOT
162-
$bin = "$dir/bin/$basename";
163-
} else {
164-
$bin = "$dir/$basename"; # From pointing to kit directory
165-
}
169+
if (-x "$RealBin/$basename" || -x "$RealBin/$basename.exe") {
170+
return "$RealBin/$basename";
166171
} else {
167-
if (-x "$RealBin/$basename"
168-
|| -x "$RealBin/$basename.exe") {
169-
$bin = "$RealBin/$basename"; # From path/to/verilator with verilator_bin installed
170-
} else {
171-
$bin = $basename; # Find in PATH
172-
}
173-
# Note we don't look under bin/$basename which would be right if running
174-
# in the kit dir. Running that would likely break, since
175-
# VERILATOR_ROOT wouldn't be set and Verilator won't find internal files.
172+
return $basename; # Find in PATH
176173
}
177-
return $bin;
178174
}
179175

180176
#######################################################################

ci/ci-script.bash

+20-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if [ "$CI_BUILD_STAGE_NAME" = "build" ]; then
4040

4141
if [ "$COVERAGE" != 1 ]; then
4242
autoconf
43-
./configure --enable-longtests --enable-ccwarn
43+
./configure --enable-longtests --enable-ccwarn --prefix="$INSTALL_DIR"
4444
ccache -z
4545
"$MAKE" -j "$NPROC" -k
4646
# 22.04: ccache -s -v
@@ -87,23 +87,37 @@ elif [ "$CI_BUILD_STAGE_NAME" = "test" ]; then
8787
# Run sanitize on Ubuntu 22.04 only
8888
[ "$CI_RUNS_ON" = 'ubuntu-22.04' ] && sanitize='--sanitize' || sanitize=''
8989

90+
TEST_REGRESS=test_regress
91+
if [ "$CI_RELOC" == 1 ]; then
92+
# Testing that the installation is relocatable.
93+
"$MAKE" install
94+
mkdir -p "$RELOC_DIR"
95+
mv "$INSTALL_DIR" "$RELOC_DIR/relocated-install"
96+
export VERILATOR_ROOT="$RELOC_DIR/relocated-install/share/verilator"
97+
TEST_REGRESS="$RELOC_DIR/test_regress"
98+
mv test_regress "$TEST_REGRESS"
99+
# Feeling brave?
100+
find . -delete
101+
ls -la .
102+
fi
103+
90104
# Run the specified test
91105
ccache -z
92106
case $TESTS in
93107
dist-vlt-0)
94-
"$MAKE" -C test_regress SCENARIOS="--dist --vlt $sanitize" DRIVER_HASHSET=--hashset=0/3
108+
"$MAKE" -C "$TEST_REGRESS" SCENARIOS="--dist --vlt $sanitize" DRIVER_HASHSET=--hashset=0/3
95109
;;
96110
dist-vlt-1)
97-
"$MAKE" -C test_regress SCENARIOS="--dist --vlt $sanitize" DRIVER_HASHSET=--hashset=1/3
111+
"$MAKE" -C "$TEST_REGRESS" SCENARIOS="--dist --vlt $sanitize" DRIVER_HASHSET=--hashset=1/3
98112
;;
99113
dist-vlt-2)
100-
"$MAKE" -C test_regress SCENARIOS="--dist --vlt $sanitize" DRIVER_HASHSET=--hashset=2/3
114+
"$MAKE" -C "$TEST_REGRESS" SCENARIOS="--dist --vlt $sanitize" DRIVER_HASHSET=--hashset=2/3
101115
;;
102116
vltmt-0)
103-
"$MAKE" -C test_regress SCENARIOS=--vltmt DRIVER_HASHSET=--hashset=0/2
117+
"$MAKE" -C "$TEST_REGRESS" SCENARIOS=--vltmt DRIVER_HASHSET=--hashset=0/2
104118
;;
105119
vltmt-1)
106-
"$MAKE" -C test_regress SCENARIOS=--vltmt DRIVER_HASHSET=--hashset=1/2
120+
"$MAKE" -C "$TEST_REGRESS" SCENARIOS=--vltmt DRIVER_HASHSET=--hashset=1/2
107121
;;
108122
coverage-all)
109123
nodist/code_coverage --stages 1-

test_regress/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
default: test
1717

1818
# This must point to the root of the VERILATOR kit
19-
VERILATOR_ROOT := $(shell pwd)/..
19+
VERILATOR_ROOT ?= $(shell pwd)/..
2020
export VERILATOR_ROOT
2121

2222
# Pick up PERL and other variable settings

test_regress/driver.pl

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ BEGIN
1212
}
1313
$ENV{MAKE} ||= "make";
1414
$ENV{CXX} ||= "c++";
15+
!defined $ENV{TEST_REGRESS} or die "TEST_REGRESS environment variable is already set";
16+
$ENV{TEST_REGRESS} = Cwd::getcwd();
1517
}
1618

1719
use Getopt::Long;
@@ -2484,7 +2486,7 @@ sub _vcd_read {
24842486
our $_Cxx_Version;
24852487

24862488
sub cxx_version {
2487-
$_Cxx_Version ||= `$ENV{MAKE} -C $ENV{VERILATOR_ROOT}/test_regress -f Makefile print-cxx-version`;
2489+
$_Cxx_Version ||= `$ENV{MAKE} -C $ENV{TEST_REGRESS} -f Makefile print-cxx-version`;
24882490
return $_Cxx_Version;
24892491
}
24902492

test_regress/t/t_a1_first_cc.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
$DEBUG_QUIET = "--debug --debugi 0 --gdbbt --no-dump-tree";
1818

19-
run(cmd => ["perl", "../bin/verilator", $DEBUG_QUIET, "-V"],
19+
run(cmd => ["perl", "$ENV{VERILATOR_ROOT}/bin/verilator", $DEBUG_QUIET, "-V"],
2020
verilator_run => 1,
2121
);
2222

test_regress/t/t_a5_attributes_include.pl

+5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010

1111
scenarios(dist => 1);
1212
rerunnable(0);
13+
14+
my $root = "..";
15+
1316
if ($ENV{VERILATOR_TEST_NO_ATTRIBUTES}) {
1417
skip("Skipping due to VERILATOR_TEST_NO_ATTRIBUTES");
18+
} elsif (!-r "$root/.git") {
19+
skip("Not in a git repository");
1520
} else {
1621
check();
1722
}

0 commit comments

Comments
 (0)