Skip to content

Commit

Permalink
Cope with changes to repo paths between compile and run time
Browse files Browse the repository at this point in the history
When installing a module via a Staging repo, at compile time, we will find
the resources in the staging repo's path while later after installation we'll
find it in the target repo's path. Thus we need to defer creating the path
as long as possible. We do this by returning an object that does Callable
(which NativeCall will run) but also stringifies to the path for non-NativeCall
users and backwards compatibility.
  • Loading branch information
niner committed Apr 17, 2017
1 parent 5b862a3 commit d4d6a99
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/core/Distribution.pm
Expand Up @@ -154,31 +154,58 @@ role CompUnit::Repository { ... }
class Distribution::Resources does Associative {
has Str $.dist-id;
has Str $.repo;
has Str $.repo-name;

proto method BUILD(|) { * }

multi method BUILD(:$!dist-id, CompUnit::Repository :$repo --> Nil) {
$!repo = $repo.path-spec;
unless $repo.can('name') and $!repo-name = $repo.name and $!repo-name ne '' {
$!repo = $repo.path-spec;
$!repo-name = Str;
}
}

multi method BUILD(:$!dist-id, Str :$!repo --> Nil) { }
multi method BUILD(:$!dist-id, :$repo, Str :$!repo-name --> Nil) { }
multi method BUILD(:$!dist-id, Str :$!repo, :$repo-name --> Nil) { }

method from-precomp() {
if %*ENV<RAKUDO_PRECOMP_DIST> -> \dist {
my %data := Rakudo::Internals::JSON.from-json: dist;
self.new(:repo(%data<repo>), :dist-id(%data<dist-id>))
self.new(:repo(%data<repo>), :repo-name(%data<repo-name>), :dist-id(%data<dist-id>))
}
else {
Nil
}
}

method AT-KEY($key) {
CompUnit::RepositoryRegistry.repository-for-spec($.repo).resource($.dist-id, "resources/$key")
my class :: does Callable {
has $.repo;
has $.repo-name;
has $.dist-id;
has $.key;
method IO() {
my $repo := $!repo-name
?? CompUnit::RepositoryRegistry.repository-for-name($!repo-name)
!! CompUnit::RepositoryRegistry.repository-for-spec($!repo);
$repo.resource($!dist-id, "resources/$!key")
}
method CALL-ME() {
self.IO.Str
}
method Str() {
return self.IO.Str
}
}.new(
:$.repo,
:$.repo-name,
:$.dist-id,
:$key,
)
}

method Str() {
Rakudo::Internals::JSON.to-json: {repo => $.repo.Str, dist-id => $.dist-id};
Rakudo::Internals::JSON.to-json: {:$.repo, :$.repo-name, :$.dist-id}
}
}

Expand Down

0 comments on commit d4d6a99

Please sign in to comment.