Skip to content

Commit

Permalink
Implement --git-cache-dir Configure.pl option
Browse files Browse the repository at this point in the history
This option makes the configure process create / update git repositories
for all of its submodules and NQP in the given folders and use those
as reference repos. The option is forwarded to a potential NQP
sub-build.

Also remove stale documentation for a not anymore implemented
`--git-reference` option. I suspect it was lost during the great build
system refactor.
  • Loading branch information
PatZim committed Feb 11, 2020
1 parent 4437723 commit 322b095
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 49 deletions.
75 changes: 27 additions & 48 deletions Configure.pl
Expand Up @@ -10,38 +10,18 @@
use Cwd;
use FindBin;


BEGIN {
if ( -d '.git' ) {
my $set_config = !qx{git config rakudo.initialized};
unless ( -e '3rdparty/nqp-configure/LICENSE' ) {
print "Updating nqp-configure submodule...\n";
my $msg =
qx{git submodule sync --quiet 3rdparty/nqp-configure && git submodule --quiet update --init 3rdparty/nqp-configure 2>&1};
if ( $? >> 8 == 0 ) {
say "OK";
$set_config = 1;
}
else {
if ( $msg =~
/[']([^']+)[']\s+already exists and is not an empty/ )
{
print "\n===SORRY=== ERROR: "
. "Cannot update submodule because directory exists and is not empty.\n"
. ">>> Please delete the following folder and try again:\n$1\n\n";
exit 1;
}
else {
print "\n===SORRY=== ERROR: "
. "Updating the submodule failed for an unknown reason. The error message was:\n"
. $msg;
exit 1;
}
}
}
if ($set_config) {
system("git config submodule.recurse true");
system("git config rakudo.initialized 1");
}
# Download / Update submodules
my $set_config = !qx{git config rakudo.initialized};
if ( !-e '3rdparty/nqp-configure/LICENSE' ) {
my $code = system($^X, 'tools/build/update-submodules.pl', Cwd::cwd(), @ARGV);
exit 1 if $code >> 8 != 0;
$set_config = 1;
}
if ($set_config) {
system("git config submodule.recurse true");
system("git config rakudo.initialized 1");
}
}

Expand Down Expand Up @@ -78,13 +58,13 @@ BEGIN
'gen-moar:s', 'moar-option=s@',
'git-protocol=s', 'ignore-errors!',
'make-install!', 'makefile-timing!',
'git-depth=s', 'git-reference=s',
'git-depth=s', 'git-cache-dir=s',
'github-user=s', 'rakudo-repo=s',
'nqp-repo=s', 'moar-repo=s',
'roast-repo=s', 'expand=s',
'out=s', 'set-var=s@',
'silent-build!', 'raku-alias!',
'force-rebuild!'
'force-rebuild!', 'git-reference=s'
)
or do {
print_help();
Expand Down Expand Up @@ -163,8 +143,7 @@ sub print_help {
--nqp-home=dir Directory to install NQP files to
--perl6-home=dir, --rakudo-home=dir
Directory to install Rakudo files to
--relocatable
Dynamically locate NQP and Perl6 home dirs instead of
--relocatable Dynamically locate NQP and Perl6 home dirs instead of
statically compiling them in. (On AIX and OpenBSD Rakudo
is always built non-relocatable, since both OSes miss a
necessary mechanism.)
Expand All @@ -174,18 +153,15 @@ sub print_help {
--sysroot=<path> When given, use for searching runtime components here
--backends=jvm,moar,js
Which backend(s) to use (or ALL for all of them)
--gen-nqp[=branch]
Download, build, and install a copy of NQP before writing
--gen-nqp[=branch] Download, build, and install a copy of NQP before writing
the Makefile
--gen-moar[=branch]
Download, build, and install a copy of MoarVM to use
before writing the Makefile
--force-rebuild
Together with --gen-* options causes corresponding
--force-rebuild Together with --gen-* options causes corresponding
components to recompile irrelevant to their existence and
version conformance.
--with-nqp=<path>
Provide path to already installed nqp
--with-nqp=<path> Provide path to already installed nqp
--make-install Install Rakudo after configuration is done
--moar-option='--option=value'
Options to pass to MoarVM's Configure.pl
Expand All @@ -197,17 +173,20 @@ sub print_help {
--rakudo-repo=<url>
--nqp-repo=<url>
--moar-repo=<url>
--roast-repo=<url>
User-defined URL to fetch corresponding components
--roast-repo=<url> User-defined URL to fetch corresponding components
from. The URL will also be used to setup git push.
--git-protocol={ssh,https,git}
Protocol used for cloning git repos
--git-depth=<number>
Use the --git-depth option for git clone with parameter number
--git-reference=<path>
Use --git-reference option to identify local path where git repositories are stored
For example: --git-reference=/home/user/repo/for_perl6
Folders 'nqp' and 'MoarVM' with corresponding git repos should be in for_perl6 folder
Use the --git-depth option for git clone with parameter
number
--git-cache-dir=<path>
Use the given path as a git repository cache.
For example: --git-cache-dir=/home/user/git_cache_dir
Each repository ('nqp' and its submodules) will use a
separate subfolder.
If the subfolder does not exist, it will be cloned. If
it exists the contained repository will be updated.
--makefile-timing Enable timing of individual makefile commands
--no-clean Skip cleanup before installation
--ignore-errors Ignore errors (such as the version of NQP)
Expand Down
101 changes: 101 additions & 0 deletions tools/build/update-submodules.pl
@@ -0,0 +1,101 @@
#!/usr/bin/env perl
# Copyright (C) 2009-2019 The Perl Foundation

use 5.10.1;
use strict;
use warnings;
use Getopt::Long;
use Cwd;
use File::Spec;

my $msg;

my $repo = shift @ARGV;
chdir $repo;

exit 0 if !-d '.git';

my $git_cache_dir;
Getopt::Long::Configure("pass_through");
Getopt::Long::GetOptions('git-cache-dir=s' => \$git_cache_dir);

print 'Updating submodules .................................... ';

exec_and_check('git submodule sync --quiet 2>&1', 'Submodule sync failed for an unknown reason.');
exec_and_check('git submodule --quiet init 2>&1', 'Submodule init failed for an unknown reason.');

if ($git_cache_dir) {
my $out = qx{git submodule status 2>&1};
if ($? >> 8 != 0) {
print "\n===SORRY=== ERROR: Submodule status failed for an unknown reason.\n";
print "The error message was: $out\n";
exit 1;
}
for my $smodline (split(/^/m, $out)) {
chomp $smodline;
if ($smodline !~ /^.[0-9a-f]+ ([^ ]+)(?:$| )/) {
print "\n===SORRY=== ERROR: "
. "Submodule status output looks unexpected: '$smodline'";
exit 1;
}
my $smodpath = $1;
my $smodname = (File::Spec->splitdir($smodpath))[-1];
my $modrefdir = File::Spec->catdir($git_cache_dir, $smodname);
my $url = qx{git config submodule.$smodpath.url 2>&1};
chomp $url;
if (!$url) {
print "Couldn't retrieve submodule URL for submodule $smodname\n";
exit 1;
}
if (!-e $modrefdir) {
exec_and_check("git clone --quiet --bare $url $modrefdir", "Got clone of $url failed.");
}
else {
my $back = Cwd::cwd();
chdir $modrefdir;
exec_and_check('git fetch --quiet --all', "Got fetch in $modrefdir failed.");
chdir $back;
}
$msg = qx{git submodule --quiet update --reference $modrefdir $smodpath 2>&1};
check_update_ok($?, $msg);
}
}
else {
$msg = qx{git submodule --quiet update 2>&1};
check_update_ok($?, $msg);
}

print "OK\n";


# Helper subs.

sub exec_and_check {
my ($command, $msg) = @_;
my $out = qx{$command};
if ($? >> 8 != 0) {
print "\n===SORRY=== ERROR: $msg\n";
print "The error message was: $out\n";
exit 1;
}
}

sub check_update_ok {
my ($code, $msg) = @_;
if ($code >> 8 != 0) {
if ( $msg =~
/[']([^']+)[']\s+already exists and is not an empty/ )
{
print "\n===SORRY=== ERROR: "
. "Cannot update submodule because directory exists and is not empty.\n"
. ">>> Please delete the following folder and try again:\n$1\n\n";
}
else {
print "\n===SORRY=== ERROR: "
. "Updating the submodule failed for an unknown reason. The error message was:\n"
. $msg;
}
exit 1;
}
}

6 changes: 5 additions & 1 deletion tools/lib/NQP/Config/Rakudo.pm
Expand Up @@ -673,7 +673,7 @@ sub gen_nqp {

# Append only the options we'd like to pass down to NQP's Configure.pl
for my $opt (
qw<git-depth git-reference github-user nqp-repo moar-repo
qw<git-depth github-user nqp-repo moar-repo
nqp-home relocatable ignore-errors with-moar silent-build
force-rebuild>
)
Expand All @@ -682,6 +682,10 @@ sub gen_nqp {
push @cmd, $opt_str if $opt_str;
}

push @cmd, '--git-cache-dir=' . $self->shell_quote_filename(
File::Spec->rel2abs($options->{'git-cache-dir'}))
if $options->{'git-cache-dir'};

push @cmd, "--backends=" . join( ",", $self->active_backends );

if ( defined $gen_moar ) {
Expand Down

0 comments on commit 322b095

Please sign in to comment.