Skip to content

Commit

Permalink
WIP for creating mac osx bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
sebradloff committed Jul 1, 2020
1 parent ab9814d commit 8f89bee
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 18 deletions.
7 changes: 4 additions & 3 deletions kapitan/dependency_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ def fetch_helm_chart(dep_mapping, save_dir):

def initialise_helm_fetch_binding():
"""returns the dl_opened library (.so file) if exists, otherwise None"""
if platform.system() not in ("Linux", "Darwin"): # TODO: later add binding for Mac
if platform.system() not in ("Linux", "Darwin"):
return None
# binding_path is kapitan/dependency_manager/helm/helm_fetch.so
binding_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "helm/helm_fetch.so")
# binding_path is kapitan/inputs/helm/helm_fetch_<platform.system()>.so
binding_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"helm/helm_fetch_{}.so".format(platform.system()))
if not os.path.exists(binding_path):
logger.debug("The helm_fetch binding does not exist at {}".format(binding_path))
return None
Expand Down
15 changes: 13 additions & 2 deletions kapitan/dependency_manager/helm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ set -euo pipefail
cd $(dirname "$0")
pwd

so_name="helm_fetch.so"
# append platform name to the .so file name, corresponding to python's platform.system()
if [[ "$OSTYPE" == "linux-gnu" ]]; then
os_suffix="Linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
os_suffix="Darwin"
fi

so_name="helm_fetch_$os_suffix.so"

# Compile the binding if a Go runtime exists
if [[ -z $(which go) ]]; then
echo "[WARN] go is not available on this system -- skipping Helm binding build!"
else
go build -buildmode=c-shared -o $so_name helm_fetch.go
if [[ "$os_suffix" == "Linux" ]]; then
GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -o $so_name helm_fetch.go
elif [[ "$os_suffix" == "Darwin" ]]; then
GOOS=darwin GOARCH=amd64 go build -buildmode=c-shared -o $so_name helm_fetch.go
fi
fi

# Validate that the compiled binding exists
Expand Down
7 changes: 4 additions & 3 deletions kapitan/inputs/helm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ def __init__(self, compile_path, search_paths, ref_controller):

def initialise_binding(self):
"""returns the dl_opened library (.so file) if exists, otherwise None"""
if platform.system() not in ("Linux", "Darwin"): # TODO: later add binding for Mac
if platform.system() not in ("Linux", "Darwin"):
return None
# binding_path is kapitan/inputs/helm/libtemplate.so
binding_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libtemplate.so")
# binding_path is kapitan/inputs/helm/libtemplate_<platform.system()>.so
binding_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"libtemplate_{}.so".format(platform.system()))
if not os.path.exists(binding_path):
logger.debug("The helm binding does not exist at {}".format(binding_path))
return None
Expand Down
15 changes: 13 additions & 2 deletions kapitan/inputs/helm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
cd $(dirname "$0")
pwd

so_name="libtemplate.so"
# append platform name to the .so file name, corresponding to python's platform.system()
if [[ "$OSTYPE" == "linux-gnu" ]]; then
os_suffix="Linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
os_suffix="Darwin"
fi

so_name="libtemplate_$os_suffix.so"

# Compile the binding if a Go runtime exists
if [[ -z $(which go) ]]; then
echo "[WARN] go is not available on this system -- skipping Helm binding build!"
else
go build -buildmode=c-shared -o $so_name template.go
if [[ "$os_suffix" == "Linux" ]]; then
GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -o $so_name template.go
elif [[ "$os_suffix" == "Darwin" ]]; then
GOOS=darwin GOARCH=amd64 go build -buildmode=c-shared -o $so_name template.go
fi
fi

# Validate that the compiled binding exists
Expand Down
4 changes: 2 additions & 2 deletions kapitan/inputs/helm/helm_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

ffi = _cffi_backend.FFI('helm_binding',
_version = 0x2601,
_types = b'\x00\x00\x01\x0D\x00\x00\x0B\x03\x00\x00\x01\x11\x00\x00\x01\x11\x00\x00\x01\x11\x00\x00\x01\x11\x00\x00\x01\x11\x00\x00\x00\x0F\x00\x00\x0C\x0D\x00\x00\x0C\x03\x00\x00\x00\x0F\x00\x00\x02\x01\x00\x00\x00\x01',
_globals = (b'\x00\x00\x08\x23free',0,b'\x00\x00\x00\x23renderChart',0),
_types = b'\x00\x00\x01\x0D\x00\x00\x0D\x03\x00\x00\x01\x11\x00\x00\x01\x11\x00\x00\x01\x11\x00\x00\x01\x11\x00\x00\x01\x11\x00\x00\x01\x03\x00\x00\x07\x01\x00\x00\x00\x0F\x00\x00\x0E\x0D\x00\x00\x0E\x03\x00\x00\x00\x0F\x00\x00\x02\x01\x00\x00\x00\x01',
_globals = (b'\x00\x00\x0A\x23free',0,b'\x00\x00\x00\x23renderChart',0),
)
9 changes: 9 additions & 0 deletions scripts/build-mac-osx-binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -euo pipefail

# install pip dependencies

# pip3 install pyinstaller

# bash scripts/pyinstaller.sh
20 changes: 14 additions & 6 deletions scripts/pyinstaller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@

set -e

if [[ "$OSTYPE" == "linux-gnu" ]]; then
os_suffix="Linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
os_suffix="Darwin"
fi

lc_os=$(echo $os_suffix | sed 's/./\L&/g')

entry='__main__'
output_name='kapitan-linux-amd64'
output_name="kapitan-$lc_os-amd64"
pyi-makespec kapitan/"$entry".py --onefile \
--add-data kapitan/reclass/reclass:reclass \
--add-data kapitan/lib:kapitan/lib \
--add-data kapitan/inputs/templates:kapitan/inputs/templates \
--add-data kapitan/inputs/helm/libtemplate.so:kapitan/inputs/helm \
--add-data kapitan/dependency_manager/helm/helm_fetch.so:kapitan/dependency_manager/helm \
--add-data "kapitan/reclass/reclass:reclass" \
--add-data "kapitan/lib:kapitan/lib" \
--add-data "kapitan/inputs/templates:kapitan/inputs/templates" \
--add-data "kapitan/inputs/helm/libtemplate_$os_suffix.so:kapitan/inputs/helm" \
--add-data "kapitan/dependency_manager/helm/helm_fetch_$os_suffix.so:kapitan/dependency_manager/helm" \
--hidden-import pyparsing --hidden-import jsonschema \
--exclude-module doctest --exclude-module pydoc
pyinstaller "$entry".spec --clean
Expand Down

0 comments on commit 8f89bee

Please sign in to comment.