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