Skip to content

Commit c5b5e95

Browse files
staticfloatStefanKarpinski
authored andcommitted
Add scaffolding for notarization on MacOS (#34120)
1 parent 0edadf1 commit c5b5e95

File tree

4 files changed

+100
-4
lines changed

4 files changed

+100
-4
lines changed

contrib/mac/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
julia/
22
dmg/
33
*.dmg
4+
notarize-*.xml

contrib/mac/app/Entitlements.plist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.automation.apple-events</key>
6+
<true/>
7+
</dict>
8+
</plist>

contrib/mac/app/Makefile

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ APP_NAME:=Julia-$(JULIA_VERSION_MAJOR_MINOR).app
1717
VOL_NAME:=Julia-$(JULIA_VERSION_OPT_COMMIT)
1818

1919
APP_ID:=org.julialang.launcherapp
20-
APP_COPYRIGHT:2016 The Julia Project
20+
APP_COPYRIGHT:$(shell date '+%Y') The Julia Project
2121

2222

2323
all: clean $(DMG_NAME)
@@ -51,7 +51,7 @@ dmg/$(APP_NAME): startup.applescript julia.icns
5151
tar zxf $(JULIAHOME)/$(JULIA_BINARYDIST_FILENAME).tar.gz -C $@/Contents/Resources/julia --strip-components 1
5252
if [ -n "$$MACOS_CODESIGN_IDENTITY" ]; then \
5353
echo "Codesigning with identity $$MACOS_CODESIGN_IDENTITY"; \
54-
codesign -s "$$MACOS_CODESIGN_IDENTITY" -v --deep $@; \
54+
codesign -s "$$MACOS_CODESIGN_IDENTITY" --option=runtime --entitlements Entitlements.plist -v --deep $@; \
5555
else \
5656
true; \
5757
fi
@@ -60,9 +60,35 @@ ROOTFILES := $(shell ls -ld dmg/*.app *.dmg 2> /dev/null | awk '{print $$3}')
6060
clean:
6161
ifneq ($(filter root,$(ROOTFILES)),)
6262
@echo "We have to use sudo here to clean out folders owned by root. You may be asked for your password"
63-
sudo rm -rf dmg *.dmg
63+
sudo rm -rf dmg *.dmg notarize-*.xml
6464
else
6565
rm -rf dmg *.dmg
6666
endif
6767

68-
.PHONY: clean all
68+
notarize-upload-$(DMG_NAME).xml: $(DMG_NAME)
69+
@# Upload the `.dmg` for notarization
70+
xcrun altool --notarize-app --primary-bundle-id org.julialang.launcherapp --username "$$APPLEID" --password "$$APPLEID_PASSWORD" -itc_provider A427R7F42H --file "$(DMG_NAME)" --output-format xml > "$@"
71+
@# Sleep for a few seconds so that we don't immediately error out when we request the UUID from Apple
72+
@sleep 5
73+
74+
75+
notarize-check: notarize-upload-$(DMG_NAME).xml
76+
@# We wait in a while loop for notarization to complete
77+
./notarize_check.sh "$<"
78+
79+
# This is the top-level notarization target. Note that this is still a somewhat manual
80+
# process; things can go wrong, and so if it fails, you may need to inspect the `.xml`
81+
# files to see what went wrong, but in general you can just run `make notarize` and it
82+
# should upload, notarize, staple, and re-package the .dmg for you.
83+
# Note that for this to work, you need to have exported `APPLEID`, `APPLEID_PASSWORD`
84+
# and `MACOS_CODESIGN_IDENTITY` to have signed the `.app` in the first place.
85+
notarize: notarize-check
86+
@# Delete old .dmg file
87+
rm -f $(DMG_NAME)
88+
@# Staple the .app
89+
xcrun stapler staple dmg/$(APP_NAME)
90+
@# re-build the .dmg
91+
$(MAKE) $(DMG_NAME)
92+
93+
94+
.PHONY: clean all notarize-upload notarize-check

contrib/mac/app/notarize_check.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
# Note that you need to have exported `APPLEID` and `APPLEID_PASSWORD` for this to work.
4+
5+
# Get the UUID from a notarization-upload*.xml file
6+
function extract_uuid()
7+
{
8+
PLIST_FILE="$1"
9+
10+
SED_PATTERN='.*([[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}).*'
11+
/usr/libexec/PlistBuddy -c "print notarization-upload:RequestUUID" "${PLIST_FILE}" 2>/dev/null
12+
if [[ $? != 0 ]]; then
13+
sed -n -E "s/${SED_PATTERN}/\1/p" "${PLIST_FILE}" 2>/dev/null | head -1
14+
fi
15+
}
16+
17+
# Continually probe and ask if Apple is done notarizing our precious binary bits
18+
function wait_until_completed()
19+
{
20+
UUID="$1"
21+
PLIST_FILE="$2"
22+
echo "Waiting until UUID ${UUID} is done processing...."
23+
24+
while true; do
25+
xcrun altool --notarization-info "${UUID}" --username "${APPLEID}" --password "${APPLEID_PASSWORD}" --output-format xml > "${PLIST_FILE}"
26+
STATUS=$(/usr/libexec/PlistBuddy -c "print notarization-info:Status" "${PLIST_FILE}" 2>/dev/null)
27+
28+
# Process loop exit conditions
29+
if [[ ${STATUS} == "success" ]]; then
30+
echo "Notarization finished"
31+
return 0
32+
elif [[ ${STATUS} == "in progress" ]]; then
33+
echo -n "."
34+
sleep 10
35+
continue
36+
else
37+
echo "Notarization failed with status ${STATUS}"
38+
exit 1
39+
fi
40+
done
41+
}
42+
43+
if [[ "$#" != 1 ]]; then
44+
echo "Usage: $0 notarize-upload-<suffix>.xml"
45+
exit 1
46+
fi
47+
48+
# Get input parameters
49+
UPLOAD_PLIST_FILE="$1"
50+
SUFFIX="${UPLOAD_PLIST_FILE#"notarize-upload-"}"
51+
SUFFIX="${SUFFIX%".xml"}"
52+
53+
# Extract UUID from uploaded plist file
54+
UUID=$(extract_uuid "${UPLOAD_PLIST_FILE}")
55+
if [[ -z "${UUID}" ]]; then
56+
echo "ERROR: Could not extract UUID value from ${UPLOAD_PLIST_FILE}" >&2
57+
exit 1
58+
fi
59+
60+
# Wait until the UUID is done processing
61+
wait_until_completed "${UUID}" "notarize-check-${SUFFIX}.xml"

0 commit comments

Comments
 (0)