Skip to content

Commit

Permalink
Tweak legacy builder logic
Browse files Browse the repository at this point in the history
This works with (and without) the candidates PRs in rakudo,
and without temporarily rewriting a meta file (to write in
Build.pm to provides). Not sure why this has to be done in
such a specific way, but it suffices to say that "it just
needs to be this way for now", where "for now" is such a time
or soluton that works for installing both Inline::Perl5 and
Linenoise.
  • Loading branch information
ugexe committed Nov 2, 2017
1 parent fb9a8bd commit 7d5f56d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 50 deletions.
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"perl" : "6",
"name" : "zef",
"version" : "0.1.31",
"version" : "0.1.32",
"auth" : "github:ugexe",
"description" : "It's like [cpanm] wearing high heels with a tracksuit",
"license" : "Artistic-2.0",
Expand Down
62 changes: 13 additions & 49 deletions lib/Zef/Service/Shell/Build.pm6
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use Zef;
use Zef::Utils::FileSystem;

class Zef::Service::Shell::Build does Builder does Messenger {
method build-matcher($path) { $path.IO.child("Build.pm").e }
Expand All @@ -11,57 +10,22 @@ class Zef::Service::Shell::Build does Builder does Messenger {
# all the existing distributions using Build.pm
method build($path, :@includes) {
die "path does not exist: {$path}" unless $path.IO.e;
my $build-file = list-paths($path, :!r, :f, :!d).first({.basename eq 'Build.pm'});

my $json-ext = $path.IO.child('META6.json').e;
my Str $comp-version = ~$*PERL.compiler.version;
my $meta-name-workaround = $comp-version.substr(5..6) <= 5
&& $comp-version.substr(0..3) <= 2016
&& $json-ext;
# make sure to use -Ilib instead of -I. or else Linenoise's Build.pm will trigger a strange precomp error
my $build-file = $path.IO.child("Build.pm").absolute;
my $cmd = "require '$build-file'; ::('Build').new.build('$path.IO.absolute()') ?? exit(0) !! exit(1);";
my @exec = |($*EXECUTABLE, '-Ilib', |@includes.grep(*.defined).map({ "-I{$_}" }), '-e', "$cmd");

my $orig-result = legacy-build($path, :@includes, :$.stderr, :$.stdout);
return $orig-result if ?$orig-result;
$.stdout.emit("Command: {@exec.join(' ')}");

# Workaround rakudo CUR::FS bug when distribution has a
# Build.pm file, is using META6.json (not META.info), and
# the rakudo version is < 2016.05
# Retries try-legacy-hook after adding 'Build' => 'Build.pm' to provides
if $meta-name-workaround {
my $meta6-path = $path.IO.child('META6.json');
my $meta6-bak = $meta6-path.absolute ~ '.bak';
my $meta6-contents = $meta6-path.IO.slurp;
try move $meta6-path, $meta6-bak;
my %meta6 = from-json($meta6-contents);
%meta6<provides><Build> = 'Build.pm';
"{$meta6-path}".IO.spurt( to-json(%meta6) );
my $result = legacy-build($path, :@includes, :$.stderr, :$.stdout);
try unlink $meta6-path;
try move $meta6-bak, $meta6-path;
$result;
my $ENV := %*ENV;
my $passed;
react {
my $proc = zrun-async(@exec);
whenever $proc.stdout.lines { $.stdout.emit($_) }
whenever $proc.stderr.lines { $.stderr.emit($_) }
whenever $proc.start(:$ENV, :cwd($path)) { $passed = $_.so }
}
return $passed;
}
}

my sub legacy-build($path, :@includes, :$stderr, :$stdout) {
my $DEBUG = ?%*ENV<ZEF_BUILDPM_DEBUG>;

# Rakudo bug related to using path instead of module name
# my $cmd = "require <{$builder-path.basename}>; ::('Build').new.build('{$path.IO.absolute}'); exit(0);";
my $cmd = "::('Build').new.build('{$path.IO.absolute}'); exit(0);";

# see: https://github.com/ugexe/zef/issues/93
# my @exec = |($*EXECUTABLE, '-Ilib', '-I.', |@cl-includes, '-e', "$cmd");
my @exec = |($*EXECUTABLE, '-Ilib', '-I.', '-MBuild', |@includes.grep(*.defined).map({ "-I{$_}" }), '-e', "$cmd");

$stdout.emit("Command: {@exec.join(' ')}") if $DEBUG;

my $ENV := %*ENV;
my $passed;
react {
my $proc = zrun-async(@exec);
whenever $proc.stdout.lines { $stdout.emit($_) }
whenever $proc.stderr.lines { $stderr.emit($_) }
whenever $proc.start(:$ENV, :cwd($path)) { $passed = $_.so }
}
return $passed;
}

0 comments on commit 7d5f56d

Please sign in to comment.