Skip to content

Commit dce3462

Browse files
committed
Make build.p6 more universal
We've been using an almost identical script for MoarVM, it's time to bring them back together. In theory, now it should be easy to throw in some other backends. Somehow I don't like the code here. Refactoring is welcome!
1 parent b2bd371 commit dce3462

File tree

1 file changed

+53
-28
lines changed

1 file changed

+53
-28
lines changed

build.p6

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,39 @@
1616
# You should have received a copy of the GNU Affero General Public License
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

19-
# This script will build rakudo for all commits that it can find
19+
# This script will build something for all commits that it can find
2020

2121
use File::Temp;
2222
use File::Directory::Tree;
2323

24-
constant PARALLEL-COUNT = 1;
25-
constant COMMIT-RANGE = 2015.07^..HEAD;
26-
constant TAGS-SINCE = 2014-01-01;
24+
enum Project <Rakudo-Moar Rakudo-JVM Rakudo-JS MoarVM>;
25+
my \PROJECT = do given @*ARGS[0] // {
26+
when /:i ^‘moarvm’$ / { MoarVM }
27+
default { Rakudo-Moar }
28+
}
29+
my \RAKUDOISH = PROJECT == Rakudo-Moar | Rakudo-JVM | Rakudo-JS;
30+
my \DIR-BASE = PROJECT.lc;
31+
32+
my \PARALLEL-COUNT = 1;
33+
my \COMMIT-RANGE = 2015.07^..HEAD;
34+
my \TAGS-SINCE = 2014-01-01;
35+
36+
my \WORKING-DIRECTORY = .; # TODO not supported yet
2737

28-
constant WORKING-DIRECTORY = .; # TODO not supported yet
38+
my \REPO-ORIGIN = RAKUDOISH
39+
?? https://github.com/rakudo/rakudo.git
40+
!! https://github.com/MoarVM/MoarVM.git;
2941

30-
constant RAKUDO-ORIGIN = https://github.com/rakudo/rakudo.git;
31-
constant RAKUDO-LATEST = /tmp/whateverable/rakudo-repo;
32-
constant RAKUDO-CURRENT = {WORKING-DIRECTORY}/rakudo.IO.absolute;
42+
my \REPO-LATEST = /tmp/whateverable/{DIR-BASE}-repo;
43+
# ↑ yes, separate cloned repo for every backend to prevent several
44+
# instances of this script fighting with each other
45+
my \REPO-CURRENT = {WORKING-DIRECTORY}/{DIR-BASE}.IO.absolute;
3346

34-
constant ARCHIVES-LOCATION = {WORKING-DIRECTORY}/builds/rakudo-moar.IO.absolute;
35-
constant BUILDS-LOCATION = /tmp/whateverable/rakudo-moar;
36-
constant BUILD-LOCK = /tmp/whateverable/build-lock;
47+
my \ARCHIVES-LOCATION = {WORKING-DIRECTORY}/builds/{DIR-BASE}.IO.absolute;
48+
my \BUILDS-LOCATION = /tmp/whateverable/{DIR-BASE};
49+
my \BUILD-LOCK = {BUILDS-LOCATION}/build-lock;
3750

38-
constant GIT-REFERENCE = WORKING-DIRECTORY.IO.absolute;
51+
my \GIT-REFERENCE = WORKING-DIRECTORY.IO.absolute;
3952

4053
mkdir BUILDS-LOCATION;
4154
mkdir ARCHIVES-LOCATION;
@@ -45,23 +58,22 @@ exit 0 unless run ‘mkdir’, :err(Nil), ‘--’, BUILD-LOCK; # only one insta
4558
my $locked = True;
4659
END BUILD-LOCK.IO.rmdir if $locked;
4760

48-
# TODO should we also pull nqp/ and MoarVM/ ?
49-
if RAKUDO-LATEST.IO ~~ :d {
61+
if REPO-LATEST.IO ~~ :d {
5062
my $old-dir = $*CWD;
5163
LEAVE chdir $old-dir;
52-
chdir RAKUDO-LATEST;
64+
chdir REPO-LATEST;
5365
run git, pull;
5466
} else {
55-
exit unless run git, clone, --, RAKUDO-ORIGIN, RAKUDO-LATEST;
67+
exit unless run git, clone, --, REPO-ORIGIN, REPO-LATEST;
5668
}
5769

58-
if RAKUDO-CURRENT.IO !~~ :d {
59-
run git, clone, --, RAKUDO-LATEST, RAKUDO-CURRENT;
70+
if REPO-CURRENT.IO !~~ :d {
71+
run git, clone, --, REPO-LATEST, REPO-CURRENT;
6072
}
6173

6274
my $channel = Channel.new;
6375

64-
my @git-latest = git, --git-dir, {RAKUDO-LATEST}/.git, --work-tree, RAKUDO-LATEST;
76+
my @git-latest = git, --git-dir, {REPO-LATEST}/.git, --work-tree, REPO-LATEST;
6577
my @args-tags = |@git-latest, log, -z, --pretty=%H, --tags, --no-walk, --since, TAGS-SINCE;
6678
my @args-latest = |@git-latest, log, -z, --pretty=%H, COMMIT-RANGE;
6779

@@ -79,8 +91,8 @@ await (for ^PARALLEL-COUNT { # TODO rewrite when .race starts working in rakudo
7991
}
8092
});
8193

82-
# update rakudo repo so that bots know about latest commits
83-
run git, --git-dir, {RAKUDO-CURRENT}/.git, --work-tree, RAKUDO-CURRENT, pull, --tags, RAKUDO-LATEST;
94+
# update repo so that bots know about latest commits
95+
run git, --git-dir, {REPO-CURRENT}/.git, --work-tree, REPO-CURRENT, pull, --tags, REPO-LATEST;
8496

8597
sub process-commit($commit) {
8698
return if {ARCHIVES-LOCATION}/$commit.zst.IO ~~ :e; # already exists
@@ -91,7 +103,7 @@ sub process-commit($commit) {
91103
my $archive-path = {ARCHIVES-LOCATION}/$commit.zst.IO.absolute;
92104

93105
# ⚡ clone
94-
run git, clone, -q, --, RAKUDO-LATEST, $temp-folder;
106+
run git, clone, -q, --, REPO-LATEST, $temp-folder;
95107
# ⚡ checkout to $commit
96108
my @git-temp = git, --git-dir, $temp-folder/.git, --work-tree, $temp-folder;
97109
run |@git-temp, reset, -q, --hard, $commit;
@@ -108,10 +120,20 @@ sub process-commit($commit) {
108120
say »»»»» $commit: configure;
109121
my $configure-log-fh = open :w, $log-path/configure.log;
110122
my $configure-err-fh = open :w, $log-path/configure.err;
111-
$config-ok = run(:out($configure-log-fh), :err($configure-err-fh),
112-
perl, --, Configure.pl,
113-
--gen-moar, --gen-nqp, --backends=moar, --prefix=$build-path,
114-
--git-reference={GIT-REFERENCE} );
123+
124+
my @args = do given PROJECT {
125+
when MoarVM {
126+
@args = perl, --, Configure.pl, --prefix=$build-path,
127+
--debug=3
128+
}
129+
when Rakudo-Moar {
130+
@args = perl, --, Configure.pl, --prefix=$build-path,
131+
--gen-moar, --gen-nqp, --backends=moar,
132+
--git-reference={GIT-REFERENCE}
133+
}
134+
}
135+
$config-ok = run :out($configure-log-fh), :err($configure-err-fh), |@args;
136+
115137
$configure-log-fh.close;
116138
$configure-err-fh.close;
117139
say »»»»» Cannot configure $commit unless $config-ok;
@@ -123,8 +145,11 @@ sub process-commit($commit) {
123145
say »»»»» $commit: make;
124146
my $make-log-fh = open :w, $log-path/make.log;
125147
my $make-err-fh = open :w, $log-path/make.err;
126-
$make-ok = run(:out($make-log-fh), :err($make-err-fh),
127-
make, -C, $temp-folder);
148+
my @args = do given PROJECT {
149+
when MoarVM { make, -j, 8, -C, $temp-folder }
150+
when Rakudo-Moar { make, -C, $temp-folder }
151+
}
152+
$make-ok = run :out($make-log-fh), :err($make-err-fh), |@args;
128153
$make-log-fh.close;
129154
$make-err-fh.close;
130155
say »»»»» Cannot make $commit unless $make-ok;

0 commit comments

Comments
 (0)