56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
from typing import cast
|
|
from script_common import ensure_dotnet_publish, find_csproj_by_keyword, resolve_repo_root, SdtResult
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Cross-platform .NET sidecar publish helper")
|
|
_ = parser.add_argument("--configuration", default="Release")
|
|
_ = parser.add_argument("--runtime", default="win-x64")
|
|
_ = parser.add_argument("--repo-root", default=None)
|
|
_ = parser.add_argument("--project", default=None, help="Relative/absolute path to sidecar csproj")
|
|
_ = parser.add_argument("--output-dir", default="output")
|
|
args = parser.parse_args()
|
|
|
|
repo_root_val = cast(str | None, args.repo_root)
|
|
repo_root = resolve_repo_root(repo_root_val)
|
|
output_dir_val = cast(str, args.output_dir)
|
|
output_dir = (repo_root / output_dir_val).resolve()
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
project_val = cast(str | None, args.project)
|
|
if project_val:
|
|
csproj = (repo_root / project_val).resolve()
|
|
else:
|
|
csproj = find_csproj_by_keyword(repo_root, ["sidecar"])
|
|
|
|
if csproj is None or not csproj.exists():
|
|
print("Could not locate sidecar project. Pass --project <path/to/project.csproj>.")
|
|
return 2
|
|
|
|
res: SdtResult = ensure_dotnet_publish(
|
|
csproj=csproj,
|
|
output_dir=output_dir,
|
|
configuration=str(args.configuration),
|
|
runtime=str(args.runtime),
|
|
single_file=True,
|
|
self_contained=True
|
|
)
|
|
|
|
if res["exit_code"] != 0:
|
|
return int(res["exit_code"])
|
|
|
|
runtime_val = str(args.runtime)
|
|
binary_name = csproj.stem + (".exe" if runtime_val.startswith("win-") else "")
|
|
binary_path = output_dir / binary_name
|
|
if binary_path.exists():
|
|
print(f"Published executable: {binary_path}")
|
|
else:
|
|
print(f"Publish completed. Output directory: {output_dir}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|