From 614f54e0f4549da45ebe212ae83862ce9c0b15bf Mon Sep 17 00:00:00 2001
From: Moritz Maxeiner <mm@ucw.sh>
Date: Tue, 16 Feb 2021 17:34:18 +0100
Subject: [PATCH] [ci] add macos support

---
 .gitlab-ci.yml       | 55 ++++++++++++++++++++++++++++++++++++++++++++
 ci/prepare.py        |  2 ++
 python/ci/build.py   |  7 ++++--
 python/ci/package.py |  2 +-
 python/ci/test.py    |  4 ++--
 5 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 358ed14..52547c6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,6 +11,9 @@ stages:
   tags: [linux, docker]
   image: git.imp.fu-berlin.de:5000/bioroboticslab/auto/ci/centos:latest
 
+.macos:
+  tags: [macos, shell]
+
 .windows:
   tags: [windows, docker]
   image: git.imp.fu-berlin.de:5000/bioroboticslab/auto/ci/windows:latest-devel
@@ -59,6 +62,10 @@ stages:
   extends: .centos
   <<: *build_cpp
 
+"build cpp: [macos]":
+  extends: .macos
+  <<: *build_cpp
+
 "build cpp: [windows]":
   extends: .windows
   <<: *build_cpp
@@ -81,6 +88,24 @@ stages:
   variables:
     <<: [*python39]
 
+"build python: [macos, 3.7]":
+  extends: .macos
+  <<: *build_python
+  variables:
+    <<: [*python37]
+
+"build python: [macos, 3.8]":
+  extends: .macos
+  <<: *build_python
+  variables:
+    <<: [*python38]
+
+"build python: [macos, 3.9]":
+  extends: .macos
+  <<: *build_python
+  variables:
+    <<: [*python39]
+
 "build python: [windows, 3.7]":
   extends: .windows
   <<: *build_python
@@ -128,6 +153,12 @@ stages:
     - "build cpp: [centos]"
   <<: *package_cpp
 
+"package cpp: [macos]":
+  extends: .macos
+  dependencies:
+    - "build cpp: [macos]"
+  <<: *package_cpp
+
 "package cpp: [windows]":
   extends: .windows
   dependencies:
@@ -152,6 +183,24 @@ stages:
     - "build python: [centos, 3.9]"
   <<: *package_python
 
+"package python: [macos, 3.7]":
+  extends: .macos
+  dependencies:
+    - "build python: [macos, 3.7]"
+  <<: *package_python
+
+"package python: [macos, 3.8]":
+  extends: .macos
+  dependencies:
+    - "build python: [macos, 3.8]"
+  <<: *package_python
+
+"package python: [macos, 3.9]":
+  extends: .macos
+  dependencies:
+    - "build python: [macos, 3.9]"
+  <<: *package_python
+
 "package python: [windows, 3.7]":
   extends: .windows
   dependencies:
@@ -181,6 +230,9 @@ deploy python to staging:
     - "package python: [centos, 3.7]"
     - "package python: [centos, 3.8]"
     - "package python: [centos, 3.9]"
+    - "package python: [macos, 3.7]"
+    - "package python: [macos, 3.8]"
+    - "package python: [macos, 3.9]"
     - "package python: [windows, 3.7]"
     - "package python: [windows, 3.8]"
     - "package python: [windows, 3.9]"
@@ -196,6 +248,9 @@ deploy python to production:
     - "package python: [centos, 3.7]"
     - "package python: [centos, 3.8]"
     - "package python: [centos, 3.9]"
+    - "package python: [macos, 3.7]"
+    - "package python: [macos, 3.8]"
+    - "package python: [macos, 3.9]"
     - "package python: [windows, 3.7]"
     - "package python: [windows, 3.8]"
     - "package python: [windows, 3.9]"
diff --git a/ci/prepare.py b/ci/prepare.py
index 814c552..6f7336e 100755
--- a/ci/prepare.py
+++ b/ci/prepare.py
@@ -48,6 +48,8 @@ if __name__ == "__main__":
         os_name = "windows"
     elif system() == "Linux":
         os_name = "centos"
+    elif system() == "Darwin":
+        os_name = "macos"
     else:
         assert False
 
diff --git a/python/ci/build.py b/python/ci/build.py
index 3a82357..342f3ad 100755
--- a/python/ci/build.py
+++ b/python/ci/build.py
@@ -11,7 +11,7 @@ from shutil import which
 def python_executable():
     if system() == "Windows":
         return f"/Python{''.join(env['PYTHON_VERSION'].split('.'))}/python.exe"
-    elif system() == "Linux":
+    elif system() == "Linux" or system() == "Darwin":
         return which(f"python{env['PYTHON_VERSION']}")
     assert False
 
@@ -28,10 +28,13 @@ if __name__ == "__main__":
             "gmpxx.so.4",
             "mpfr.so.4",
         ]
+    elif system() == "Darwin":
+        shared_libraries = []
     else:
         assert False
 
-    env["INSTALL_SHARED_LIBRARIES"] = ";".join(shared_libraries)
+    if len(shared_libraries) > 0:
+        env["INSTALL_SHARED_LIBRARIES"] = ";".join(shared_libraries)
 
     env["CMAKE_PREFIX_PATH"] = str(Path("vendor").resolve())
     env["CMAKE_GENERATOR"] = "Ninja"
diff --git a/python/ci/package.py b/python/ci/package.py
index 5d327a1..fc3937e 100755
--- a/python/ci/package.py
+++ b/python/ci/package.py
@@ -11,7 +11,7 @@ from shutil import which
 def python_executable():
     if system() == "Windows":
         return f"/Python{''.join(env['PYTHON_VERSION'].split('.'))}/python.exe"
-    elif system() == "Linux":
+    elif system() == "Linux" or system() == "Darwin":
         return which(f"python{env['PYTHON_VERSION']}")
     assert False
 
diff --git a/python/ci/test.py b/python/ci/test.py
index 6b70a71..f304e4e 100755
--- a/python/ci/test.py
+++ b/python/ci/test.py
@@ -11,7 +11,7 @@ from shutil import which
 def python_executable():
     if system() == "Windows":
         return f"/Python{''.join(env['PYTHON_VERSION'].split('.'))}/python.exe"
-    elif system() == "Linux":
+    elif system() == "Linux" or system() == "Darwin":
         return which(f"python{env['PYTHON_VERSION']}")
     assert False
 
@@ -19,7 +19,7 @@ def python_executable():
 def python_venv_executable():
     if system() == "Windows":
         return str(Path("python/.venv/Scripts/python.exe").resolve())
-    elif system() == "Linux":
+    elif system() == "Linux" or system() == "Darwin":
         return str(Path("python/.venv/bin/python").resolve())
     assert False
 
-- 
GitLab