return mount_overlay([state.root], state.workspace / "build-overlay", state.root, read_only)
+def finalize_sources(config: MkosiConfig) -> list[tuple[Path, Path]]:
+ sources = [
+ (src, Path("work/src") / (str(target).lstrip("/") if target else "."))
+ for src, target
+ in config.build_sources
+ ]
+
+ return sorted(sources, key=lambda s: s[1])
+
+
def run_prepare_script(state: MkosiState, build: bool) -> None:
if state.config.prepare_script is None:
return
return
bwrap: list[PathString] = [
- "--bind", state.config.build_sources, "/work/src",
"--bind", state.config.prepare_script, "/work/prepare",
"--chdir", "/work/src",
]
+ for src, target in finalize_sources(state.config):
+ bwrap += ["--bind", src, Path("/") / target]
+
if build:
with complete_step("Running prepare script in build overlay…"), mount_build_overlay(state):
run_workspace_command(
Clean Package Metadata: {yes_no_auto(config.clean_package_metadata)}
Remove Files: {line_join_list(config.remove_files)}
Remove Packages: {line_join_list(config.remove_packages)}
- Build Sources: {config.build_sources}
+ Build Sources: {line_join_source_target_list(config.build_sources)}
Build Packages: {line_join_list(config.build_packages)}
Build Script: {path_or_none(config.build_script, check_script_input)}
Run Tests in Build Script: {yes_no(config.with_tests)}
with complete_step("Running build script…"), mount_build_overlay(state, read_only=True):
bwrap: list[PathString] = [
- "--bind", state.config.build_sources, "/work/src",
"--bind", state.config.build_script, "/work/build-script",
"--bind", state.install_dir, "/work/dest",
"--bind", state.staging, "/work/out",
"--chdir", "/work/src",
]
+ for src, target in finalize_sources(state.config):
+ bwrap += ["--bind", src, Path("/") / target]
+
env = dict(
WITH_DOCS=one_zero(state.config.with_docs),
WITH_TESTS=one_zero(state.config.with_tests),
return path
-def parse_source_target_paths(value: str) -> tuple[Path, Optional[Path]]:
- src, sep, target = value.partition(':')
- src_path = parse_path(src, required=False)
- if sep:
- target_path = parse_path(target, required=False, absolute=False, expanduser=False)
- if not target_path.is_absolute():
- die("Target path must be absolute")
- else:
- target_path = None
- return src_path, target_path
+def make_source_target_paths_parser(absolute: bool = True) -> Callable[[str], tuple[Path, Optional[Path]]]:
+ def parse_source_target_paths(value: str) -> tuple[Path, Optional[Path]]:
+ src, sep, target = value.partition(':')
+ src_path = parse_path(src, required=False)
+ if sep:
+ target_path = parse_path(target, required=False, absolute=False, expanduser=False)
+ if absolute and not target_path.is_absolute():
+ die("Target path must be absolute")
+ else:
+ target_path = None
+ return src_path, target_path
+
+ return parse_source_target_paths
def config_parse_string(dest: str, value: Optional[str], namespace: argparse.Namespace) -> Optional[str]:
clean_package_metadata: ConfigFeature
remove_files: list[str]
environment: dict[str, str]
- build_sources: Path
+ build_sources: list[tuple[Path, Optional[Path]]]
build_dir: Optional[Path]
build_packages: list[str]
build_script: Optional[Path]
long="--extra-tree",
metavar="PATH",
section="Content",
- parse=config_make_list_parser(delimiter=",", parse=parse_source_target_paths),
+ parse=config_make_list_parser(delimiter=",", parse=make_source_target_paths_parser()),
paths=("mkosi.extra", "mkosi.extra.tar"),
help="Copy an extra tree on top of image",
),
long="--skeleton-tree",
metavar="PATH",
section="Content",
- parse=config_make_list_parser(delimiter=",", parse=parse_source_target_paths),
+ parse=config_make_list_parser(delimiter=",", parse=make_source_target_paths_parser()),
paths=("mkosi.skeleton", "mkosi.skeleton.tar"),
help="Use a skeleton tree to bootstrap the image before installing anything",
),
long="--package-manager-tree",
metavar="PATH",
section="Content",
- parse=config_make_list_parser(delimiter=",", parse=parse_source_target_paths),
+ parse=config_make_list_parser(delimiter=",", parse=make_source_target_paths_parser()),
default_factory=config_default_package_manager_tree,
help="Use a package manager tree to configure the package manager",
),
dest="build_sources",
metavar="PATH",
section="Content",
- parse=config_make_path_parser(),
- default=Path("."),
+ parse=config_make_list_parser(delimiter=",", parse=make_source_target_paths_parser(absolute=False)),
+ default=[(Path("."), None)],
help="Path for sources to build",
),
MkosiConfigSetting(