scripts: gen_config: Wrong order of profiles being included by gen_config.py
Problem: Included profiles were processed only after all command-line profiles, which broke the expected recursive include order. Fix: Implement recursive profile loading so each profile processes its own 'includes' before moving to the next CLI profile. Added 'seen' set to avoid duplicates and circular includes. Fixes: PPW-1115 Signed-off-by: Volodymyr Martysh <vmartysh@maxlinear.com>
This commit is contained in:
parent
fd7f2b43cd
commit
add1b5884b
@ -41,14 +41,18 @@ def usage(code: int = 0):
|
||||
quit(code)
|
||||
|
||||
|
||||
def load_yaml(fname: str, profile: dict):
|
||||
def load_yaml(fname: str, profile: dict, seen: set[str]):
|
||||
|
||||
if fname in seen:
|
||||
return profile
|
||||
|
||||
# Allow profile overriding by searching in reverse order
|
||||
for folder in profile_folders.split(':')[::-1]:
|
||||
profile_file = (Path(folder) / fname).with_suffix(".yml")
|
||||
|
||||
if not profile_file.is_file():
|
||||
continue
|
||||
|
||||
includes = []
|
||||
new = yaml.safe_load(profile_file.read_text())
|
||||
for n in new:
|
||||
if n in {"target", "subtarget", "external_target"}:
|
||||
@ -74,15 +78,25 @@ def load_yaml(fname: str, profile: dict):
|
||||
die(f"Found bad additional_packages {f}")
|
||||
profile["additional_packages"].extend(new.get(n))
|
||||
elif n in {"include"}:
|
||||
profile["include"].extend(new.get(n))
|
||||
includes = new.get(n)
|
||||
elif n in {"packages_remove"}:
|
||||
profile["packages_remove"].extend(new.get(n))
|
||||
|
||||
return profile
|
||||
seen.add(fname);
|
||||
|
||||
for inc in includes:
|
||||
(profile, seen) = load_yaml(inc, profile, seen)
|
||||
|
||||
return (profile, seen)
|
||||
|
||||
if not profile_file.is_file():
|
||||
die(f"Profile {fname} not found")
|
||||
|
||||
def load_yaml_list(fnames: [str], profile: dict):
|
||||
seen = set()
|
||||
for fn in fnames:
|
||||
(profile, seen) = load_yaml(fn, profile, seen)
|
||||
return profile
|
||||
|
||||
def extract_sha1_from_revision(revision: str) -> str:
|
||||
"""
|
||||
@ -162,15 +176,11 @@ profile = {
|
||||
"feeds": {},
|
||||
"packages": [],
|
||||
"profiles": [],
|
||||
"include": [],
|
||||
"packages_remove": [],
|
||||
}
|
||||
|
||||
for p in sys.argv[1:]:
|
||||
profile = load_yaml(p, profile)
|
||||
profile = load_yaml_list(sys.argv[1:], profile)
|
||||
|
||||
for p in profile.get("include", []):
|
||||
profile = load_yaml(p, profile)
|
||||
|
||||
if getenv("GENCONFIG_VERBOSE"):
|
||||
print(yaml.dump(profile))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user