Skip to content

Commit

Permalink
build: allow to define additional configs
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gave committed Jan 5, 2025
1 parent e0e2e11 commit b81385f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
28 changes: 28 additions & 0 deletions asu/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ def build(build_request: BuildRequest, job=None):
},
)

if build_request.configs:
log.debug("Found extra configs")
configs = ""
for config in build_request.configs:
configs += f"{config}\n"

(bin_dir / ".config_local").write_text(configs)

mounts.append(
{
"type": "bind",
"source": str(bin_dir / ".config_local"),
"target": "/builder/.config_local",
"read_only": True,
}
)

log.debug("Mounts: %s", mounts)

container = podman.containers.create(
Expand Down Expand Up @@ -243,6 +260,17 @@ def build(build_request: BuildRequest, job=None):
packages_hash: str = get_packages_hash(manifest.keys())
log.debug(f"Packages Hash: {packages_hash}")

if build_request.configs:
log.info("Appling local configs")
returncode, job.meta["stdout"], job.meta["stderr"] = run_cmd(
container, ["sh", "-c",
(
"for config in $(grep '#' .config_local | awk '{print $2}'); do sed -i 's/'$config'.*//' .config ; done; cat .config_local >> .config"
)]
)
if returncode:
report_error(job, "Could not apply local configs")

job.meta["build_cmd"] = [
"make",
"image",
Expand Down
17 changes: 17 additions & 0 deletions asu/build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
STRING_PATTERN = r"^[\w.,-]*$"
TARGET_PATTERN = r"^[\w]*/[\w]*$"
PKG_VERSION_PATTERN = r"^[\w.,~-]*$"
CONFIG_PATTERN= r"^(# CONFIG_[\w_.-]+ is not set|CONFIG_[\w_.-]+=([\w_.-]+$|\"[^\"][\w_.-]+\"))$"


class BuildRequest(BaseModel):
Expand Down Expand Up @@ -158,3 +159,19 @@ class BuildRequest(BaseModel):
""".strip(),
),
] = None
configs: Annotated[
list[Annotated[str, Field(pattern=CONFIG_PATTERN)]],
Field(
examples=[[
"CONFIG_VERSION_DIST=MyRouterOS",
"CONFIG_VERSION_NUMBER=1.6",
"CONFIG_TARGET_ROOTFS_TARGZ=y",
"CONFIG_TARGET_ROOTFS_JFFS2=y",
"# CONFIG_TARGET_ROOTFS_SQUASHFS is not set"
]],
description="""
List of configs, only the few ones not related to kernel/packages
as they will not be recompiled.
""".strip(),
),
] = []
13 changes: 13 additions & 0 deletions asu/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ def get_file_hash(path: str) -> str:
return h.hexdigest()


def get_configs_hash(configs: list) -> str:
"""Return sha256sum of configs list
Duplicate configs are automatically removed and the list is sorted to be
reproducible
Args:
configs (list): list of configs
Returns:
str: hash of `req`
"""
return get_str_hash(" ".join(sorted(list(set(configs)))))


def get_manifest_hash(manifest: dict[str, str]) -> str:
"""Return sha256sum of package manifest
Expand Down Expand Up @@ -132,6 +144,7 @@ def get_request_hash(build_request: BuildRequest) -> str:
build_request.target,
build_request.profile.replace(",", "_"),
get_packages_hash(build_request.packages),
get_configs_hash(build_request.configs),
get_manifest_hash(build_request.packages_versions),
str(build_request.diff_packages),
"", # build_request.filesystem
Expand Down

0 comments on commit b81385f

Please sign in to comment.