Skip to content

Commit

Permalink
Generate Rakudo Flavor into the actual code
Browse files Browse the repository at this point in the history
Adapt tools/build/gen-cat.nqp so that it will look for the string
 #RAKUDO_FLAVOR# in the source being processed.  If found, it will
look in the environment for the RAKUDO_FLAVOR variable.  If that is
set, then it will replace the #RAKUDO_FLAVOR# target with a
"' $flavor'".  If it is not found, it will generate an empty string
(as in "''") there.

This also adds the #RAKUDO_FLAVOR# string to Compiler.nqp's version
information, so that --version will show the flavor.

This grants the wish of the Rakudo Star people to be able to mark
their version of Rakudo with an additional "Star" label, by making
sure that the environment variable RAKUDO_FLAVOR is set to "Star"
**at the moment that Rakudo is being compiled**.

This also should fix any objections with users potentially getting
confused by which version of Rakudo they are using, as the flavor
is "burnt into" the actual binary code of the executor, and thus
cannot be changed at runtime.

Additionally, this should allow the flavor to become available in
other areas, perhaps in the form of a $*RAKU attribute, burnt into
in the same manner.
  • Loading branch information
lizmat committed May 5, 2024
1 parent c885595 commit f253d68
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
26 changes: 2 additions & 24 deletions src/Perl6/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,8 @@ class Perl6::Compiler is HLL::Compiler {
method version_string(:$shorten-versions, :$no-unicode) {
my $config-version := self.config()<version>;
my $backend-version := nqp::getattr(self,HLL::Compiler,'$!backend').version_string;
my $execname := nqp::execname;
my $path-sep := nqp::gethllsym('default', 'SysConfig').path-sep;
my $install-dir := nqp::substr($execname, 0, nqp::rindex($execname, $path-sep, nqp::rindex($execname, $path-sep) - 1));
my $flavor-file := $install-dir ~ $path-sep ~ "etc" ~ $path-sep ~ "FLAVOR";
my $rakudo-core-flavor := " v";

my $raku;
my $rakudo;
my $rakudo-flavor;

if $shorten-versions {
my $index := nqp::index($config-version,"-");
Expand All @@ -173,24 +166,10 @@ class Perl6::Compiler is HLL::Compiler {
$rakudo := "Rakudo™";
}

# Support different flavors of Rakudo, i.e. Star.
# Rakudo flavor can be either set by an environment variable
# 'RAKUDO_FLAVOR' or by the special file '$RAKUDO_PREFIX/etc/FLAVOR'
if nqp::existskey(nqp::getenvhash(), 'RAKUDO_FLAVOR') {
$rakudo-flavor := " " ~ (nqp::getenvhash<RAKUDO_FLAVOR>) ~ $rakudo-core-flavor;
}
elsif nqp::stat($flavor-file, nqp::const::STAT_EXISTS) {
my $data := open($flavor-file, :r);
$rakudo-flavor := " " ~ ($data.get) ~ $rakudo-core-flavor;
close($data);
}
else {
$rakudo-flavor := $rakudo-core-flavor;
}

"Welcome to "
~ $rakudo
~ $rakudo-flavor
~ #RAKUDO_FLAVOR#
~ " v"
~ $config-version
~ ".\nImplementing the "
~ $raku
Expand Down Expand Up @@ -381,7 +360,6 @@ The following environment variables are respected:
PERL6LIB Modify the module search path (DEPRECATED)
NQP_HOME Override the path of the NQP runtime files
RAKUDO_HOME Override the path of the Rakudo runtime files
RAKUDO_FLAVOR Set derived Rakudo compiler, i.e. "Star"
); # end of usage statement
Expand Down
30 changes: 21 additions & 9 deletions tools/build/gen-cat.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ sub MAIN(*@ARGS) {
$in_cond := 1;
$in_omit := $x[0] && $x[1] eq $backend || !$x[0] && $x[1] ne $backend;
print("\n");
} elsif $_ ~~ /^ '#?endif' / {
}
elsif $_ ~~ /^ '#?endif' / {
unless $in_cond {
stderr().say(
"#?endif without matching #?if in file $file, line $line"
Expand All @@ -49,15 +50,26 @@ sub MAIN(*@ARGS) {
$in_cond := 0;
$in_omit := 0;
print("\n");
} elsif $in_omit {
}
elsif $in_omit {
print("\n");
} else {
if $backend eq 'js' && $_ ~~ /'#?js: NFG'/ {
print(subst($_, /nqp\:\:[chars|substr|iseq_s|iscclass]/,
-> $op {$op ~ 'nfg'}, :global));
} else {
print($_) unless nqp::eqat($_,"# vim:",0);
}
}
elsif nqp::index($_, '#RAKUDO_FLAVOR#') > -1 {
my str $flavor := nqp::ifnull(
nqp::atkey(nqp::getenvhash, 'RAKUDO_FLAVOR'),
""
);
$flavor := " $flavor" if $flavor;
print(
nqp::join("'$flavor'", nqp::split('#RAKUDO_FLAVOR#', $_))
);
}
elsif $backend eq 'js' && $_ ~~ /'#?js: NFG'/ {
print(subst($_, /nqp\:\:[chars|substr|iseq_s|iscclass]/,
-> $op {$op ~ 'nfg'}, :global));
}
else {
print($_) unless nqp::eqat($_,"# vim:",0);
}
$line++;
}
Expand Down

0 comments on commit f253d68

Please sign in to comment.