]> git.saurik.com Git - apple/icu.git/blame - icuSources/data/buildtool/renderers/common_exec.py
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / data / buildtool / renderers / common_exec.py
CommitLineData
3d1f044b
A
1# Copyright (C) 2018 and later: Unicode, Inc. and others.
2# License & terms of use: http://www.unicode.org/copyright.html
3
4from . import *
5from .. import *
6from .. import utils
7from ..request_types import *
8
9import os
10import shutil
11import subprocess
12
13def run(build_dirs, requests, common_vars, **kwargs):
14 for bd in build_dirs:
15 os.makedirs(bd.format(**common_vars), exist_ok=True)
16 for request in requests:
17 status = run_helper(request, common_vars, **kwargs)
18 if status != 0:
19 print("!!! ERROR executing above command line: exit code %d" % status)
20 return 1
21 print("All data build commands executed")
22 return 0
23
24def 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,
29 )
30 print("Printing to file: %s" % output_path)
31 with open(output_path, "w") as f:
32 f.write(request.content)
33 return 0
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,
38 )
39 output_path = "{DIRNAME}/{FILENAME}".format(
40 DIRNAME = utils.dir_for(request.output_file).format(**common_vars),
41 FILENAME = request.output_file.filename,
42 )
43 print("Copying file to: %s" % output_path)
44 shutil.copyfile(input_path, output_path)
45 return 0
46 if isinstance(request, VariableRequest):
47 # No-op
48 return 0
49
50 assert isinstance(request.tool, IcuTool)
51 if is_windows:
52 cmd_template = "{TOOL_DIR}/{TOOL}/{TOOL_CFG}/{TOOL}.exe {{ARGS}}".format(
53 TOOL_DIR = tool_dir,
54 TOOL_CFG = tool_cfg,
55 TOOL = request.tool.name,
56 **common_vars
57 )
58 else:
59 cmd_template = "{TOOL_DIR}/{TOOL} {{ARGS}}".format(
60 TOOL_DIR = tool_dir,
61 TOOL = request.tool.name,
62 **common_vars
63 )
64
65 if isinstance(request, RepeatedExecutionRequest):
66 for loop_vars in utils.repeated_execution_request_looper(request):
67 command_line = utils.format_repeated_request_command(
68 request,
69 cmd_template,
70 loop_vars,
71 common_vars
72 )
73 if is_windows:
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:
79 return res.returncode
80 return 0
81 if isinstance(request, SingleExecutionRequest):
82 command_line = utils.format_single_request_command(
83 request,
84 cmd_template,
85 common_vars
86 )
87 if is_windows:
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)
92 return res.returncode
93 assert False