Commit | Line | Data |
eee9a548 |
1 | package Object::Remote::FatNode; |
2 | |
3 | use strictures 1; |
4 | use Config; |
5 | use B qw(perlstring); |
6 | |
d0a91ad2 |
7 | my @exclude_mods = qw(XSLoader.pm DynaLoader.pm); |
8 | |
c003f065 |
9 | #used by t/watchdog_fatnode |
7985ed9e |
10 | our $INHIBIT_RUN_NODE = 0; |
e5b3f03f |
11 | |
eee9a548 |
12 | sub stripspace { |
13 | my ($text) = @_; |
14 | $text =~ /^(\s+)/ && $text =~ s/^$1//mg; |
15 | $text; |
16 | } |
17 | |
18 | my %maybe_libs = map +($_ => 1), grep defined, (values %Config, '.'); |
19 | |
20 | my @extra_libs = grep not(ref($_) or $maybe_libs{$_}), @INC; |
21 | |
22 | my $extra_libs = join '', map " -I$_\n", @extra_libs; |
23 | |
24 | my $command = qq( |
25 | $^X |
26 | $extra_libs |
27 | -mObject::Remote |
28 | -mObject::Remote::Connector::STDIO |
29 | -mCPS::Future |
8c81a0e5 |
30 | -mMRO::Compat |
eee9a548 |
31 | -mClass::C3 |
8c81a0e5 |
32 | -mClass::C3::next |
33 | -mAlgorithm::C3 |
eee9a548 |
34 | -mObject::Remote::ModuleLoader |
35 | -mObject::Remote::Node |
4c8c83d7 |
36 | -mMethod::Generate::BuildAll |
37 | -mMethod::Generate::DemolishAll |
eee9a548 |
38 | -mJSON::PP |
df8e0ca6 |
39 | -e 'print join "\\n", \%INC' |
eee9a548 |
40 | ); |
41 | |
42 | $command =~ s/\n/ /g; |
43 | |
c003f065 |
44 | #warn $command; |
df8e0ca6 |
45 | chomp(my @inc = qx($command)); |
46 | |
c003f065 |
47 | my %exclude = map { $_ => 1 } @exclude_mods; |
48 | my %mod_files = @inc; |
df8e0ca6 |
49 | my %mods = reverse @inc; |
eee9a548 |
50 | |
d0a91ad2 |
51 | foreach(keys(%mods)) { |
52 | if ($exclude{ $mods{$_} }) { |
53 | delete($mods{$_}); |
54 | } |
55 | } |
56 | |
c003f065 |
57 | my @non_core_non_arch = ( $mod_files{'Devel/GlobalDestruction.pm'} ); |
58 | push @non_core_non_arch, grep +( |
59 | not ( |
6330846d |
60 | #some of the config variables can be empty which will eval as a matching regex |
c003f065 |
61 | $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/ |
62 | or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/ |
63 | or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/ |
64 | or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/ |
65 | ) |
66 | ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods; |
67 | |
68 | my @core_non_arch = grep +( |
69 | $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/ |
70 | and not($Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/ |
71 | or /\Q$Config{archname}/ or /\Q$Config{myarchname}/) |
72 | ), keys %mods; |
73 | |
74 | #print STDERR "non-core non-arch ", Dumper(\@non_core_non_arch); |
75 | #print STDERR "core non-arch ", Dumper(\@core_non_arch); |
1ef3d225 |
76 | |
42ff5efb |
77 | #TODO this is the wrong path to go down - fork() will bring |
78 | #the env vars with it and the ssh connector can handle |
79 | #forwarding the env vars |
23591f5f |
80 | my $env_pass = ''; |
81 | if (defined($ENV{OBJECT_REMOTE_LOG_LEVEL})) { |
1a7f821f |
82 | my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL}; |
c0d4da69 |
83 | $env_pass .= '$ENV{OBJECT_REMOTE_LOG_LEVEL} = "' . $level . "\";\n"; |
84 | } |
85 | if (defined($ENV{OBJECT_REMOTE_LOG_FORMAT})) { |
86 | my $format = $ENV{OBJECT_REMOTE_LOG_FORMAT}; |
87 | $env_pass .= '$ENV{OBJECT_REMOTE_LOG_FORMAT} = "' . $format . "\";\n"; |
23591f5f |
88 | } |
a0771eda |
89 | if (defined($ENV{OBJECT_REMOTE_LOG_SELECTIONS})) { |
90 | my $selections = $ENV{OBJECT_REMOTE_LOG_SELECTIONS}; |
91 | $env_pass .= '$ENV{OBJECT_REMOTE_LOG_SELECTIONS} = "' . $selections . "\";\n"; |
92 | } |
aa4a1d83 |
93 | if (defined($ENV{OBJECT_REMOTE_LOG_FORWARDING})) { |
94 | my $forwarding = $ENV{OBJECT_REMOTE_LOG_FORWARDING}; |
95 | $env_pass .= '$ENV{OBJECT_REMOTE_LOG_FORWARDING} = "' . $forwarding . "\";\n"; |
96 | } |
52a81cde |
97 | if (defined($ENV{OBJECT_REMOTE_PERL_BIN})) { |
98 | my $perl_bin = $ENV{OBJECT_REMOTE_PERL_BIN}; |
99 | $env_pass .= '$ENV{OBJECT_REMOTE_PERL_BIN} = "' . $perl_bin . "\";\n"; |
100 | } |
aa4a1d83 |
101 | |
eee9a548 |
102 | my $start = stripspace <<'END_START'; |
103 | # This chunk of stuff was generated by Object::Remote::FatNode. To find |
104 | # the original file's code, look for the end of this BEGIN block or the |
105 | # string 'FATPACK' |
106 | BEGIN { |
1ef3d225 |
107 | my (%fatpacked,%fatpacked_extra); |
eee9a548 |
108 | END_START |
d0a91ad2 |
109 | |
110 | $start .= 'my %exclude = map { $_ => 1 } qw(' . join(' ', @exclude_mods) . ");\n"; |
111 | |
eee9a548 |
112 | my $end = stripspace <<'END_END'; |
1ef3d225 |
113 | s/^ //mg for values %fatpacked, values %fatpacked_extra; |
eee9a548 |
114 | |
d0a91ad2 |
115 | sub load_from_hash { |
1ef3d225 |
116 | if (my $fat = $_[0]->{$_[1]}) { |
d0a91ad2 |
117 | if ($exclude{$_[1]}) { |
118 | warn "Will not pre-load '$_[1]'"; |
119 | return undef; |
120 | } |
121 | |
122 | #warn "handling $_[1]"; |
eee9a548 |
123 | open my $fh, '<', \$fat; |
124 | return $fh; |
125 | } |
d0a91ad2 |
126 | |
8c81a0e5 |
127 | #Uncomment this to find brokenness |
128 | #warn "Missing $_[1]"; |
d0a91ad2 |
129 | return; |
1ef3d225 |
130 | } |
131 | |
132 | unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) }; |
133 | push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) }; |
eee9a548 |
134 | |
135 | } # END OF FATPACK CODE |
136 | |
137 | use strictures 1; |
138 | use Object::Remote::Node; |
e5b3f03f |
139 | |
140 | unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) { |
141 | Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT); |
142 | } |
143 | |
eee9a548 |
144 | END_END |
145 | |
146 | my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }), |
c003f065 |
147 | @non_core_non_arch, @core_non_arch; |
eee9a548 |
148 | |
c003f065 |
149 | my %did_pack; |
1ef3d225 |
150 | sub generate_fatpack_hash { |
151 | my ($hash_name, $orig) = @_; |
152 | (my $stub = $orig) =~ s/\.pm$//; |
eee9a548 |
153 | my $name = uc join '_', split '/', $stub; |
1ef3d225 |
154 | my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg; |
c003f065 |
155 | return () if $did_pack{$hash_name}{$orig}; |
156 | $did_pack{$hash_name}{$orig} = 1; |
fb2b75a2 |
157 | $data .= "\n" unless $data =~ m/\n$/; |
158 | my $ret = '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n! |
159 | .qq!${data}${name}\n!; |
160 | # warn $ret; |
161 | return $ret; |
1ef3d225 |
162 | } |
163 | |
164 | my @segments = ( |
c003f065 |
165 | map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch), |
166 | map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch), |
1ef3d225 |
167 | ); |
eee9a548 |
168 | |
c003f065 |
169 | #print STDERR Dumper(\@segments); |
23591f5f |
170 | our $DATA = join "\n", $start, $env_pass, @segments, $end; |
eee9a548 |
171 | |
172 | 1; |