feat: create omrf packer basic layout
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
from .archiver import pack
|
||||
from .cargo import get_artifacts
|
||||
from .cli import Cli, parse
|
||||
from .cmake import render as render_cmake
|
||||
from .pkgconfig import render as render_pkgconfig
|
||||
|
||||
|
||||
def main() -> None:
|
||||
cli = parse()
|
||||
get_artifacts(cli.manifest_path)
|
||||
render_cmake(cli.output_dir)
|
||||
render_pkgconfig(cli.output_dir)
|
||||
pack(cli.output_dir, cli.output_dir + ".zip")
|
||||
@@ -0,0 +1,10 @@
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def pack(dist_dir: str, output_zip: str) -> None:
|
||||
dist = Path(dist_dir)
|
||||
with zipfile.ZipFile(output_zip, "w", zipfile.ZIP_DEFLATED) as zf:
|
||||
for path in dist.rglob("*"):
|
||||
if path.is_file():
|
||||
zf.write(path, path.relative_to(dist))
|
||||
@@ -0,0 +1,22 @@
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
|
||||
def get_metadata(manifest_path: str) -> dict:
|
||||
cmd = [
|
||||
"cargo",
|
||||
"metadata",
|
||||
"--format-version=1",
|
||||
f"--manifest-path={manifest_path}",
|
||||
]
|
||||
proc = subprocess.Popen(
|
||||
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
stdout, _ = proc.communicate()
|
||||
return json.loads(stdout)
|
||||
|
||||
|
||||
def get_artifacts(manifest_path: str) -> list[str]:
|
||||
metadata = get_metadata(manifest_path)
|
||||
target_directory = metadata["target_directory"]
|
||||
return [target_directory]
|
||||
@@ -0,0 +1,19 @@
|
||||
import argparse
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Cli:
|
||||
manifest_path: str
|
||||
output_dir: str
|
||||
|
||||
|
||||
def parse() -> Cli:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="sarasacw-omrf-packer",
|
||||
description="Create distribution and generate CMake and pkg-config files.",
|
||||
)
|
||||
parser.add_argument("--manifest-path", default="Cargo.toml")
|
||||
parser.add_argument("--output-dir", default="dist")
|
||||
args = parser.parse_args()
|
||||
return Cli(manifest_path=args.manifest_path, output_dir=args.output_dir)
|
||||
@@ -0,0 +1,13 @@
|
||||
from pathlib import Path
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
|
||||
|
||||
def render(output_dir: str) -> None:
|
||||
templates_dir = Path(__file__).parent / "templates"
|
||||
env = Environment(
|
||||
loader=FileSystemLoader(templates_dir),
|
||||
autoescape=select_autoescape(),
|
||||
)
|
||||
out = Path(output_dir)
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
@@ -0,0 +1,13 @@
|
||||
from pathlib import Path
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
|
||||
|
||||
def render(output_dir: str) -> None:
|
||||
templates_dir = Path(__file__).parent / "templates"
|
||||
env = Environment(
|
||||
loader=FileSystemLoader(templates_dir),
|
||||
autoescape=select_autoescape(),
|
||||
)
|
||||
out = Path(output_dir)
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
Reference in New Issue
Block a user