Skip to content

Commit a337501

Browse files
committed
bootstrap: fix regression
The `Utilities/bootstrap` script is no longer emitting Swift PM build status information. This change reverted the #8161 and then converted the print calls to use python's logging module. Fixes #8281
1 parent 2215d09 commit a337501

File tree

2 files changed

+29
-38
lines changed

2 files changed

+29
-38
lines changed

Utilities/bootstrap

+22-31
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import sys
2828
from helpers import symlink_force, mkdir_p, call, call_output
2929

3030

31+
3132
logging.basicConfig(
3233
stream=sys.stdout,
3334
format=" | ".join([
@@ -42,6 +43,8 @@ logging.basicConfig(
4243
]),
4344
level=logging.INFO,
4445
)
46+
47+
4548
g_macos_deployment_target = '12.0'
4649

4750
g_shared_lib_prefix = "lib"
@@ -50,10 +53,11 @@ if platform.system() == 'Darwin':
5053
else:
5154
g_shared_lib_suffix = ".so"
5255

56+
5357
class BinaryNotFound(BaseException):
5458

5559
def __init__(self, *, tool: str, path: pathlib.Path):
56-
super().__init__("Unable to find {tool} source directory at {path}")
60+
super().__init__(f"Unable to find {tool} source directory at {path}")
5761

5862

5963
def main():
@@ -84,7 +88,7 @@ def main():
8488
parser_install.set_defaults(func=install)
8589
add_build_args(parser_install)
8690

87-
logging.info("sys.argv: %r", sys.argv)
91+
logging.debug("sys.argv: %r", sys.argv)
8892
args = parser.parse_args()
8993
# update the root logger level based on the verbose flag
9094
logging.getLogger().setLevel(logging.DEBUG if args.verbose else logging.INFO)
@@ -232,7 +236,7 @@ def parse_global_args(args):
232236
args.source_root = os.path.join(args.project_root, "Sources")
233237

234238
if platform.system() == 'Darwin':
235-
args.sysroot = call_output(["xcrun", "--sdk", "macosx", "--show-sdk-path"], verbose=args.verbose)
239+
args.sysroot = call_output(["xcrun", "--sdk", "macosx", "--show-sdk-path"])
236240
else:
237241
args.sysroot = None
238242

@@ -279,50 +283,39 @@ def parse_test_args(args):
279283

280284
def get_swiftc_path(args):
281285
"""Returns the path to the Swift compiler."""
282-
logging.debug("Getting path to swiftc...")
283286
if args.swiftc_path:
284287
swiftc_path = os.path.abspath(args.swiftc_path)
285-
logging.debug("path provided via command line argument. swiftc_path is %r", swiftc_path)
286288
elif os.getenv("SWIFT_EXEC"):
287-
swiftc_path = os.getenv("SWIFT_EXEC")
288-
logging.debug("SWIFT_EXEC env set. swiftc_path set to %r", swiftc_path)
289+
swiftc_path = os.path.realpath(os.getenv("SWIFT_EXEC"))
289290
elif platform.system() == 'Darwin':
290-
logging.debug("we are on darwin, so calling `xcrun --find swiftc`")
291291
swiftc_path = call_output(
292292
["xcrun", "--find", "swiftc"],
293293
stderr=subprocess.PIPE,
294-
verbose=args.verbose,
295294
)
296-
logging.debug("swiftc_path is set to %r", swiftc_path)
297295
else:
298-
swiftc_path = call_output(["which", "swiftc"], verbose=args.verbose)
299-
logging.debug("calling 'which swiftc'. path is %r", swiftc_path)
296+
swiftc_path = call_output(["which", "swiftc"])
300297

301298
if os.path.basename(swiftc_path) == 'swift':
302299
swiftc_path = swiftc_path + 'c'
303-
logging.debug("appending to path, it is now %r", swiftc_path)
304300

305-
logging.debug("swiftc_path set to %r", swiftc_path)
306301
if os.path.exists(swiftc_path):
307-
logging.debug("swiftc_path exists.. returning...")
308302
return swiftc_path
309303
logging.error("unable to find swiftc at %s", swiftc_path)
310304
raise BinaryNotFound(tool="swiftc", path=swiftc_path)
311305

306+
312307
def get_tool_path(args, tool):
313308
"""Returns the path to the specified tool."""
314-
logging.debug("Searching for %s tool", tool)
315309
path = getattr(args, tool + "_path", None)
316310
if path is not None:
317311
return os.path.abspath(path)
318312
elif platform.system() == 'Darwin':
319313
return call_output(
320314
["xcrun", "--find", tool],
321315
stderr=subprocess.PIPE,
322-
verbose=args.verbose,
323316
)
324317
else:
325-
return call_output(["which", tool], verbose=args.verbose)
318+
return call_output(["which", tool])
326319

327320
def get_build_target(args, cross_compile=False):
328321
"""Returns the target-triple of the current machine or for cross-compilation."""
@@ -331,14 +324,11 @@ def get_build_target(args, cross_compile=False):
331324
if cross_compile:
332325
cross_compile_json = json.load(open(args.cross_compile_config))
333326
command += ['-target', cross_compile_json["target"]]
334-
logging.debug("Running command >>> %r", command)
335327
target_info_json = subprocess.check_output(command,
336-
stderr=subprocess.PIPE, universal_newlines=True, env=os.environ).strip()
337-
logging.debug("Command returned: %r", target_info_json)
328+
stderr=subprocess.PIPE, universal_newlines=True).strip()
338329
args.target_info = json.loads(target_info_json)
339330
return args.target_info["target"]["unversionedTriple" if platform.system() == 'Darwin' else "triple"]
340331
except subprocess.CalledProcessError as cpe:
341-
logging.debug("Command failed...")
342332
# Temporary fallback for Darwin.
343333
if platform.system() == 'Darwin':
344334
macOS_default = 'x86_64-apple-macosx'
@@ -357,7 +347,7 @@ def clean(args):
357347
logging.info("Cleaning")
358348
parse_global_args(args)
359349

360-
call(["rm", "-rf", args.build_dir], verbose=args.verbose)
350+
call(["rm", "-rf", args.build_dir])
361351

362352
def build(args):
363353
"""Builds SwiftPM using a two-step process: first using CMake, then with itself."""
@@ -564,7 +554,7 @@ def build_with_cmake(args, cmake_args, ninja_args, source_path, build_dir, cmake
564554
logging.debug(' '.join(cmd))
565555

566556
mkdir_p(build_dir)
567-
call(cmd, cwd=build_dir, verbose=True)
557+
call(cmd, cwd=build_dir)
568558

569559
# Build.
570560
ninja_cmd = [args.ninja_path]
@@ -575,7 +565,7 @@ def build_with_cmake(args, cmake_args, ninja_args, source_path, build_dir, cmake
575565
if platform.system() == 'Darwin':
576566
call(["sed", "-i", "", "s/macosx10.10/macosx%s/" % (g_macos_deployment_target), "build.ninja"], cwd=build_dir)
577567

578-
call(ninja_cmd + ninja_args, cwd=build_dir, verbose=args.verbose)
568+
call(ninja_cmd + ninja_args, cwd=build_dir)
579569

580570
def build_llbuild(args):
581571
"""Builds LLBuild using CMake."""
@@ -586,7 +576,7 @@ def build_llbuild(args):
586576

587577
api_dir = os.path.join(args.build_dirs["llbuild"], ".cmake/api/v1/query")
588578
mkdir_p(api_dir)
589-
call(["touch", "codemodel-v2"], cwd=api_dir, verbose=args.verbose)
579+
call(["touch", "codemodel-v2"], cwd=api_dir)
590580

591581
flags = [
592582
"-DCMAKE_C_COMPILER:=%s" % (args.clang_path),
@@ -627,7 +617,7 @@ def add_rpath_for_cmake_build(args, rpath):
627617
swift_build = os.path.join(args.bootstrap_dir, "bin/swift-bootstrap")
628618
add_rpath_cmd = ["install_name_tool", "-add_rpath", rpath, swift_build]
629619
logging.info(' '.join(add_rpath_cmd))
630-
subprocess.call(add_rpath_cmd, stderr=subprocess.PIPE, env=os.environ)
620+
subprocess.call(add_rpath_cmd, stderr=subprocess.PIPE)
631621

632622
def get_swift_backdeploy_library_paths(args):
633623
if platform.system() == 'Darwin':
@@ -719,7 +709,7 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
719709

720710
def call_swiftpm(args, cmd, cwd=None):
721711
"""Calls a SwiftPM binary with the necessary environment variables and flags."""
722-
logging.info("function args: %r, cmd: %r, cwd: %r", args, cmd, cwd)
712+
logging.debug("function %s args: %r, cmd: %r, cwd: %r", call_swiftpm.__qualname__, args, cmd, cwd)
723713
args.build_target = get_build_target(args, cross_compile=(True if args.cross_compile_config else False))
724714

725715
logging.debug("build target: %r", args.build_target)
@@ -728,8 +718,9 @@ def call_swiftpm(args, cmd, cwd=None):
728718
args.platform_path = re.search(r"(lib/swift/([^/]+))$", path)
729719
if args.platform_path:
730720
break
731-
else:
732-
# this gets called if the for loop does not break
721+
# else:
722+
# # this gets called if the for loop does not break
723+
if not args.platform_path:
733724
logging.error(
734725
"the command `%s -print-target-info` didn't return a valid runtime library path",
735726
args.swiftc_path
@@ -739,7 +730,7 @@ def call_swiftpm(args, cmd, cwd=None):
739730
full_cmd = get_swiftpm_env_cmd(args) + cmd + get_swiftpm_flags(args)
740731
if cwd is None:
741732
cwd = args.project_root
742-
call_output(full_cmd, cwd=cwd, stderr=True, verbose=True)
733+
call(full_cmd, cwd=cwd)
743734

744735
# -----------------------------------------------------------
745736
# Build-related helper functions

Utilities/helpers.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ def mkdir_p(path):
3535
if e.errno != errno.EEXIST:
3636
raise
3737

38-
def call(cmd, cwd=None, verbose=False):
38+
def call(cmd, cwd=None):
3939
"""Calls a subprocess."""
40-
logging.info("executing command >>> %s", ' '.join(cmd))
40+
logging.info("executing command >>> %r", ' '.join(cmd))
4141
try:
4242
subprocess.check_call(cmd, cwd=cwd)
4343
except subprocess.CalledProcessError as cpe:
44-
logging.debug("executing command >>> %s", ' '.join(cmd))
44+
logging.debug("command failed >>> %r", ' '.join(cmd))
4545
logging.error("Process failure: %s", str(cpe))
4646
raise cpe
4747

48-
def call_output(cmd, cwd=None, stderr=False, verbose=False):
48+
def call_output(cmd, cwd=None, stderr=False):
4949
"""Calls a subprocess for its return data."""
50-
logging.info(' '.join(cmd))
50+
logging.info("executing command >>> %r", ' '.join(cmd))
5151
try:
5252
return subprocess.check_output(cmd, cwd=cwd, stderr=stderr, universal_newlines=True).strip()
5353
except subprocess.CalledProcessError as cpe:
54-
logging.debug(' '.join(cmd))
55-
logging.error(str(cpe))
54+
logging.debug("command failed >>> %r", ' '.join(cmd))
55+
logging.error("Process failure: %s", str(cpe))
5656
raise cpe

0 commit comments

Comments
 (0)