l0_cli_build namespace
Classes
- class _TemporarySourceWriteError
- Report a generated-C write failure that also retained its path.
Functions
- auto _find_cc() -> str|None
- Find the best available C compiler.
- _compiler_flag_family(str compiler) protected
- Determine the compiler family for flag selection using a simple heuristic.
- auto _is_windows_host() -> bool
- Return whether the current Python host is Windows.
- auto _default_executable_name() -> str
- Return the default build output name for the current platform.
- auto _runtime_include_flags(str flag_family, str runtime_include) -> list[str]
- Return compiler-family-specific runtime include flags.
- auto _runtime_library_flags(str flag_family, str runtime_lib) -> list[str]
- Return compiler-family-specific runtime library search-path flags.
- auto _output_flags(str flag_family, Path exe_path) -> list[str]
- Return compiler-family-specific output flags.
- auto _validated_temporary_directory() -> Path
- Resolve and validate the host temporary directory.
- auto _emit_temporary_source_cleanup_failure(Path c_path) -> None
- Report a compiler-temporary source retained after failed cleanup.
- auto _remove_temporary_c_source(Path c_path) -> bool
- Remove a generated-C temporary and report retained recovery state.
- auto _write_temporary_c_source(str c_code) -> Path
- Atomically create and write one anonymous generated-C source.
- auto _check_entry_main_for_build(AnalysisResult result, str entry_name) -> bool
- Check that the entry module defines a valid 'main' function for build/run.
- auto _validate_runtime_library_path(str runtime_lib_path) -> bool
- Validate that the provided runtime library path exists and is a directory.
- auto _split_c_options(str|None raw_options) -> list[str]
- Split a raw C options string into individual compiler arguments.
- auto _get_optimize_flag(str flag_family, list extra_opts[str]) -> str|None
- Determine the appropriate optimization flag for the compiler family.
- auto _compile_generated_c(argparse.Namespace args, CompilationContext context, Path c_path, Path exe_path) -> int
- Invoke the selected host compiler for one generated-C source.
- auto cmd_build(argparse.Namespace args) -> int
- Build an executable from an L0 module.
- auto cmd_run(argparse.Namespace args) -> int
- Build and run an L0 module.
Function documentation
str|None l0_ cli_ build:: _find_cc() protected
Find the best available C compiler.
| Returns | The compiler command if found, or None if no compiler is found. |
|---|
Used in codegen and build stages if the user didn't specify one explicitly.
The search order is:
- L0_CC environment variable. 2. Common compiler names in PATH: tcc, gcc, clang, cc (in that order). 3. CC environment variable.
l0_ cli_ build:: _compiler_flag_family(str compiler) protected
Determine the compiler family for flag selection using a simple heuristic.
| Parameters | |
|---|---|
| compiler | The compiler command string. |
| Returns | A string representing the compiler family ("tcc", "gcc", "cc", "msvc", or "unknown"). |
Uses pattern matching to handle cases like "gcc-10" or "clang-14" on Unix and "gcc.exe" or "clang.exe" on Windows.
bool l0_ cli_ build:: _is_windows_host() protected
Return whether the current Python host is Windows.
str l0_ cli_ build:: _default_executable_name() protected
Return the default build output name for the current platform.
list[str] l0_ cli_ build:: _runtime_include_flags(str flag_family,
str runtime_include) protected
Return compiler-family-specific runtime include flags.
list[str] l0_ cli_ build:: _runtime_library_flags(str flag_family,
str runtime_lib) protected
Return compiler-family-specific runtime library search-path flags.
list[str] l0_ cli_ build:: _output_flags(str flag_family,
Path exe_path) protected
Return compiler-family-specific output flags.
Path l0_ cli_ build:: _validated_temporary_directory() protected
Resolve and validate the host temporary directory.
| Returns | The resolved temporary directory. |
|---|---|
| Exceptions | |
| OSError | If the directory cannot be resolved or its POSIX hierarchy is not trusted. |
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.
None l0_ cli_ build:: _emit_temporary_source_cleanup_failure(Path c_path) protected
Report a compiler-temporary source retained after failed cleanup.
| Parameters | |
|---|---|
| c_path | Retained temporary generated-C path. |
bool l0_ cli_ build:: _remove_temporary_c_source(Path c_path) protected
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. |
Path l0_ cli_ build:: _write_temporary_c_source(str c_code) protected
Atomically create and write one anonymous generated-C source.
| Parameters | |
|---|---|
| c_code | Generated C source text. |
| Returns | The temporary source path, closed and ready for the host compiler. |
| Exceptions | |
| OSError | If the path cannot be created or written. |
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.
bool l0_ cli_ build:: _check_entry_main_for_build(AnalysisResult result,
str entry_name) protected
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. |
bool l0_ cli_ build:: _validate_runtime_library_path(str runtime_lib_path) protected
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. |
list[str] l0_ cli_ build:: _split_c_options(str|None raw_options) protected
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. |
str|None l0_ cli_ build:: _get_optimize_flag(str flag_family,
list extra_opts[str]) protected
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. |
int l0_ cli_ build:: _compile_generated_c(argparse.Namespace args,
CompilationContext context,
Path c_path,
Path exe_path) protected
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. |
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). |
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. |