Skip to content

Commit bd9e18e

Browse files
committed
- rename post_make_install_files to zip_extra_files
- implement perl_onlyextensions config item for easy appending on new extensions to a config - use $XDG_DATA_HOME/apperl for default repo location instead SITE_CONFIG_DIR - implement apperlm --version
1 parent 1980da1 commit bd9e18e

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

lib/Perl/Dist/APPerl.pm

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Getopt::Long::Configure qw(gnu_getopt);
1515

1616
use constant {
1717
SITE_CONFIG_DIR => (($ENV{XDG_CONFIG_HOME} // ($ENV{HOME}.'/.config')).'/apperl'),
18+
SITE_REPO_DIR => (($ENV{XDG_DATA_HOME} // ($ENV{HOME}.'/.local/share')).'/apperl'),
1819
PROJECT_FILE => 'apperl-project.json',
1920
START_WD => getcwd(),
2021
PROJECT_TMP_DIR => abs_path('.apperl')
@@ -644,7 +645,7 @@ my %defconfig = (
644645
desc => 'base nobuild config',
645646
dest => 'perl-nobuild.com',
646647
MANIFEST => ['lib', 'bin'],
647-
post_make_install_files => {},
648+
zip_extra_files => {},
648649
nobuild_perl_bin => ['src/perl.com', $^X],
649650
},
650651
'v5.36.0-full-v0.1.0' => {
@@ -659,7 +660,7 @@ my %defconfig = (
659660
MANIFEST => ['lib', 'bin'],
660661
'include_Perl-Dist-APPerl' => 1,
661662
perl_repo_files => {},
662-
post_make_install_files => {},
663+
zip_extra_files => {},
663664
},
664665
'v5.36.0-full-v0.1.0-vista' => {
665666
desc => 'Full perl v5.36.0, but with non-standard cosmopolitan libc that still supports vista',
@@ -670,7 +671,8 @@ my %defconfig = (
670671
'v5.36.0-small-v0.1.0' => {
671672
desc => 'small perl v5.36.0',
672673
base => 'v5.36.0-full-v0.1.0',
673-
perl_extra_flags => ['-Doptimize=-Os', "-Donlyextensions= Cwd Fcntl File/Glob Hash/Util IO List/Util POSIX Socket attributes re ", '-de'],
674+
perl_onlyextensions => [qw(Cwd Fcntl File/Glob Hash/Util IO List/Util POSIX Socket attributes re)],
675+
perl_extra_flags => ['-Doptimize=-Os', '-de'],
674676
MANIFEST => \@smallmanifest,
675677
'include_Perl-Dist-APPerl' => 0
676678
},
@@ -773,12 +775,12 @@ sub InstallBuildDeps {
773775
my $SiteConfig = _load_json(SITE_CONFIG_FILE);
774776
# if a repo is not set, set one up by default
775777
if((!$SiteConfig || !exists $SiteConfig->{perl_repo}) && (!$perlrepo)) {
776-
$perlrepo = SITE_CONFIG_DIR."/perl5";
778+
$perlrepo = SITE_REPO_DIR."/perl5";
777779
_setup_repo($perlrepo, _load_apperl_configs()->{perl_remotes});
778780
print "apperlm install-build-deps: setup perl repo\n";
779781
}
780782
if((!$SiteConfig || !exists $SiteConfig->{cosmo_repo}) && (!$cosmorepo)) {
781-
$cosmorepo = SITE_CONFIG_DIR."/cosmopolitan";
783+
$cosmorepo = SITE_REPO_DIR."/cosmopolitan";
782784
_setup_repo( $cosmorepo, _load_apperl_configs()->{cosmo_remotes});
783785
print "apperlm install-build-deps: setup cosmo repo\n";
784786
}
@@ -908,7 +910,9 @@ sub Configure {
908910
$ENV{COSMO_REPO} = $SiteConfig->{cosmo_repo};
909911
$ENV{COSMO_MODE} = $itemconfig->{cosmo_mode};
910912
$ENV{COSMO_APE_LOADER} = $itemconfig->{cosmo_ape_loader};
911-
_command_or_die('sh', 'Configure', @{$itemconfig->{perl_flags}}, @{$itemconfig->{perl_extra_flags}}, @_);
913+
my @onlyextensions = ();
914+
push @onlyextensions, ("-Donlyextensions= ".join(' ', sort @{$itemconfig->{perl_onlyextensions}}).' ') if(exists $itemconfig->{perl_onlyextensions});
915+
_command_or_die('sh', 'Configure', @{$itemconfig->{perl_flags}}, @onlyextensions, @{$itemconfig->{perl_extra_flags}}, @_);
912916
print "$0: Configure successful, time for apperlm build\n";
913917
}
914918

@@ -974,12 +978,12 @@ sub Build {
974978
my $APPPATH = "$TEMPDIR/$APPNAME";
975979
_command_or_die('cp', $PERL_APE, $APPPATH);
976980
_command_or_die('chmod', 'u+w', $APPPATH);
977-
if((! exists $UserProjectConfig->{nobuild_perl_bin}) || scalar(keys %{$itemconfig->{post_make_install_files}})) {
981+
if((! exists $UserProjectConfig->{nobuild_perl_bin}) || scalar(keys %{$itemconfig->{zip_extra_files}})) {
978982
print "cd $ZIP_ROOT\n";
979983
chdir($ZIP_ROOT) or die "failed to enter ziproot";
980-
foreach my $destkey (keys %{$itemconfig->{post_make_install_files}}) {
984+
foreach my $destkey (keys %{$itemconfig->{zip_extra_files}}) {
981985
my $dest = _fix_bases($destkey, $PERL_VERSION, $PERL_ARCHNAME);
982-
foreach my $file (@{$itemconfig->{post_make_install_files}{$destkey}}) {
986+
foreach my $file (@{$itemconfig->{zip_extra_files}{$destkey}}) {
983987
_copy_recursive($file, $dest);
984988
}
985989
}
@@ -1015,9 +1019,22 @@ END_USAGE
10151019
my $command = shift(@_) if(@_);
10161020
$command or die($generic_usage);
10171021
if($command eq 'list') {
1022+
my $usage = <<'END_USAGE';
1023+
apperlm list
1024+
List available APPerl configs; checks apperl-project.json and built-in
1025+
to Perl::Dist::APPerl configs. If a current config is set it is denoted
1026+
with a '*'.
1027+
END_USAGE
1028+
die($usage) if(@_);
10181029
Perl::Dist::APPerl::Status();
10191030
}
10201031
elsif($command eq 'build') {
1032+
my $usage = <<'END_USAGE';
1033+
apperlm build
1034+
Build APPerl. If the current config is a from-scratch build, you must
1035+
run `apperlm configure` first.
1036+
END_USAGE
1037+
die($usage) if(@_);
10211038
Perl::Dist::APPerl::Build();
10221039
}
10231040
elsif($command eq 'configure') {
@@ -1026,6 +1043,15 @@ END_USAGE
10261043
elsif($command =~ /^(\-)*(halp|help|h)$/i) {
10271044
print $generic_usage;
10281045
}
1046+
elsif($command =~ /^(\-)*(version|v)$/i) {
1047+
my $message = <<"END_USAGE";
1048+
apperlm $VERSION
1049+
Copyright (C) 2022 Gavin Arthur Hayes
1050+
This is free software; you can redistribute it and/or modify it under
1051+
the same terms as the Perl 5 programming language system itself.
1052+
END_USAGE
1053+
print $message;
1054+
}
10291055
elsif($command eq 'checkout') {
10301056
scalar(@_) == 1 or die('bad args');
10311057
my $cfgname = $_[0];
@@ -1186,8 +1212,8 @@ sub _load_apperl_config {
11861212
}
11871213

11881214
# switch these from relative paths to abs paths
1189-
foreach my $destdir (keys %{$itemconfig{post_make_install_files}}) {
1190-
foreach my $path (@{$itemconfig{post_make_install_files}{$destdir}}) {
1215+
foreach my $destdir (keys %{$itemconfig{zip_extra_files}}) {
1216+
foreach my $path (@{$itemconfig{zip_extra_files}{$destdir}}) {
11911217
$path = abs_path($path);
11921218
$path or die;
11931219
print $path;
@@ -1199,10 +1225,10 @@ sub _load_apperl_config {
11991225
if(exists $itemconfig{'include_Perl-Dist-APPerl'} && $itemconfig{'include_Perl-Dist-APPerl'}) {
12001226
my $thispath = abs_path(__FILE__);
12011227
defined($thispath) or die(__FILE__.'issues?');
1202-
push @{$itemconfig{post_make_install_files}{"__perllib__/Perl/Dist"}}, $thispath;
1228+
push @{$itemconfig{zip_extra_files}{"__perllib__/Perl/Dist"}}, $thispath;
12031229
my @additionalfiles = map { "$FindBin::Bin/$_" } ('apperlm');
12041230
-e $_ or die($!) foreach @additionalfiles;
1205-
push @{$itemconfig{post_make_install_files}{bin}}, @additionalfiles;
1231+
push @{$itemconfig{zip_extra_files}{bin}}, @additionalfiles;
12061232
}
12071233

12081234
# verify apperl config sanity
@@ -1492,7 +1518,7 @@ one you copied into src. Let's create a script.
14921518
To add it open apperl-project.json and add the following to
14931519
my_nobuild_config:
14941520
1495-
"post_make_install_files" : { "bin" : ["src/hello"] }
1521+
"zip_extra_files" : { "bin" : ["src/hello"] }
14961522
14971523
Rebuild and try loading the newly added script
14981524
@@ -1512,7 +1538,7 @@ magic prefix __perllib__ can be used in the destination. Note, you may
15121538
have to add items to the MANIFEST key if the MANIFEST isn't set
15131539
permissively already.
15141540
1515-
"post_make_install_files" : { "__perllib__/Your" : ["Module.pm"] }
1541+
"zip_extra_files" : { "__perllib__/Your" : ["Module.pm"] }
15161542
15171543
=head2 BUILDING AN APPLICATION FROM SCRATCH
15181544
@@ -1568,7 +1594,7 @@ config.
15681594
"MyCExtension"
15691595
]},
15701596
"+MANIFEST" : ["__perlarchlib__/MyCExtension.pm"],
1571-
"perl_extra_flags" : ["-Doptimize=-Os", "-Donlyextensions= Cwd Fcntl File/Glob Hash/Util IO List/Util POSIX Socket attributes re MyCExtension ", "-de"]
1597+
"+perl_onlyextensions" : ["MyCExtension"]
15721598
15731599
Build it and try it out. apperlm checkout is needed as Perl must be
15741600
rebuilt from scratch as the Configure flags changed and new files were
@@ -1594,7 +1620,7 @@ the script so that it will launch the script.
15941620
15951621
"dest" : "helloext.com",
15961622
"+MANIFEST" : ["__perlarchlib__/MyCExtension.pm", "bin/helloext"],
1597-
"post_make_install_files" : { "bin" : ["helloext"] }
1623+
"zip_extra_files" : { "bin" : ["helloext"] }
15981624
15991625
Build and test it.
16001626

0 commit comments

Comments
 (0)