Change all the schemata to not allow additional properties. This
should help with misspelled properties as well as missing schema
information in the stage itself.
Done via a small python3 script:
--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---
import os
import sys
def list_stages(base):
return [(base, f) for f in os.listdir(base) if f.startswith("org.osbuild")]
stages = list_stages("stages")
stages += list_stages("assemblers")
def find_line(lines, start):
for i, l in enumerate(lines):
if l.startswith(start):
return i
return None
NOADD = '"additionalProperties": false'
for stage in stages:
with open(f"{stage[0]}/{stage[1]}", "r") as f:
print(f"{stage[0]}/{stage[1]}", file=sys.stderr)
data = f.readlines()
i = find_line(data, 'STAGE_OPTS = """')
if i:
data.insert(i+1, NOADD + ",\n")
else:
i = find_line(data, 'STAGE_OPTS = ""')
if i:
data[i] = f'STAGE_OPTS = """\n'
data.insert(i+1, NOADD + "\n")
data.insert(i+2, '"""\n')
with open(f"{stage[0]}/{stage[1]}", "w") as f:
f.writelines(data)
79 lines
2 KiB
Python
Executable file
79 lines
2 KiB
Python
Executable file
#!/usr/bin/python3
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
|
|
STAGE_DESC = "Assemble a tar archive"
|
|
STAGE_INFO = """
|
|
Assembles the tree into a tar archive named `filename`.
|
|
|
|
Uses the buildhost's `tar` command, like: `tar -cf $FILENAME -C $TREE`
|
|
|
|
If the `compression` option is given, the archive will be compressed by passing
|
|
the `--{compression}` option to `tar`. (This option is non-standard and might
|
|
not work for anything other than GNU tar.)
|
|
|
|
Known options for `compression`: "bzip2", "xz", "lzip", "lzma", "lzop", "gzip".
|
|
|
|
Note that using `compression` does not add an extension to `filename`, so the
|
|
caller is responsible for making sure that `compression` and `filename` match.
|
|
|
|
Buildhost commands used: `tar` and any named `compression` program.
|
|
"""
|
|
STAGE_OPTS = """
|
|
"additionalProperties": false,
|
|
"required": ["filename"],
|
|
"properties": {
|
|
"filename": {
|
|
"description": "Filename for tar archive",
|
|
"type": "string"
|
|
},
|
|
"compression": {
|
|
"description": "Name of compression program",
|
|
"type": "string",
|
|
"enum": ["bzip2", "xz", "lzip", "lzma", "lzop", "gzip"]
|
|
}
|
|
}
|
|
"""
|
|
|
|
def main(tree, output_dir, options):
|
|
filename = options["filename"]
|
|
compression = options.get("compression")
|
|
|
|
extra_args = []
|
|
if compression is not None:
|
|
if compression not in {"bzip2", "xz", "lzip", "lzma", "lzop", "gzip"}:
|
|
return 1
|
|
extra_args.append(f"--{compression}")
|
|
|
|
# Set environment variables for the tar operation.
|
|
tar_env = {
|
|
# Speed up xz by allowing it to use all CPU cores for compression.
|
|
"XZ_OPT": "--threads 0"
|
|
}
|
|
|
|
# Set up the tar command.
|
|
tar_cmd = [
|
|
"tar",
|
|
*extra_args,
|
|
"-cf", f"{output_dir}/{filename}",
|
|
"-C", tree,
|
|
"."
|
|
]
|
|
|
|
# Make a tarball of the tree.
|
|
subprocess.run(
|
|
tar_cmd,
|
|
stdout=subprocess.DEVNULL,
|
|
check=True,
|
|
env=tar_env
|
|
)
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
args = json.load(sys.stdin)
|
|
r = main(args["tree"], args["output_dir"], args["options"])
|
|
sys.exit(r)
|