Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use @*INC for the order of CompUnitRepos
Before we use a priority to do that, but @*INC is needed anyway. This also
moves the setup code from core_epilog to Inc.pm.
  • Loading branch information
FROGGS committed May 28, 2014
1 parent ca7121f commit dfca3e9
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 87 deletions.
14 changes: 4 additions & 10 deletions src/core/CompUnitRepo.pm
@@ -1,11 +1,10 @@
class CompUnitRepo {
my Mu $p6ml := nqp::gethllsym('perl6', 'ModuleLoader');
my %repos;

method files($file, :$name, :$auth, :$ver) {
for %repos.sort -> $prio {
for @*INC -> $group {
my @candi;
for @($prio.value) {
for $group.list {
@candi := (@candi, .files($file, :$name, :$auth, :$ver)).flat
}
@candi.sort: { ($^b<ver> // Version.new('0')) cmp ($^a<ver> // Version.new('0')) };
Expand All @@ -14,21 +13,16 @@ class CompUnitRepo {
}

method candidates($name, :$file, :$auth, :$ver) {
for %repos.sort.reverse -> $prio {
for @*INC -> $group {
my @candi;
for @($prio.value) {
for $group.list {
@candi := (@candi, .candidates($name, :$file, :$auth, :$ver)).flat
}
@candi.sort: { ($^b<ver> // Version.new('0')) cmp ($^a<ver> // Version.new('0')) };
return @candi if +@candi
}
}

method add_repo($repo, :$name, :$prio = 0) {
%repos{$prio}.push: $repo;
%*CUSTOM_LIB{$name} := $repo if $name
}

method p6ml { $p6ml }

method load_module($module_name, %opts, *@GLOBALish is rw, :$line, :$file) {
Expand Down
96 changes: 73 additions & 23 deletions src/core/Inc.pm
@@ -1,19 +1,21 @@
{
my @INC;
my %CUSTOM_LIB;

#?if jvm
my $pathsep := $*VM.properties<path.separator>;
#?endif
#?if !jvm
my $pathsep := $*VM.config<osname> eq 'MSWin32' ?? ';' !! ':';
#?endif
@INC.push(%*ENV<RAKUDOLIB>.split($pathsep)) if %*ENV<RAKUDOLIB>;
@INC.push(%*ENV<PERL6LIB>.split($pathsep)) if %*ENV<PERL6LIB>;
@INC.push(CompUnitRepo::Local::File.new(%*ENV<RAKUDOLIB>.split($pathsep))) if %*ENV<RAKUDOLIB>;
@INC.push(CompUnitRepo::Local::File.new(%*ENV<PERL6LIB>.split($pathsep))) if %*ENV<PERL6LIB>;

#?if jvm
for nqp::jvmclasspaths() -> $path {
@INC.push($path) if nqp::stat($path, nqp::const::STAT_ISDIR);
@INC.push(CompUnitRepo::Local::File.new($path)) if nqp::stat($path, nqp::const::STAT_ISDIR);
}
#?endif
#?endif

my $prefix :=
#?if jvm
Expand All @@ -27,34 +29,82 @@
#?endif
~ '/languages/perl6';

# XXX Various issues with this stuff on JVM
my Mu $compiler := nqp::getcurhllsym('$COMPILER_CONFIG'); # TEMPORARY
my %CUSTOM_LIB;
try {
my $home := %*ENV<HOME> // %*ENV<HOMEDRIVE> ~ %*ENV<HOMEPATH>;
my $ver := nqp::p6box_s(nqp::atkey($compiler, 'version'));
%CUSTOM_LIB<home> = "$home/.perl6/$ver";
@INC.push(%CUSTOM_LIB<home> ~ '/lib');
if "$prefix/share/libraries.json".IO.e {
my $config = "$prefix/share/libraries.json".IO.e ?? from-json( slurp "$prefix/share/libraries.json" ) !! [];

my @all_paths;
sub make-cur($class, *@paths) {
@all_paths.push: @paths;
if $class eq 'CompUnitRepo::Local::File' {
CompUnitRepo::Local::File.new(|@paths);
}
elsif $class eq 'CompUnitRepo::Local::Installation' {
CompUnitRepo::Local::Installation.new(|@paths);
}
else {
my $name = 'lib/' ~ $class.split('::').join('/') ~ '.pm';
for @all_paths -> $path {
if "$path/$name".IO.e {
require "$path/$name";
return ::($class).new(|@paths);
}
}
}
}

for $config.list -> @group {
my @cur_group;
for @group>>.kv -> $class, $props {
for $props.list -> $prop {
if $prop ~~ Associative {
my $cur = make-cur($class, $prop.value.flat);
@cur_group.push: $cur;
%CUSTOM_LIB{$prop.key} = $cur;
}
else {
@cur_group.push: make-cur($class, $prop.flat)
}
}
}
@INC.push: +@cur_group > 1 ?? [@cur_group] !! @cur_group
}
}
# There is no config file, so pick sane defaults.
else {
# XXX Various issues with this stuff on JVM
my Mu $compiler := nqp::getcurhllsym('$COMPILER_CONFIG'); # TEMPORARY
my @cur_inst;
try {
my $home := %*ENV<HOME> // %*ENV<HOMEDRIVE> ~ %*ENV<HOMEPATH>;
my $ver := nqp::p6box_s(nqp::atkey($compiler, 'version'));
@INC.push(CompUnitRepo::Local::File.new("$home/.perl6/$ver/lib"));
@cur_inst.push(%CUSTOM_LIB<home> = CompUnitRepo::Local::Installation.new("$home/.perl6/$ver"));
}
@INC.push(CompUnitRepo::Local::File.new("$prefix/lib"));
@INC.push(CompUnitRepo::Local::File.new("$prefix/vendor/lib"));
@INC.push(CompUnitRepo::Local::File.new("$prefix/site/lib"));
@cur_inst.push(%CUSTOM_LIB<perl> = CompUnitRepo::Local::Installation.new($prefix));
@cur_inst.push(%CUSTOM_LIB<vendor> = CompUnitRepo::Local::Installation.new("$prefix/vendor"));
@cur_inst.push(%CUSTOM_LIB<site> = CompUnitRepo::Local::Installation.new("$prefix/site"));
@INC.push([@cur_inst]);
}
%CUSTOM_LIB<perl> = $prefix;
%CUSTOM_LIB<vendor> = $prefix ~ '/vendor';
%CUSTOM_LIB<site> = $prefix ~ '/site';
@INC.push(%CUSTOM_LIB<site> ~ '/lib');
@INC.push(%CUSTOM_LIB<vendor> ~ '/lib');
@INC.push(%CUSTOM_LIB<perl> ~ '/lib');
PROCESS::<%CUSTOM_LIB> := %CUSTOM_LIB;

# TODO Allow to pass Repo class to -I as well as the path.
my $I := nqp::atkey(nqp::atkey(%*COMPILING, '%?OPTIONS'), 'I');
if nqp::defined($I) {
if nqp::islist($I) {
my Mu $iter := nqp::iterator($I);
@INC.unshift: nqp::p6box_s(nqp::shift($iter)) while $iter;
@INC.unshift: CompUnitRepo::Local::File.new(nqp::p6box_s(nqp::shift($iter))) while $iter;
}
else {
@INC.unshift: nqp::p6box_s($I);
@INC.unshift: CompUnitRepo::Local::File.new(nqp::p6box_s($I));
}
}
PROCESS::<@INC> := @INC;

PROCESS::<@INC> := @INC;
PROCESS::<%CUSTOM_LIB> := %CUSTOM_LIB;

nqp::bindhllsym('perl6', 'ModuleLoader', CompUnitRepo);
}

# vim: ft=perl6 expandtab sw=4
54 changes: 0 additions & 54 deletions src/core/core_epilogue.pm
Expand Up @@ -14,60 +14,6 @@ BEGIN {
Perl6::Metamodel::GrammarHOW.HOW.compose(Perl6::Metamodel::GrammarHOW);
}

#?if jvm
my $prefix = nqp::atkey(nqp::backendconfig(), 'runtime.prefix');
#?endif
#?if !jvm
my $prefix = $*VM.config<prefix>;
#?endif
if "$prefix/share/libraries.cfg".IO.e {
my @lines = slurp("$prefix/share/libraries.cfg").lines;
my %repos;
for nqp::atkey(nqp::atkey(%*COMPILING, '%?OPTIONS'), 'I'), @lines -> $repo {
next if !$repo || $repo ~~ /^ '#'/;
my %options;
if $repo ~~ / $<class>=[ <.ident>+ % '::' ] [ ':' $<n>=\w+ <[<([]> $<v>=<[\w-]>+ <[>)\]]> { %options{$<n>} = $<v> } ]* '=' $<path>=.+ / {
my $name = %options<name> // '';
my $prio = %options<prio> // 0;
%repos{~$<class>}{$name}{$prio} //= [];
my $env_sep = $*DISTRO.is-win ?? ';' !! ':';
my @path = $<path>.split($env_sep);
for @path {
%repos{~$<class>}{$name}{$prio}.push(.IO.path.is-relative ?? "$prefix/share/$_" !! .Str);
}
}
}
my @custom_libs = %*CUSTOM_LIB.values;
for %repos.kv -> $classname, $libnames {
for $libnames.kv -> $name, $prios {
for $prios.kv -> $prio, $args {
if $classname eq 'CompUnitRepo::Local::File' {
CompUnitRepo.add_repo( CompUnitRepo::Local::File.new(|@$args), :$name, :$prio );
}
elsif $classname eq 'CompUnitRepo::Local::Installation' {
CompUnitRepo.add_repo( CompUnitRepo::Local::Installation.new(|@$args), :$name, :$prio );
}
else {
my $name = 'lib/' ~ $classname.split('::').join('/') ~ '.pm';
for @custom_libs -> $path {
if "$path/$name".IO.e {
require "$path/$name";
CompUnitRepo.add_repo( ::($classname).new(|@$args), :$name, :$prio );
}
}
}
}
}
}
}
else {
"$prefix/share/libraries.cfg".IO.spurt:
join( "\n", "CompUnitRepo::Local::File:prio<1>=" ~ @*INC.join(':'),
%*CUSTOM_LIB.kv.map( -> $k, $v { "CompUnitRepo::Local::Installation:name<$k>=$v" } ))
}

nqp::bindhllsym('perl6', 'ModuleLoader', CompUnitRepo);

{YOU_ARE_HERE}

# vim: ft=perl6 expandtab sw=4

0 comments on commit dfca3e9

Please sign in to comment.