Skip to content

Commit 4b7adc6

Browse files
committed
Massive parallelism with powershell
1 parent 642e7f0 commit 4b7adc6

2 files changed

Lines changed: 53 additions & 19 deletions

File tree

Validate.py

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#! py -3
22
from pathlib import Path
33
import pprint
4+
import os, sys
5+
from contextlib import contextmanager
46

5-
6-
# def extract(line, token):
7-
# tag = line.split(token)[1]
8-
# return tag.split("}")[0].strip()
7+
# Powershell: https://gist.github.com/diyan/2850866
98

109
class Flags:
1110
discard = ["{Requires:"]
@@ -29,6 +28,9 @@ def __init__(self, lines):
2928
else:
3029
self.flags[flag] = None # Make an entry, but no arg
3130

31+
def __contains__(self, elt):
32+
return elt in self.flags
33+
3234
def __repr__(self):
3335
return pprint.pformat(self.flags)
3436

@@ -60,32 +62,37 @@ def __init__(self, path, body):
6062
self.lines = body.splitlines()
6163
self.flags = Flags(self.lines)
6264
self._package = ""
63-
# self.args = ""
64-
# self.jvm_args = ""
65-
# self.brace_cmds = ""
6665
for line in self.lines:
67-
# if "{Args:" in line:
68-
# self.args = extract(line,"{Args:")
69-
# if "{JVMArgs:" in line:
70-
# self.jvm_args = extract(line,"{JVMArgs:") + " "
7166
if line.startswith("package "):
7267
self._package = line.split("package ")[1].strip()[:-1]
7368
if self._package.replace('.', '/') not in self.lines[0]:
7469
self._package = ""
75-
# if line.startswith("// {"):
76-
# self.brace_cmds += line + "\n"
70+
71+
def __contains__(self, elt):
72+
return elt in self.flags
7773

7874
def __repr__(self):
79-
return str(self.relative) + "\n" #+ self.header
75+
return str(self.relative) + ": " + self.name
8076

8177
def package(self):
8278
return self._package + '.' if self._package else ''
8379

80+
def rundir(self):
81+
"Directory to change to before running the command"
82+
return self.path.parent
83+
84+
def javaArguments(self):
85+
return self.flags.jvm_args() + self.package() + self.name + self.flags.cmd_args()
86+
8487
def runCommand(self):
85-
return "[" + str(self.path.parent) + "] java " + self.flags.jvm_args() + self.package() + self.name + self.flags.cmd_args()
88+
return "java " + self.javaArguments()
8689

8790

8891
class RunFiles:
92+
# RunFirst is temporary?
93+
not_runnable = ["RunByHand", "TimeOutDuringTesting", "CompileTimeError", 'TimeOut', 'RunFirst']
94+
skip_dirs = ["gui", "swt"]
95+
8996
base = Path(".")
9097
def __init__(self):
9198
self.runFiles = []
@@ -94,6 +101,8 @@ def __init__(self):
94101
body = code.read()
95102
if "static void main(String[] args)" in body:
96103
self.runFiles.append(RunnableFile(java, body))
104+
self.runFiles = [f for f in self.runFiles if not [nr for nr in self.not_runnable if nr in f]]
105+
self.runFiles = [f for f in self.runFiles if not [nd for nd in self.skip_dirs if nd in f.path.parts[0]]]
97106

98107
def allFlagKeys(self):
99108
flagkeys = set()
@@ -110,10 +119,35 @@ def allFlags(self):
110119
def runCommands(self):
111120
return [f.runCommand() for f in self.runFiles]
112121

122+
def runData(self):
123+
return "\n".join(["[{}] {}".format(f.rundir(), f.runCommand()) for f in self.runFiles])
124+
125+
def __iter__(self):
126+
return iter(self.runFiles)
127+
128+
129+
@contextmanager
130+
def visitDir(d):
131+
d = str(d)
132+
old = os.getcwd()
133+
os.chdir(d)
134+
yield d
135+
os.chdir(old)
136+
137+
113138
if __name__ == '__main__':
114139
assert Path.cwd().stem is "ExtractedExamples"
115140
runFiles = RunFiles()
116-
pprint.pprint(runFiles.allFlags())
117-
pprint.pprint(runFiles.runCommands())
118-
141+
startDir = os.getcwd()
142+
# [print(f, f.flags) for f in runFiles]
143+
# sys.exit()
144+
with open("runall.ps1", 'w') as ps:
145+
for rf in runFiles:
146+
with visitDir(rf.rundir()):
147+
ps.write("cd {}\n".format(os.getcwd()))
148+
ps.write('Start-Process -FilePath "java.exe" -ArgumentList "{}" -NoNewWindow -RedirectStandardOutput {}-output.txt -RedirectStandardError {}-erroroutput.txt \n'.format(rf.javaArguments(), rf.name, rf.name))
149+
ps.write('Write-Host [{}] {}\n'.format(rf.relative, rf.name))
150+
ps.write("cd {}\n".format(startDir))
151+
152+
# pprint.pprint(runFiles.runCommands())
119153

tools/Examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def dirPath(self):
248248

249249
def arguments(self):
250250
if self.cmdargs:
251-
return """arguments='%s' """ % self.cmdargs
251+
return """arguments="%s" """ % self.cmdargs
252252
return ""
253253

254254
def failOnError(self):

0 commit comments

Comments
 (0)