Support reproducible XZ Linux archives without changing runtime contents
This commit is contained in:
1 parent
193ab08f62
commit
a8080f061f
4 files changed
+33
-5
No files matched your search
+10
-4
@@ -8,6 +8,7 @@ import gzip
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import lzma
|
||||
import os
|
||||
from pathlib import Path, PurePosixPath
|
||||
import re
|
||||
@@ -169,7 +170,9 @@ def media_files(root, media):
|
||||
return selected
|
||||
|
||||
|
||||
def package(root, executable, runtime, media, output, llama_license=None):
|
||||
def package(root, executable, runtime, media, output, llama_license=None, compression="gzip"):
|
||||
if compression not in {"gzip", "xz"}:
|
||||
raise ValueError("Unsupported package compression")
|
||||
root, executable, runtime, media, output = map(Path, (root, executable, runtime, media, output))
|
||||
regular(executable, executable.parent)
|
||||
elf_x64(executable)
|
||||
@@ -199,7 +202,7 @@ def package(root, executable, runtime, media, output, llama_license=None):
|
||||
temporary_path = Path(temporary.name)
|
||||
try:
|
||||
records = []
|
||||
with temporary_path.open("wb") as raw, gzip.GzipFile(filename="", mode="wb", fileobj=raw, mtime=0) as compressed, tarfile.open(fileobj=compressed, mode="w|") as archive:
|
||||
with temporary_path.open("wb") as raw, (lzma.LZMAFile(raw, "w", preset=6) if compression == "xz" else gzip.GzipFile(filename="", mode="wb", fileobj=raw, mtime=0)) as compressed, tarfile.open(fileobj=compressed, mode="w|") as archive:
|
||||
for name, (path, expected_record) in sorted(selected.items()):
|
||||
safe_name(name)
|
||||
regular(path, path.parent)
|
||||
@@ -249,9 +252,12 @@ def main():
|
||||
parser.add_argument("--runtime", type=Path, default=ROOT / ".searchi/runtime/auto")
|
||||
parser.add_argument("--media", type=Path, default=ROOT / ".searchi/media-runtime")
|
||||
parser.add_argument("--llama-license", type=Path)
|
||||
parser.add_argument("--output", type=Path, default=ROOT / ".searchi/packages/searchi-linux-x86_64.tar.gz")
|
||||
parser.add_argument("--compression", choices=["gzip", "xz"], default="gzip")
|
||||
parser.add_argument("--output", type=Path)
|
||||
args = parser.parse_args()
|
||||
package(ROOT, args.executable, args.runtime, args.media, args.output, args.llama_license)
|
||||
if args.output is None:
|
||||
args.output = ROOT / (".searchi/packages/searchi-linux-x86_64.tar.xz" if args.compression == "xz" else ".searchi/packages/searchi-linux-x86_64.tar.gz")
|
||||
package(ROOT, args.executable, args.runtime, args.media, args.output, args.llama_license, args.compression)
|
||||
print(f"Packaged Linux x86_64 development candidate: {args.output}")
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user