]> granicus.if.org Git - graphviz/commitdiff
port windows/bin/build.ps1 to Python
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 2 May 2021 16:45:44 +0000 (09:45 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 8 May 2021 18:28:08 +0000 (11:28 -0700)
This is a first step to moving away from PowerShell for CI scripts. PowerShell
has too many error prone characteristics and there is not enough knowledge about
it amongst the Graphviz maintainers.

ci/build_windows.py [new file with mode: 0644]

diff --git a/ci/build_windows.py b/ci/build_windows.py
new file mode 100644 (file)
index 0000000..387d29e
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+
+"""Graphviz CI script for compilation on Windows"""
+
+import argparse
+import os
+from pathlib import Path
+import shutil
+import subprocess
+import sys
+from typing import List
+
+def run(args: List[str], cwd: Path): #pylint: disable=C0116
+  print(f"+ {' '.join(str(x) for x in args)}")
+  subprocess.check_call(args, cwd=cwd)
+
+def main(args: List[str]) -> int: #pylint: disable=C0116
+
+  parser = argparse.ArgumentParser(description="Graphviz CI script for "
+                                   "compilation on Windows")
+  parser.add_argument("--build-system", choices=("cmake", "msbuild"),
+                      required=True, help="build system to run")
+  parser.add_argument("--configuration", choices=("Debug", "Release"),
+                      required=True, help="build configuration to select")
+  parser.add_argument("--platform", choices=("Win32", "x64"),
+                      required=True, help="target platform")
+  options = parser.parse_args(args[1:])
+
+  # find the repository root directory
+  root = Path(__file__).resolve().parent.parent
+
+  if options.build_system == "cmake":
+    build = root / "build"
+    if build.exists():
+      shutil.rmtree(build)
+    os.makedirs(build)
+    run(["cmake", "-G", "Visual Studio 16 2019", "-A", options.platform, ".."],
+        build)
+    run(["cmake", "--build", ".", "--config", options.configuration], build)
+    run(["cpack", "-C", options.configuration], build)
+
+  else:
+    run(["msbuild.exe", f"-p:Configuration={options.configuration}",
+         f"-p:Platform={options.platform}", "graphviz.sln"], root)
+    if options.configuration == "Release":
+      for filename in os.listdir(root / "Release" / "Graphviz" / "bin"):
+        src = root / "Release" / "Graphviz" / "bin" / filename
+        if src.suffix in (".lastcodeanalysissucceeded", ".iobj", ".ipdb",
+                          ".ilk"):
+          print(f"deleting {src}")
+          src.unlink()
+
+  return 0
+
+if __name__ == "__main__":
+  sys.exit(main(sys.argv))