WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}"
+def separator():
+ """Print a separator line across the terminal width."""
+ try:
+ tput_output = subprocess.check_output(
+ ["tput", "cols"], encoding="utf-8"
+ )
+ except subprocess.CalledProcessError:
+ terminal_width = 80
+ else:
+ terminal_width = int(tput_output.strip())
+ print("โฏ" * terminal_width)
+
+
+def log(emoji, message, *, spacing=None):
+ """Print a notification with an emoji.
+
+ If 'spacing' is None, calculate the spacing based on the number of code points
+ in the emoji as terminals "eat" a space when the emoji has multiple code points.
+ """
+ if spacing is None:
+ spacing = " " if len(emoji) == 1 else " "
+ print("".join([emoji, spacing, message]))
+
+
def updated_env(updates={}):
"""Create a new dict representing the environment to use.
if os.environ.get(key) != value:
env_diff[key] = value
- print("๐ Environment changes:")
- for key in sorted(env_diff.keys()):
- print(f" {key}={env_diff[key]}")
+ env_vars = (
+ f"\n {key}={item}" for key, item in sorted(env_diff.items())
+ )
+ log("๐", f"Environment changes:{''.join(env_vars)}")
return environment
if callable(working_dir):
working_dir = working_dir(context)
- try:
- tput_output = subprocess.check_output(
- ["tput", "cols"], encoding="utf-8"
- )
- except subprocess.CalledProcessError:
- terminal_width = 80
- else:
- terminal_width = int(tput_output.strip())
- print("โฏ" * terminal_width)
- print("๐", working_dir)
+ separator()
+ log("๐", os.fsdecode(working_dir))
if (
clean_ok
and getattr(context, "clean", False)
and working_dir.exists()
):
- print("๐ฎ Deleting directory (--clean)...")
+ log("๐ฎ", "Deleting directory (--clean)...")
shutil.rmtree(working_dir)
working_dir.mkdir(parents=True, exist_ok=True)
elif quiet and logdir is None:
raise ValueError("When quiet is True, logdir must be specified")
- print("โฏ", " ".join(map(str, command)))
+ log("โฏ", " ".join(map(str, command)), spacing=" ")
if not quiet:
stdout = None
stderr = None
suffix=".log",
)
stderr = subprocess.STDOUT
- print(f"๐ Logging output to {stdout.name} (--quiet)...")
+ log("๐", f"Logging output to {stdout.name} (--quiet)...")
subprocess.check_call(command, **kwargs, stdout=stdout, stderr=stderr)
"""Configure the build/host Python."""
if LOCAL_SETUP.exists():
if LOCAL_SETUP.read_bytes() == LOCAL_SETUP_MARKER:
- print(f"๐ {LOCAL_SETUP} exists ...")
+ log("๐", f"{LOCAL_SETUP} exists ...")
else:
- print(f"โ ๏ธ {LOCAL_SETUP} exists, but has unexpected contents")
+ log("โ ๏ธ", f"{LOCAL_SETUP} exists, but has unexpected contents")
else:
- print(f"๐ Creating {LOCAL_SETUP} ...")
+ log("๐", f"Creating {LOCAL_SETUP} ...")
LOCAL_SETUP.write_bytes(LOCAL_SETUP_MARKER)
configure = [os.path.relpath(CHECKOUT / "configure", working_dir)]
]
version = subprocess.check_output(cmd, encoding="utf-8").strip()
- print(f"๐ {binary} {version}")
+ log("๐", f"{binary} {version}")
def find_wasi_sdk():
# supported version is a prefix of the found version (e.g. `25` and `2567`).
if not found_version.startswith(f"{WASI_SDK_VERSION}."):
major_version = found_version.partition(".")[0]
- print(
- f"โ ๏ธ Found WASI SDK {major_version}, "
- f"but WASI SDK {WASI_SDK_VERSION} is the supported version"
+ log(
+ "โ ๏ธ",
+ f" Found WASI SDK {major_version}, "
+ f"but WASI SDK {WASI_SDK_VERSION} is the supported version",
)
return wasi_sdk_path
with exec_script.open("w", encoding="utf-8") as file:
file.write(f'#!/bin/sh\nexec {host_runner} {python_wasm} "$@"\n')
exec_script.chmod(0o755)
- print(f"๐โโ๏ธ Created {exec_script} (--host-runner)... ")
+ log("๐", f"Created {exec_script} (--host-runner)... ")
sys.stdout.flush()
exec_script = working_dir / "python.sh"
call([exec_script, "--version"], quiet=False)
- print(
- f"๐ Use `{exec_script.relative_to(context.init_dir)}` "
- "to run CPython w/ the WASI host specified by --host-runner"
+ log(
+ "๐",
+ f"Use `{exec_script.relative_to(context.init_dir)}` "
+ "to run CPython w/ the WASI host specified by --host-runner",
)
def clean_contents(context):
"""Delete all files created by this script."""
if CROSS_BUILD_DIR.exists():
- print(f"๐งน Deleting {CROSS_BUILD_DIR} ...")
+ log("๐งน", f"Deleting {CROSS_BUILD_DIR} ...")
shutil.rmtree(CROSS_BUILD_DIR)
if LOCAL_SETUP.exists():
if LOCAL_SETUP.read_bytes() == LOCAL_SETUP_MARKER:
- print(f"๐งน Deleting generated {LOCAL_SETUP} ...")
+ log("๐งน", f"Deleting generated {LOCAL_SETUP} ...")
def main():