Skip to content

Commit f6ce8a9

Browse files
author
Geoffrey Broadwell
committed
Refactor handling of COMPONENTS_DIR and checking whether setup has been done
1 parent 91def7b commit f6ce8a9

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

bench

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use JSON::Tiny;
1010
my ($PROGRAM_DIR) = ~($*PROGRAM_NAME ~~ /^(.*\/)/) // './';
1111
chdir $PROGRAM_DIR;
1212
$PROGRAM_DIR = cwd;
13+
my $COMPONENTS_DIR = "$PROGRAM_DIR/components";
14+
1315

1416
#= Show benchmark configuration
1517
multi MAIN ('config') {
@@ -28,14 +30,11 @@ multi MAIN ('setup') {
2830
my $components = from-json(slurp 'components.json');
2931

3032
say 'Cloning component repos ...';
31-
chdir 'components';
32-
my $comp_dir = cwd;
33-
3433
for $components.values -> $component {
3534
my $name = $component<name>;
3635
say "==> $name";
3736

38-
chdir $comp_dir;
37+
chdir $COMPONENTS_DIR;
3938
mkdir $name unless $name.IO.d;
4039
chdir $name;
4140

@@ -50,19 +49,14 @@ multi MAIN ('setup') {
5049

5150
#= Fetch latest commits in each cloned component
5251
multi MAIN ('fetch') {
53-
unless 'components'.IO.d {
54-
say "There is no 'components' tree, and thus there are no repos to fetch.";
55-
say "Please run `$*PROGRAM_NAME setup` instead.";
56-
return;
57-
}
52+
needs-setup('fetch');
5853

59-
chdir 'components';
60-
my $comp_dir = cwd;
54+
chdir $COMPONENTS_DIR;
6155

6256
for dir('.').sort -> $component-name {
6357
say "==> $component-name";
64-
my $bare = "$component-name/$component-name.git";
6558

59+
my $bare = "$component-name/$component-name.git";
6660
unless $bare.IO.d {
6761
say "No bare repository exists for component $component-name; can't fetch updates.";
6862
next;
@@ -73,6 +67,14 @@ multi MAIN ('fetch') {
7367
}
7468
}
7569

70+
sub needs-setup ($action) {
71+
unless $COMPONENTS_DIR.IO.d {
72+
say "There is no 'components' tree, and thus there are no repos to $action.";
73+
say "Please run `$*PROGRAM_NAME setup`.";
74+
exit 1;
75+
}
76+
}
77+
7678
multi MAIN ('build') {
7779
# %*ENV<GIT_DIR> = $bare;
7880
# my $tag_list = open 'git tag', :p;

0 commit comments

Comments
 (0)