17from io
import StringIO
18from subprocess
import getoutput
22 id = platform.system()
27 elif id ==
"Windows" or id ==
"Microsoft":
43 id = platform.machine()
44 if id.startswith(
'arm'):
46 elif (
not id)
or (
not re.match(
'(x|i[3-6])86', id)
is None):
56 if os.path.exists(
"/proc/cpuinfo"):
59 "GREP_OPTIONS= grep -E '^processor' /proc/cpuinfo | wc -l"))
60 if os.path.exists(
"/usr/bin/hostinfo"):
63 '/usr/bin/hostinfo | GREP_OPTIONS= grep "processors are logically available." | awk "{ print \\$1 }"'
65 win_cpu_count = os.getenv(
"NUMBER_OF_PROCESSORS")
67 return int(win_cpu_count)
68 return int(os.getenv(
"DART_NUMBER_OF_CORES", 2))
80 for line
in open(name):
82 line = line[:line.find(
'#')]
96 for arg
in parser.rargs:
97 if arg[:2].startswith(
'--'):
101 del parser.rargs[:
len(value)]
102 setattr(parser.values, option.dest, value)
111 for arg
in parser.rargs:
112 if arg[:2].startswith(
'--')
or arg[0] !=
'-':
116 del parser.rargs[:
len(value)]
117 setattr(parser.values, option.dest, value)
123 'release':
'Release',
128 'linux': os.path.join(
'out'),
129 'freebsd': os.path.join(
'out'),
130 'macos': os.path.join(
'xcodebuild'),
136 return BUILD_MODES[mode]
146 return os.path.join(BUILD_ROOT[host_os],
149 return BUILD_ROOT[host_os]
157 killOnEarlyReturn=True,
160 printErrorInfo=False):
162 Run a command, with optional input
and polling function.
165 command: list of the command
and its arguments.
166 input: optional string of input to feed to the command, it should be
167 short enough to fit
in an i/o pipe buffer.
168 pollFn:
if present will be called occasionally to check
if the command
169 should be finished early. If pollFn() returns true then the command
171 outStream:
if present, the stdout output of the command will be written to
173 errStream:
if present, the stderr output of the command will be written to
175 killOnEarlyReturn:
if true
and pollFn returns true, then the subprocess will
176 be killed, otherwise the subprocess will be detached.
177 verbose:
if true, the command
is echoed to stderr.
178 debug:
if true, prints debugging information to stderr.
179 printErrorInfo:
if true, prints error information when the subprocess
180 returns a non-zero exit code.
181 Returns: the output of the subprocess.
184 Raises Error
if the subprocess returns an error code.
185 Raises ValueError
if called
with invalid arguments.
188 sys.stderr.write(
"command %s\n" % command)
191 stdin = subprocess.PIPE
193 process = subprocess.Popen(
197 stdout=subprocess.PIPE,
198 stderr=subprocess.PIPE)
200 if not isinstance(command, str):
201 command =
' '.
join(command)
203 sys.stderr.write(
"Command failed: '%s'\n" % command)
206 def StartThread(out):
207 queue = queue.Queue()
209 def EnqueueOutput(out, queue):
210 for line
in iter(out.readline, b
''):
214 thread = threading.Thread(target=EnqueueOutput, args=(out, queue))
219 outQueue = StartThread(process.stdout)
220 errQueue = StartThread(process.stderr)
222 def ReadQueue(queue, out, out2):
225 line = queue.get(
False)
232 outBuf = StringIO.StringIO()
233 errorBuf = StringIO.StringIO()
235 process.stdin.write(input)
237 returncode = process.poll()
238 if returncode !=
None:
240 ReadQueue(errQueue, errorBuf, errStream)
241 ReadQueue(outQueue, outBuf, outStream)
242 if pollFn !=
None and pollFn():
244 if killOnEarlyReturn:
249 ReadQueue(errQueue, errorBuf, errStream)
250 ReadQueue(outQueue, outBuf, outStream)
252 out = outBuf.getvalue()
253 error = errorBuf.getvalue()
255 if not isinstance(command, str):
256 command =
' '.
join(command)
258 sys.stderr.write(
"Command failed: '%s'\n" % command)
259 sys.stderr.write(
" stdout: '%s'\n" % out)
260 sys.stderr.write(
" stderr: '%s'\n" % error)
261 sys.stderr.write(
" returncode: %d\n" % returncode)
262 raise Error(
"Command failed: %s" % command)
264 sys.stderr.write(
"output: %s\n" % out)
279if __name__ ==
"__main__":
def print(*args, **kwargs)
def ListArgCallback(option, opt_str, value, parser)
def GetBuildConf(mode, arch)
def RunCommand(command, input=None, pollFn=None, outStream=None, errStream=None, killOnEarlyReturn=True, verbose=False, debug=False, printErrorInfo=False)
def ListDashArgCallback(option, opt_str, value, parser)
def GetBuildRoot(host_os, mode=None, arch=None, sanitizer=None)
static SkString join(const CommandLineFlags::StringArray &)