@@ -830,17 +830,6 @@ sub _install_cosmocc {
830
830
_write_json(SITE_CONFIG_FILE, $SiteConfig );
831
831
}
832
832
833
- # sub _load_valid_site_config {
834
- # my ($is_cosmo3) = @_;
835
- # my $SiteConfig = _load_json(SITE_CONFIG_FILE);
836
- # $SiteConfig || defined($is_cosmo3) or die "Failed to load SiteConfig";
837
- # $SiteConfig //= {};
838
- # defined $is_cosmo3 or return $SiteConfig;
839
- # if ($is_cosmo3) {
840
- #
841
- # }
842
- # }
843
-
844
833
sub InstallBuildDeps {
845
834
my ($perlrepo , $cosmorepo ) = @_ ;
846
835
my $SiteConfig = _load_json(SITE_CONFIG_FILE);
@@ -957,17 +946,11 @@ sub Checkout {
957
946
my $itemconfig = _load_apperl_config(_load_apperl_configs()-> {apperl_configs }, $cfgname );
958
947
print Dumper($itemconfig );
959
948
if (! exists $itemconfig -> {nobuild_perl_bin }) {
960
- my $SiteConfig = _load_json(SITE_CONFIG_FILE );
949
+ my $SiteConfig = _load_valid_site_config( $itemconfig -> { cosmo3 } );
961
950
if (! $itemconfig -> {cosmo3 }) {
962
- $SiteConfig or die " cannot set without build deps (run apperlm install-build-deps)" ;
963
- -d $SiteConfig -> {cosmo_repo } or die $SiteConfig -> {cosmo_repo } .' is not directory' ;
964
951
print " cd " .$SiteConfig -> {cosmo_repo }." \n " ;
965
952
chdir ($SiteConfig -> {cosmo_repo }) or die " Failed to enter cosmo repo" ;
966
953
_command_or_die(' git' , ' checkout' , $itemconfig -> {cosmo_id });
967
- } else {
968
- $SiteConfig //= {};
969
- exists $SiteConfig -> {cosmocc } or _install_cosmocc($SiteConfig );
970
- -d $SiteConfig -> {cosmocc } or die $SiteConfig -> {cosmocc } . ' is not a directory' ;
971
954
}
972
955
$UserProjectConfig -> {configs }{$cfgname }{perl_build_dir } //= $SiteConfig -> {perl_repo } if !$itemconfig -> {perl_url };
973
956
$UserProjectConfig -> {configs }{$cfgname }{perl_build_dir } //= " $UserProjectConfig ->{apperl_output}/$cfgname /tmp/perl5" ;
@@ -1039,17 +1022,13 @@ sub Checkout {
1039
1022
}
1040
1023
1041
1024
sub Configure {
1042
- my $Configs = _load_apperl_configs();
1043
- my ($UserProjectConfig , $CurAPPerlName ) = _load_valid_user_project_config_with_default($Configs ) or die " cannot Configure without valid UserProjectConfig" ;
1025
+ my ($UserProjectConfig , $CurAPPerlName , $itemconfig ) = _load_valid_configs() or die " cannot Configure without valid UserProjectConfig" ;
1044
1026
! exists $UserProjectConfig -> {nobuild_perl_bin } or die " nobuild perl cannot be configured" ;
1045
1027
my $perl_build_dir = $UserProjectConfig -> {configs }{$CurAPPerlName }{perl_build_dir };
1046
1028
$perl_build_dir && -d $perl_build_dir or die " $perl_build_dir is not a directory" ;
1047
- my $itemconfig = _load_apperl_config($Configs -> {apperl_configs }, $CurAPPerlName );
1048
1029
_install_perl_src_files($itemconfig , $perl_build_dir );
1049
- my $SiteConfig = _load_json(SITE_CONFIG_FILE );
1030
+ my $SiteConfig = _load_valid_site_config( $itemconfig -> { cosmo3 } );
1050
1031
if (! $itemconfig -> {cosmo3 }) {
1051
- $SiteConfig or die " cannot Configure without build deps (run apperlm install-build-deps)" ;
1052
- -d $SiteConfig -> {cosmo_repo } or die $SiteConfig -> {cosmo_repo } .' is not directory' ;
1053
1032
# build toolchain
1054
1033
_command_or_die(' make' , ' -C' , $SiteConfig -> {cosmo_repo }, ' -j' , ' toolchain' , ' MODE=' , ' ARCH=x86_64' );
1055
1034
# build cosmo
@@ -1064,9 +1043,6 @@ sub Configure {
1064
1043
$ENV {COSMO_APE_LOADER } = $itemconfig -> {cosmo_ape_loader };
1065
1044
$ENV {COSMO_REPO } = $SiteConfig -> {cosmo_repo };
1066
1045
} else {
1067
- $SiteConfig //= {};
1068
- exists $SiteConfig -> {cosmocc } or _install_cosmocc($SiteConfig );
1069
- -d $SiteConfig -> {cosmocc } or die $SiteConfig -> {cosmocc } . ' is not a directory' ;
1070
1046
$ENV {COSMOCC } = $SiteConfig -> {cosmocc };
1071
1047
}
1072
1048
@@ -1104,21 +1080,14 @@ sub _find_zip {
1104
1080
1105
1081
sub Build {
1106
1082
my ($zippath ) = @_ ;
1107
- my $Configs = _load_apperl_configs();
1108
- my ($UserProjectConfig , $CurAPPerlName ) = _load_valid_user_project_config_with_default($Configs ) or die " cannot Build without valid UserProjectConfig" ;
1109
- my $itemconfig = _load_apperl_config($Configs -> {apperl_configs }, $CurAPPerlName );
1083
+ my ($UserProjectConfig , $CurAPPerlName , $itemconfig ) = _load_valid_configs() or die " cannot Build without valid UserProjectConfig" ;
1110
1084
my $startdir = abs_path(' ./' );
1111
1085
1112
1086
my $PERL_APE ;
1113
1087
my @perl_config_cmd ;
1114
1088
# build cosmo perl if this isn't a nobuild config
1115
1089
if (! exists $UserProjectConfig -> {nobuild_perl_bin }){
1116
- my $SiteConfig = _load_json(SITE_CONFIG_FILE) or die " cannot build without build deps (run apperlm install-build-deps)" ;
1117
- if (! $itemconfig -> {cosmo3 }) {
1118
- -d $SiteConfig -> {cosmo_repo } or die $SiteConfig -> {cosmo_repo } .' is not directory' ;
1119
- } else {
1120
- -d $SiteConfig -> {cosmocc } or die $SiteConfig -> {cosmocc } .' is not directory' ;
1121
- }
1090
+ my $SiteConfig = _load_valid_site_config($itemconfig -> {cosmo3 });
1122
1091
my $perl_build_dir = $UserProjectConfig -> {configs }{$CurAPPerlName }{perl_build_dir };
1123
1092
$perl_build_dir && -d $perl_build_dir or die " $perl_build_dir is not a directory" ;
1124
1093
_install_perl_src_files($itemconfig , $perl_build_dir );
@@ -1654,22 +1623,37 @@ sub _load_valid_user_project_config {
1654
1623
if (exists $UserProjectConfig -> {current_apperl }) {
1655
1624
my $CurAPPerlName = $UserProjectConfig -> {current_apperl };
1656
1625
exists $Configs -> {apperl_configs }{$CurAPPerlName } or die (" non-existent apperl config $CurAPPerlName in user project config" );
1657
- return ($UserProjectConfig , $CurAPPerlName );
1626
+ my $itemconfig = _load_apperl_config($Configs -> {apperl_configs }, $CurAPPerlName );
1627
+ return ($UserProjectConfig , $CurAPPerlName , $itemconfig );
1658
1628
}
1659
1629
}
1660
1630
return ();
1661
1631
}
1662
1632
1663
- sub _load_valid_user_project_config_with_default {
1664
- my ($Configs ) = @_ ;
1665
- my ($UserProjectConfig , $CurAPPerlName ) = _load_valid_user_project_config($Configs );
1666
- if ($UserProjectConfig ) {
1667
- return ($UserProjectConfig , $CurAPPerlName );
1668
- } elsif (!exists $Configs -> {defaultconfig }) {
1669
- return ();
1633
+ sub _load_valid_configs {
1634
+ my $apperlconfigs = _load_apperl_configs();
1635
+ my @configs = _load_valid_user_project_config($apperlconfigs );
1636
+ return @configs if (@configs );
1637
+ return () if (!exists $apperlconfigs -> {defaultconfig });
1638
+ Checkout($apperlconfigs -> {defaultconfig });
1639
+ return _load_valid_user_project_config($apperlconfigs );
1640
+ }
1641
+
1642
+ sub _load_valid_site_config {
1643
+ my ($is_cosmo3 ) = @_ ;
1644
+ my $SiteConfig = _load_json(SITE_CONFIG_FILE);
1645
+ if ($is_cosmo3 ) {
1646
+ $SiteConfig //= {};
1647
+ if (! exists $SiteConfig -> {cosmocc }) {
1648
+ print " cosmocc not found in " . SITE_CONFIG_FILE . " attempting to install cosmocc\n " ;
1649
+ _install_cosmocc($SiteConfig );
1650
+ }
1651
+ -d $SiteConfig -> {cosmocc } or die $SiteConfig -> {cosmocc } . ' is not a directory, please edit or remove the entry in ' . SITE_CONFIG_FILE;
1652
+ } else {
1653
+ $SiteConfig or die " Failed to load SiteConfig, run apperlm install-build-deps" ;
1654
+ -d $SiteConfig -> {cosmo_repo } or die $SiteConfig -> {cosmo_repo } ." is not directory, reconfigure with `apperlm install-build-deps`. Note to redownload if its already there edit " .SITE_CONFIG_FILE;
1670
1655
}
1671
- Checkout($Configs -> {defaultconfig });
1672
- return _load_valid_user_project_config($Configs );
1656
+ return $SiteConfig ;
1673
1657
}
1674
1658
1675
1659
sub _write_user_project_config {
0 commit comments