l0_cli_build.py

l0_cli_build.py

Module: l0_cli_build

Source: compiler/stage1_py/l0_cli_build.py Language: Python

Symbols

Namespace l0_cli_build

Function l0_cli_build._find_cc

1
str | None l0_cli_build._find_cc()

Find the best available C compiler.

Used in codegen and build stages if the user didn’t specify one explicitly.

The search order is:

  1. L0_CC environment variable. 2. Common compiler names in PATH: tcc, gcc, clang, cc (in that order). 3. CC environment variable.

Returns: The compiler command if found, or None if no compiler is found.

Function l0_cli_build._compiler_flag_family

1
l0_cli_build._compiler_flag_family(str compiler)

Determine the compiler family for flag selection using a simple heuristic.

Uses pattern matching to handle cases like “gcc-10” or “clang-14” on Unix and “gcc.exe” or “clang.exe” on Windows.

Parameters:

  • compiler: The compiler command string.

Returns: A string representing the compiler family (“tcc”, “gcc”, “cc”, “msvc”, or “unknown”).

Function l0_cli_build._is_windows_host

1
bool l0_cli_build._is_windows_host()

Return whether the current Python host is Windows.

Function l0_cli_build._default_executable_name

1
str l0_cli_build._default_executable_name()

Return the default build output name for the current platform.

Function l0_cli_build._runtime_include_flags

1
list[str] l0_cli_build._runtime_include_flags(str flag_family, str runtime_include)

Return compiler-family-specific runtime include flags.

Function l0_cli_build._runtime_library_flags

1
list[str] l0_cli_build._runtime_library_flags(str flag_family, str runtime_lib)

Return compiler-family-specific runtime library search-path flags.

Function l0_cli_build._output_flags

1
list[str] l0_cli_build._output_flags(str flag_family, Path exe_path)

Return compiler-family-specific output flags.

Function l0_cli_build._validated_temporary_directory

1
Path l0_cli_build._validated_temporary_directory()

Resolve and validate the host temporary directory.

POSIX temporary sources are safe to pass to an external compiler only when every component in the resolved directory hierarchy is owned by root or the effective user. Group- or other-writable components must also carry the sticky bit. Windows relies on the platform temporary directory ACL.

Returns: The resolved temporary directory.

Function l0_cli_build._emit_temporary_source_cleanup_failure

1
None l0_cli_build._emit_temporary_source_cleanup_failure(Path c_path)

Report a compiler-temporary source retained after failed cleanup.

Parameters:

  • c_path: Retained temporary generated-C path.

    Function l0_cli_build._remove_temporary_c_source

1
bool l0_cli_build._remove_temporary_c_source(Path c_path)

Remove a generated-C temporary and report retained recovery state.

Parameters:

  • c_path: Temporary generated-C path to remove.

Returns: True when the path is absent after cleanup, otherwise False.

Function l0_cli_build._write_temporary_c_source

1
Path l0_cli_build._write_temporary_c_source(str c_code)

Atomically create and write one anonymous generated-C source.

The returned descriptor reserves the path before any generated content is written. Writing through that descriptor avoids reopening an attacker- substituted path between selection and creation.

Parameters:

  • c_code: Generated C source text.

Returns: The temporary source path, closed and ready for the host compiler.

Function l0_cli_build._check_entry_main_for_build

1
bool l0_cli_build._check_entry_main_for_build(AnalysisResult result, str entry_name)

Check that the entry module defines a valid ‘main’ function for build/run.

Parameters:

  • result: The analysis result.
  • entry_name: The name of the entry module.

Returns: True if a valid ‘main’ function is found, False otherwise.

Function l0_cli_build._validate_runtime_library_path

1
bool l0_cli_build._validate_runtime_library_path(str runtime_lib_path)

Validate that the provided runtime library path exists and is a directory.

Parameters:

  • runtime_lib_path: Path to the runtime library directory.

Returns: True if the path is a directory, False otherwise.

Function l0_cli_build._split_c_options

1
list[str] l0_cli_build._split_c_options(str|None raw_options)

Split a raw C options string into individual compiler arguments.

Parameters:

  • raw_options: Raw options string, or None.

Returns: A list of whitespace-delimited compiler option tokens.

Function l0_cli_build._get_optimize_flag

1
str | None l0_cli_build._get_optimize_flag(str flag_family, list[str] extra_opts)

Determine the appropriate optimization flag for the compiler family.

Parameters:

  • flag_family: The detected compiler family string.
  • extra_opts: List of extra C compiler options.

Returns: The optimization flag string (e.g., ‘-O1’) or None if no suitable flag is found or if the user provided explicit optimization flags.

Function l0_cli_build._compile_generated_c

1
int l0_cli_build._compile_generated_c(argparse.Namespace args, CompilationContext context, Path c_path, Path exe_path)

Invoke the selected host compiler for one generated-C source.

Parameters:

  • args: Parsed build arguments.
  • context: Active compiler context.
  • c_path: Closed generated-C source path.
  • exe_path: Requested executable output path.

Returns: Zero when the host compiler succeeds, otherwise one.

Function l0_cli_build.cmd_build

1
int l0_cli_build.cmd_build(argparse.Namespace args)

Build an executable from an L0 module.

Parameters:

  • args: Parsed command-line arguments.

Returns: Exit code (0 for success, non-zero for failure).

Function l0_cli_build.cmd_run

1
int l0_cli_build.cmd_run(argparse.Namespace args)

Build and run an L0 module.

Parameters:

  • args: Parsed command-line arguments.

Returns: Exit code from the executed program or the build process.

Class l0_cli_build::_TemporarySourceWriteError

Report a generated-C write failure that also retained its path.

Member Data l0_cli_build._TemporarySourceWriteError.retained_path

1
l0_cli_build._TemporarySourceWriteError::retained_path

Function l0_cli_build._TemporarySourceWriteError.__init__

1
l0_cli_build._TemporarySourceWriteError.__init__(self, Path retained_path)

Initialize the failure.

Parameters:

  • retained_path: Temporary generated-C path that could not be removed.