]>
git.saurik.com Git - apple/icu.git/blob - icuSources/data/buildtool/renderers/common_exec.py
1 # Copyright (C) 2018 and later: Unicode, Inc. and others.
2 # License & terms of use: http://www.unicode.org/copyright.html
7 from ..request_types
import *
13 def run(build_dirs
, requests
, common_vars
, **kwargs
):
15 os
.makedirs(bd
.format(**common_vars
), exist_ok
=True)
16 for request
in requests
:
17 status
= run_helper(request
, common_vars
, **kwargs
)
19 print("!!! ERROR executing above command line: exit code %d" % status
)
21 print("All data build commands executed")
24 def run_helper(request
, common_vars
, is_windows
, tool_dir
, tool_cfg
=None, **kwargs
):
25 if isinstance(request
, PrintFileRequest
):
26 output_path
= "{DIRNAME}/{FILENAME}".format(
27 DIRNAME
= utils
.dir_for(request
.output_file
).format(**common_vars
),
28 FILENAME
= request
.output_file
.filename
,
30 print("Printing to file: %s" % output_path
)
31 with open(output_path
, "w") as f
:
32 f
.write(request
.content
)
34 if isinstance(request
, CopyRequest
):
35 input_path
= "{DIRNAME}/{FILENAME}".format(
36 DIRNAME
= utils
.dir_for(request
.input_file
).format(**common_vars
),
37 FILENAME
= request
.input_file
.filename
,
39 output_path
= "{DIRNAME}/{FILENAME}".format(
40 DIRNAME
= utils
.dir_for(request
.output_file
).format(**common_vars
),
41 FILENAME
= request
.output_file
.filename
,
43 print("Copying file to: %s" % output_path
)
44 shutil
.copyfile(input_path
, output_path
)
46 if isinstance(request
, VariableRequest
):
50 assert isinstance(request
.tool
, IcuTool
)
52 cmd_template
= "{TOOL_DIR}/{TOOL}/{TOOL_CFG}/{TOOL}.exe {{ARGS}}".format(
55 TOOL
= request
.tool
.name
,
59 cmd_template
= "{TOOL_DIR}/{TOOL} {{ARGS}}".format(
61 TOOL
= request
.tool
.name
,
65 if isinstance(request
, RepeatedExecutionRequest
):
66 for loop_vars
in utils
.repeated_execution_request_looper(request
):
67 command_line
= utils
.format_repeated_request_command(
74 # Note: this / to \ substitution may be too aggressive?
75 command_line
= command_line
.replace("/", "\\")
76 print("Running: %s" % command_line
)
77 res
= subprocess
.run(command_line
, shell
=True)
78 if res
.returncode
!= 0:
81 if isinstance(request
, SingleExecutionRequest
):
82 command_line
= utils
.format_single_request_command(
88 # Note: this / to \ substitution may be too aggressive?
89 command_line
= command_line
.replace("/", "\\")
90 print("Running: %s" % command_line
)
91 res
= subprocess
.run(command_line
, shell
=True)