Skip to content

Commit ebaadbc

Browse files
committed
Log the truncated compiler string
Add the script name as prefix to all logged messages.
1 parent 1d9bb17 commit ebaadbc

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

‎Lib/test/test_tools/test_getbuildinfo.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import generate_getbuildinfo
1919

2020
SRC_DIR = os.path.dirname(test_tools.toolsdir)
21+
SCRIPT_NAME = 'generate_getbuildinfo.py'
2122

2223

2324
class TestGetBuildInfo(unittest.TestCase):
@@ -102,6 +103,7 @@ def test_get_compiler(self):
102103
mock_run_command.assert_called_once_with(cmd, check=False)
103104

104105
def test_compact_compiler(self):
106+
get_compiler = generate_getbuildinfo.get_compiler
105107
compact_compiler = generate_getbuildinfo.compact_compiler
106108

107109
def check(compiler, expected):
@@ -143,6 +145,13 @@ def check_unchanged(compiler):
143145
check_unchanged('GCC 15.2.0')
144146
check_unchanged('MSC v.1951 32 bit (Intel)')
145147

148+
with support.captured_stdout() as stdout:
149+
compiler = get_compiler('Clang 21.0.0 (clang-2100.1.1.101)')
150+
self.assertEqual(compiler, '[Clang 21.0.0]')
151+
self.assertEqual(stdout.getvalue(),
152+
f"{SCRIPT_NAME}: Truncate compiler string 'Clang 21.0.0 "
153+
"(clang-2100.1.1.101)' to 'Clang 21.0.0'\n")
154+
146155
def test_functional(self):
147156
old_locale = locale.setlocale(locale.LC_ALL)
148157
self.addCleanup(locale.setlocale, locale.LC_ALL, old_locale)
@@ -165,7 +174,7 @@ def test_functional(self):
165174
env['SOURCE_DATE_EPOCH'] = str(1791419852)
166175
with support.captured_stdout() as stdout:
167176
generate_getbuildinfo.main()
168-
self.assertEqual(stdout.getvalue(), f'{filename} updated\n')
177+
self.assertEqual(stdout.getvalue(), f'{SCRIPT_NAME}: {filename} updated\n')
169178

170179
with open(filename) as fp:
171180
output = fp.read()

‎Tools/build/generate_getbuildinfo.py‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
)
3030

3131

32+
def log(msg):
33+
print(f"{SCRIPT_NAME}: {msg}")
34+
35+
3236
def exit_error(msg):
33-
print(msg)
34-
print("cwd: {os.getcwd()}")
37+
log(msg)
3538
sys.exit(1)
3639

3740

@@ -104,7 +107,7 @@ def parse_args():
104107

105108
def run_command(cmd, *, check=True):
106109
cmd_str = shlex.join(cmd)
107-
print(f"+ {cmd_str}")
110+
log(f"+ {cmd_str}")
108111
try:
109112
proc = subprocess.run(cmd, stdout=subprocess.PIPE, text=True)
110113
except OSError as exc:
@@ -121,7 +124,7 @@ def run_command(cmd, *, check=True):
121124
if check:
122125
exit_error(msg)
123126
else:
124-
print(msg)
127+
log(msg)
125128
return None
126129

127130
return proc.stdout.rstrip()
@@ -177,7 +180,10 @@ def get_compiler(compiler):
177180
# (see Programs/_getcompiler.c)
178181
compiler = 'C'
179182

180-
compiler = compact_compiler(compiler)
183+
old_compiler = compiler
184+
compiler = compact_compiler(old_compiler)
185+
if compiler != old_compiler:
186+
log(f"Truncate compiler string {old_compiler!r} to {compiler!r}")
181187

182188
return f'[{compiler}]'
183189

@@ -231,7 +237,7 @@ def write_macro(name, value):
231237
write_macro('VERSION', version)
232238

233239
os.replace(new_filename, output_filename)
234-
print(f"{output_filename} updated")
240+
log(f"{output_filename} updated")
235241

236242

237243
if __name__ == "__main__":

0 commit comments

Comments
 (0)