50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
# build/utils.py
|
|
from pathlib import Path
|
|
import subprocess
|
|
import os
|
|
import shutil
|
|
|
|
|
|
def mkdir(p: Path):
|
|
p.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
def run(cmd, **kwargs):
|
|
print(">>", " ".join(str(c) for c in cmd))
|
|
subprocess.check_call(cmd, **kwargs)
|
|
|
|
|
|
def detect_platform_name():
|
|
import platform
|
|
system = platform.system()
|
|
if system == "Darwin":
|
|
return "macos"
|
|
if system == "Windows":
|
|
return "windows"
|
|
if system == "Linux":
|
|
return "linux"
|
|
return "unknown"
|
|
|
|
|
|
def git_commit_hash():
|
|
try:
|
|
result_hash = subprocess.check_output([
|
|
"git", "describe", "--always", "--dirty", "--abbrev=7"
|
|
], text=True, stderr=subprocess.DEVNULL).strip()
|
|
result_date = subprocess.check_output([
|
|
"git", "show", "-s", "--format=%ci"
|
|
], text=True, stderr=subprocess.DEVNULL).strip()
|
|
return f"{result_hash} {result_date}"
|
|
except Exception:
|
|
return "unknown"
|
|
|
|
|
|
def is_up_to_date(src: Path, obj: Path, dep: Path):
|
|
if "meta" in [src.stem, obj.stem, dep.stem]:
|
|
return False
|
|
if not obj.exists():
|
|
return False
|
|
if dep.exists() and dep.stat().st_mtime > obj.stat().st_mtime:
|
|
return False
|
|
return src.stat().st_mtime < obj.stat().st_mtime
|