Skip to content

Commit

Permalink
Merge pull request #97 from salopensource/apple_silicon
Browse files Browse the repository at this point in the history
Apple silicon
  • Loading branch information
grahamgilbert authored Nov 12, 2021
2 parents 6dda3ee + 6fb6280 commit e7bab64
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 31 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/build_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Build Package
# name: Build Package

on: push
# on: push

jobs:
build_pkg:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v1
# - name: Install Luggage
# run: |
# mkdir -p /usr/local/share/luggage
# cp luggage/luggage.make /usr/local/share/luggage/luggage.make
# cp luggage/prototype.plist /usr/local/share/luggage/prototype.plist
- name: make pkg
run: |
sudo make pkg
# jobs:
# build_pkg:
# runs-on: macos-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v1
# # - name: Install Luggage
# # run: |
# # mkdir -p /usr/local/share/luggage
# # cp luggage/luggage.make /usr/local/share/luggage/luggage.make
# # cp luggage/prototype.plist /usr/local/share/luggage/prototype.plist
# - name: make pkg
# run: |
# sudo make pkg
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ report_broken_client/report_broken_client.xcodeproj/xcuserdata/*
vendor/
report_broken_client/build

.vscode/
.vscode/
config.mk
entitlements.plist
25 changes: 23 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
USE_PKGBUILD=1
include luggage/luggage.make
include config.mk
PACKAGE_VERSION:=$(shell sed -n -e '/^__version__/p' sal_python_pkg/sal/version.py | cut -d "\"" -f 2)
PB_EXTRA_ARGS+= --sign "${DEV_INSTALL_CERT}"
.PHONY: remove-xattrs sign clean-build
TITLE=sal_scripts
PACKAGE_NAME=sal_scripts
REVERSE_DOMAIN=com.github.salopensource
Expand All @@ -11,9 +14,12 @@ PAYLOAD=\
pack-Library-LaunchDaemons-com.salopensource.sal.runner.plist \
pack-Library-LaunchDaemons-com.salopensource.sal.random.runner.plist \
pack-script-postinstall \
pack-python
pack-python \
remove-xattrs \
sign

clean-build:
killall Dropbox || true
@sudo rm -rf report_broken_client/build

pack-report-broken-client: pack-sal-scripts clean-build
Expand Down Expand Up @@ -46,4 +52,19 @@ build-python:
@rm -rf "${PYTHONTOOLDIR}"
@git clone https://github.com/gregneagle/relocatable-python.git "${PYTHONTOOLDIR}"
@./build_python_framework.sh
@find ./Python.framework -name '*.pyc' -delete
@find ./Python.framework -name '*.pyc' -delete

sign: remove-xattrs
@sudo ./sign_python_framework.py -v -S "${DEV_APP_CERT}"

remove-xattrs:
@sudo xattr -rd com.dropbox.attributes ${WORK_D}
@sudo xattr -rd com.dropbox.internal ${WORK_D}
@sudo xattr -rd com.apple.ResourceFork ${WORK_D}
@sudo xattr -rd com.apple.FinderInfo ${WORK_D}
@sudo xattr -rd com.apple.metadata:_kMDItemUserTags ${WORK_D}
@sudo xattr -rd com.apple.metadata:kMDItemFinderComment ${WORK_D}
@sudo xattr -rd com.apple.metadata:kMDItemOMUserTagTime ${WORK_D}
@sudo xattr -rd com.apple.metadata:kMDItemOMUserTags ${WORK_D}
@sudo xattr -rd com.apple.metadata:kMDItemStarRating ${WORK_D}
@sudo xattr -rd com.dropbox.ignored ${WORK_D}
30 changes: 28 additions & 2 deletions build_python_framework.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
#!/bin/zsh
# Build script for Python 3 framework for Sal scripts
TOOLSDIR=$(dirname "$0")
PYTHON_VERSION=3.8.5
PYTHON_VERSION=3.9.7

# build the framework
/tmp/relocatable-python-git/make_relocatable_python_framework.py \
--python-version "${PYTHON_VERSION}" \
--pip-requirements requirements.txt \
--destination "${TOOLSDIR}"
--destination "${TOOLSDIR}" \
--os-version "11" \
--upgrade-pip

# Stolen with love from https://github.com/macadmins/python/blob/main/build_python_framework_pkgs.zsh
TOTAL_DYLIB=$(/usr/bin/find "${TOOLSDIR}/Python.framework/Versions/Current/lib" -name "*.dylib" | /usr/bin/wc -l | /usr/bin/xargs)
UNIVERSAL_DYLIB=$(/usr/bin/find "${TOOLSDIR}/Python.framework/Versions/Current/lib" -name "*.dylib" | /usr/bin/xargs file | /usr/bin/grep "2 architectures" | /usr/bin/wc -l | /usr/bin/xargs)
if [ "${TOTAL_DYLIB}" != "${UNIVERSAL_DYLIB}" ] ; then
echo "Dynamic Libraries do not match, resulting in a non-universal Python framework."
echo "Total Dynamic Libraries found: ${TOTAL_DYLIB}"
echo "Universal Dynamic Libraries found: ${UNIVERSAL_DYLIB}"
exit 1
fi

echo "Dynamic Libraries are confirmed as universal"

TOTAL_SO=$(/usr/bin/find "${TOOLSDIR}/Python.framework/Versions/Current/lib" -name "*.so" | /usr/bin/wc -l | /usr/bin/xargs)
UNIVERSAL_SO=$(/usr/bin/find "${TOOLSDIR}/Python.framework/Versions/Current/lib" -name "*.so" | /usr/bin/xargs file | /usr/bin/grep "2 architectures" | /usr/bin/wc -l | /usr/bin/xargs)
if [ "${TOTAL_SO}" != "${UNIVERSAL_SO}" ] ; then
echo "Shared objects do not match, resulting in a non-universal Python framework."
echo "Total shared objects found: ${TOTAL_SO}"
echo "Universal shared objects found: ${UNIVERSAL_SO}"
UNIVERSAL_SO_ARRAY=("${(@f)$(/usr/bin/find "${TOOLSDIR}/Python.framework/Versions/Current/lib" -name "*.so" | /usr/bin/xargs file | /usr/bin/grep "2 architectures" | awk '{print $1;}' | sed 's/:*$//g')}")
TOTAL_SO_ARRAY=("${(@f)$(/usr/bin/find "${TOOLSDIR}/Python.framework/Versions/Current/lib" -name "*.so" )}")
echo ${TOTAL_SO_ARRAY[@]} ${UNIVERSAL_SO_ARRAY[@]} | tr ' ' '\n' | sort | uniq -u
exit 1
fi
27 changes: 22 additions & 5 deletions payload/usr/local/sal/checkin_modules/machine_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ def process_system_profile():
"machine_model"
]

udid = system_profile["SPHardwareDataType"][0]['provisioning_UDID']
udid = system_profile["SPHardwareDataType"][0]["provisioning_UDID"]
friendly_model = get_friendly_model(serial=machine_results["serial"], udid=udid)
if friendly_model:
machine_results["machine_model_friendly"] = friendly_model
machine_results["cpu_type"] = system_profile["SPHardwareDataType"][0].get(
"cpu_type", ""
)
if system_profile["SPHardwareDataType"][0].get("chip_type", None):
machine_results["cpu_type"] = system_profile["SPHardwareDataType"][0].get(
"chip_type", ""
)
else:
machine_results["cpu_type"] = system_profile["SPHardwareDataType"][0].get(
"cpu_type", ""
)
machine_results["cpu_speed"] = system_profile["SPHardwareDataType"][0][
"current_processor_speed"
]
Expand Down Expand Up @@ -102,12 +107,24 @@ def get_machine_name(net_config, nametype):

def get_friendly_model(serial, udid):
"""Return friendly model name"""
cmd = ["/usr/sbin/ioreg", "-arc", "IOPlatformDevice", "-k", "product-name"]
try:
out = subprocess.check_output(cmd)
except:
pass
if out:
try:
data = plistlib.loads(out)
if len(data) != 0:
return data[0].get("product-name").decode("utf-8")
except:
pass

# set up cache file for this udid...create dir,
MODEL_PATH.mkdir(mode=0o755, parents=True, exist_ok=True)

# name cache for this udid
UDID_CACHE_PATH = pathlib.Path(MODEL_PATH, '%s.txt' % (udid))
UDID_CACHE_PATH = pathlib.Path(MODEL_PATH, "%s.txt" % (udid))
for cache_file in MODEL_PATH.iterdir():
# clean up any other files in dir
if cache_file != UDID_CACHE_PATH:
Expand Down
8 changes: 5 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
sal_python_pkg/
pyobjc==6.2.2
urllib3==1.25.10
requests==2.24.0
pyobjc==7.2
#urllib3==1.26.5
requests==2.26.0
MacSesh==0.3.0
six==1.16.0
--no-binary :all:
2 changes: 1 addition & 1 deletion sal_python_pkg/sal/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.1.1"
__version__ = "4.2.0"
2 changes: 1 addition & 1 deletion sal_python_pkg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
version=namespace["__version__"],
description="Sal client utilities",
install_requires=[
'pyobjc == 6.2.2 ; platform_system=="Darwin"',
'pyobjc >= 6.2.2 ; platform_system=="Darwin"',
'macsesh == 0.3.0 ; platform_system=="Darwin"',
"requests >= 2.23.0",
],
Expand Down
Loading

0 comments on commit e7bab64

Please sign in to comment.