88import subprocess
99import sys
1010import traceback
11+ import platform
12+ import multiprocessing
1113from contextlib import contextmanager
1214
1315_SHQUOTE_WINDOWS_ESCAPEDCHARS = re .compile (r'(["\\])' )
@@ -37,6 +39,72 @@ def report(msg):
3739 print (msg , file = sys .stderr , flush = True )
3840
3941
42+ def report_prog_version (name , cmd ):
43+ try :
44+ p = subprocess .run (cmd , check = True , capture_output = True , text = True )
45+ outlines = p .stdout .strip ().splitlines ()
46+ report_list (name , outlines [0 ])
47+ except BaseException :
48+ pass
49+
50+
51+ def report_list (category , * items ):
52+ items = list (items )
53+ filtered = []
54+
55+ while items :
56+ item = items .pop ()
57+ match item :
58+ case tuple () | list ():
59+ items += item
60+ continue
61+ case None :
62+ continue
63+ case _:
64+ item = str (item ).strip ()
65+ if not item :
66+ continue
67+ if item in filtered :
68+ continue
69+ filtered .append (item )
70+ category += ":"
71+ report (f"{ category :<9} { ', ' .join (reversed ( filtered ))} " )
72+
73+
74+ def report_platform ():
75+ report_list (
76+ "CPU" ,
77+ platform .machine (),
78+ platform .architecture ()[0 ],
79+ platform .processor (),
80+ f"{ multiprocessing .cpu_count ()} native threads" ,
81+ )
82+ try :
83+ releaseinfo = platform .freedesktop_os_release ()
84+ except BaseException :
85+ releaseinfo = dict ()
86+ report_list (
87+ "OS" ,
88+ platform .system (),
89+ platform .architecture ()[1 ],
90+ platform .platform (),
91+ releaseinfo .get ("PRETTY_NAME" ),
92+ )
93+ report_list ("Python" , platform .python_implementation (), platform .python_version ())
94+
95+ report_prog_version ("CMake" , ["cmake" , "--version" ])
96+ report_prog_version ("Ninja" , ["ninja" , "--version" ])
97+ report_prog_version ("Sphinx" , ["sphinx-build" , "--version" ])
98+ report_prog_version ("Doxygen" , ["doxygen" , "--version" ])
99+
100+ report_prog_version ("gcc" , ["gcc" , "--version" ])
101+ report_prog_version ("ld" , ["ld" , "--version" ])
102+
103+ report_prog_version ("LLVM" , ["llvm-config" , "--version" ])
104+ report_prog_version ("Clang" , ["clang" , "--version" ])
105+ report_prog_version ("LLD" , ["ld.lld" , "--version" ])
106+
107+
40108def run_command (cmd , shell = False , ** kwargs ):
41109 """Report which command is being run, then execute it using subprocess.check_call."""
42110 report (f"Running: { cmd if shell else shjoin (cmd )} " )
@@ -51,8 +119,8 @@ def _remove_readonly(func, path, _):
51119
52120
53121def rmtree (path ):
54- """
55- Remove directory path and all its subdirectories. Includes a workaround for Windows where shutil.rmtree errors on read-only files.
122+ """Remove directory path and all its subdirectories. Includes a workaround
123+ for Windows where shutil.rmtree errors on read-only files.
56124
57125 Taken from official Pythons docs
58126 https://docs.python.org/3/library/shutil.html#rmtree-example
@@ -163,6 +231,10 @@ def step(self, step_name, halt_on_fail=False):
163231 with step (step_name , halt_on_fail = halt_on_fail ) as s :
164232 yield s
165233
234+ def report (self , msg ):
235+ """Convenience wrapper for report()"""
236+ report (msg )
237+
166238 def run_command (self , * args , ** kwargs ):
167239 """Convenience wrapper for run_command()"""
168240 return run_command (* args , ** kwargs )
@@ -179,7 +251,9 @@ def checkout(self, giturl, sourcepath):
179251def convert_bool (v ):
180252 """Convert input to bool type
181253
182- Use to convert the value of bool environment variables. Specifically, the buildbot master sets 'false' to build properties, which by default Python would interpret as true-ish.
254+ Use to convert the value of bool environment variables. Specifically, the
255+ buildbot master sets 'false' to build properties, which by default Python
256+ would interpret as true-ish.
183257 """
184258 match v :
185259 case None :
@@ -390,4 +464,8 @@ def run(
390464 )
391465
392466 os .environ ["NINJA_STATUS" ] = "[%p/%es :: %u->%r->%f (of %t)] "
467+
468+ with step ("platform-info" ):
469+ report_platform ()
470+
393471 yield w
0 commit comments