6 # =====================================================================
14 sub perforceGetOpenFiles
17 open(P4
, "p4 -ztag opened -c default |");
22 push (@files, $_) if (s/^\.\.\. depotFile //);
32 # find out what files are open
33 my @files = perforceGetOpenFiles
();
35 my $tmpfile = "submit.tmp";
37 # submit all the open files
38 open(TMP
, ">" . $tmpfile);
40 print TMP
"Change:\tnew\n";
41 print TMP
"\nDescription:\n";
45 print TMP
"\t", $_, "\n";
48 print TMP
"\nFiles:\n";
51 print TMP
"\t", $_, "\n";
56 my $result = system("p4 submit -i < $tmpfile");
57 fatal
"p4 submit failed" if ($result != 0);
63 # find out where a perforce file resides on the local machine
66 open(P4
, "p4 where $_[0] |");
86 my $path = shift(@paths);
87 opendir(DIR
, $path) || die "could not open dir $path";
88 while ($_ = readdir(DIR
))
90 next if ($_ eq "." || $_ eq "..");
92 my $new = $path . "/" . $_;
108 # =====================================================================
110 die "uasge: perl recompileAllScripts.pl branch\n" if (@ARGV != 1);
113 my $depotScriptBaseDir = "//depot/swg/$branch/dsrc/sku.0/sys.server/compiled/game/script";
114 my $localScriptBaseDir = perforceWhere
($depotScriptBaseDir);
115 my $depotClassBaseDir = "//depot/swg/$branch/data/sku.0/sys.server/compiled/game/script";
116 my $localClassBaseDir = perforceWhere
($depotClassBaseDir);
117 my $depotJavaSourceDir = "//depot/swg/$branch/dsrc/sku.0/sys.server/compiled/game";
118 my $localJavaSourceDir = perforceWhere
($depotJavaSourceDir);
119 my $depotJavaDestinationDir = "//depot/swg/$branch/data/sku.0/sys.server/compiled/game";
120 my $localJavaDestinationDir = perforceWhere
($depotJavaDestinationDir);
121 my $pythonPreprocessor = perforceWhere
("//depot/swg/$branch/exe/shared/script_prep.py");
123 my $perforceEditClassFiles = 1;
124 my $removeClassFiles = 1;
125 my $removeJavaFilesBefore = 1;
126 my $removeJavaFilesAfter = 1;
128 my $preprocessExisting = 0;
129 my $batchPreprocess = 1;
130 my $verifyJavaFilesFromScriptFiles = 1;
132 my $batchCompile = 1;
133 my $verifyClassFilesFromJavaFiles = 1;
134 my $updatePerforce = 1;
135 my $submitToPerforce = 0;
137 # =====================================================================
139 print STDERR
"Running on branch $branch\n";
141 if ($perforceEditClassFiles)
143 print STDERR
"Opening all .class files for edit...\n";
144 system("p4 edit $depotClassBaseDir/... > /dev/null") == 0 || die "could not edit class files\n";
145 system("p4 lock $depotClassBaseDir/... > /dev/null") == 0 || die "could not lock class files\n";
148 if ($removeClassFiles)
150 print STDERR
"Deleting all .class files...\n";
151 foreach (findFiles
($localClassBaseDir))
153 die "file does not end in .class" if (!/\.class$/);
154 unlink($_) || die "could not remove file $_\n";
158 if ($removeJavaFilesBefore)
160 print STDERR
"Removing temporary java files...\n";
162 opendir(DIR
, $localScriptBaseDir) || die "could not open dir $localScriptBaseDir";
163 while ($_ = readdir(DIR
))
165 next if ($_ eq "." || $_ eq "..");
166 my $new = $localScriptBaseDir . "/" . $_;
167 push(@paths, $new) if (-d
$new);
170 foreach my $java (grep(/\.java$/, findFiles
(@paths)))
172 unlink($java) || die "could not remove temporary java file $java\n";
176 if ($preprocess || $verifyJavaFilesFromScriptFiles)
178 my @files = grep(/\.script(lib)?$/, findFiles
($localScriptBaseDir));
184 unlink("pythonPreprocessorStdout.log");
185 unlink("pythonPreprocessorStderr.log");
187 if ($batchPreprocess)
189 print STDERR
"Batch preprocessing all scripts...\n";
190 open(PYTHON
, "| xargs --max-procs=2 python2 $pythonPreprocessor -nocompile >> pythonPreprocessorStdout.log 2>> pythonPreprocessorStderr.log");
191 print PYTHON
join("\n", @files), "\n";
196 print STDERR
"Single preprocessing all scripts...\n";
198 my $files = scalar(@files);
201 foreach my $script (@files)
203 print STDERR
sprintf("%3d", (($count * 100) / $files)), "% $count/$files $script\n";
206 $java =~ s/\.script(lib)?/\.java/;
207 if ($preprocessExisting || !-e $java)
209 system("python2
$pythonPreprocessor -nocompile
$script >> pythonPreprocessorStdout
.log 2>> pythonPreprocessorStderr
.log");
215 print STDERR "preprocessing
: ", time - $start, "s
\n";
218 die "script files failed preprocessing
\n" if (-s "pythonPreprocessorStderr
.log");
220 if ($verifyJavaFilesFromScriptFiles)
223 foreach my $script (@files)
226 $java =~ s/\.script(lib)?/\.java/;
229 print STDERR "could
not find java file
$java from script file
$script\n";
233 die "missing java files
\n" if ($die);
237 if ($compile || $verifyClassFilesFromJavaFiles)
239 my @files = grep(/\.java$/, findFiles($localScriptBaseDir));
240 my $files = scalar(@files);
249 print STDERR "Batch java compiling all the scripts
...\n";
251 open(JAVAC, "| xargs javac
-classpath
$localJavaDestinationDir -d
$localJavaDestinationDir -sourcepath
$localJavaSourceDir -g
-deprecation
>> javac
.log 2>&1");
252 print JAVAC join("\n", @files), "\n";
257 print STDERR "Single java compiling all the scripts
...\n";
261 foreach my $java (@files)
263 print STDERR sprintf("%3d", (($count * 100) / $files)), "% $count/$files $errors $java\n";
264 $errors += 1 if (system("javac
-classpath
$localJavaDestinationDir -d
$localJavaDestinationDir -sourcepath
$localJavaSourceDir -g
-deprecation
$java >> javac
.log 2>&1") != 0);
269 print STDERR "compile
: ", time - $start, "s
\n";
272 die "java files failed compilation
\n" if (-s "javac
.log");
274 if ($verifyClassFilesFromJavaFiles)
277 foreach my $java (@files)
280 $class =~ s/\.java/\.class/;
281 $class =~ s/$localScriptBaseDir/$localClassBaseDir/;
284 print STDERR "could
not find
class file
$class for java file
$java\n";
288 die "missing
class files
\n" if ($die);
292 if ($removeJavaFilesAfter)
294 print STDERR "Removing temporary java files
...\n";
296 opendir(DIR, $localScriptBaseDir) || die "could
not open dir
$localScriptBaseDir";
297 while ($_ = readdir(DIR))
299 next if ($_ eq "." || $_ eq "..");
300 my $new = $localScriptBaseDir . "/" . $_;
301 push(@paths, $new) if (-d $new);
304 foreach my $java (grep(/\.java$/, findFiles(@paths)))
306 unlink($java) || die "could
not remove temporary java file
$java\n";
312 print STDERR "Searching
for class files to
delete...\n";
313 my @openedFiles = perforceGetOpenFiles();
315 foreach (grep(/\.class$/, @openedFiles))
317 s/$depotClassBaseDir/$localClassBaseDir/;
318 push (@deleted, $_) if (! -e $_);
323 print join("\n", @deleted), "\n";
325 print STDERR "Deleting old
.class files
...\n";
326 open(P4, "| p4
-x
- revert
> /dev/null
");
327 print P4 join("\n", @deleted), "\n";
330 open(P4, "| p4
-x
- delete > /dev/null
");
331 print P4 join("\n", @deleted), "\n";
335 print STDERR "Searching
for class files to add
...\n";
336 open(P4, "| p4
-x
- add
2> /dev/null
> /dev/null
");
337 foreach (findFiles($localClassBaseDir))
339 die "file does
not end
in .class" if (!/\.class$/);
345 print STDERR "Reverting unchanged files
...\n";
346 system("p4 revert
-a
> /dev/null
");
348 if ($submitToPerforce)
350 print STDERR "Submitting to perforce
...\n";
351 perforceSubmit("[automated
]", "- Recompile all scripts
");