Skip to content

Commit 3aa035b

Browse files
authored
Merge pull request #1409 from ychin/create-dmg-upgrade
Upgrade create-dmg and build DMG disk image with APFS
2 parents a27b466 + 1bf1606 commit 3aa035b

File tree

21 files changed

+84
-30
lines changed

21 files changed

+84
-30
lines changed

.github/workflows/ci-macvim.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,11 @@ jobs:
312312
run: |
313313
# Use the --skip-jenkins flag to skip the prettify osascript calls which could fail due to permission issues in
314314
# CI environment.
315-
make -C src macvim-dmg CREATEDMG_FLAGS=--skip-jenkins
315+
if ${{ matrix.legacy == true }}; then
316+
make -C src macvim-dmg-legacy CREATEDMG_FLAGS=--skip-jenkins
317+
else
318+
make -C src macvim-dmg CREATEDMG_FLAGS=--skip-jenkins
319+
fi
316320
317321
if ${{ matrix.publish_postfix != '' }}; then
318322
mv src/MacVim/build/Release/MacVim.dmg src/MacVim/build/Release/MacVim${{ matrix.publish_postfix }}.dmg
File renamed without changes.

src/MacVim/create-dmg/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Content of this directory is copied from https://github.com/create-dmg/create-dmg (c89d743919acb1a16259ed7b98059393978fb639 / 2023-01-23).
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ All contents of source\_folder will be copied into the disk image.
6363
- **--eula \<eula_file\>:** attach a license file to the dmg
6464
- **--rez \<rez_path\>:** specify custom path to Rez tool used to include license file
6565
- **--no-internet-enable:** disable automatic mount&copy
66-
- **--format:** specify the final image format (UDZO|UDBZ|ULFO|ULMO) (default is UDZO)
66+
- **--format:** specify the final image format (UDZO|UDBZ|ULFO|ULMO) (default is UDZO)
67+
- **--filesystem:** specify the image filesystem (HFS+|APFS) (default is HFS+, APFS supports macOS 10.13 or newer)
6768
- **--add-file \<target_name\> \<file|folder\> \<x\> \<y\>:** add additional file or folder (can be used multiple times)
6869
- **--disk-image-size \<x\>:** set the disk image size manually to x MB
6970
- **--hdiutil-verbose:** execute hdiutil in verbose mode
@@ -73,7 +74,7 @@ All contents of source\_folder will be copied into the disk image.
7374
- **--notarize \<credentials>:** notarize the disk image (waits and staples) with the keychain stored credentials
7475
For more information check [Apple's documentation](https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution/customizing_the_notarization_workflow)
7576
- **--skip-jenkins:** skip Finder-prettifying AppleScript, useful in Sandbox and non-GUI environments, [#72](https://github.com/create-dmg/create-dmg/pull/72)
76-
- **--sandbox-safe:** hdiutil with sandbox compatibility, do not bless and do not execute the cosmetic AppleScript
77+
- **--sandbox-safe:** hdiutil with sandbox compatibility, do not bless and do not execute the cosmetic AppleScript (not supported for APFS disk images)
7778
- **--version:** show tool version number
7879
- **-h, --help:** display the help
7980

File renamed without changes.
Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@
44

55
# Bail out on any unhandled errors
66
set -e;
7+
# Any command that exits with non-zero code will cause the pipeline to fail
8+
set -o pipefail;
79

8-
CDMG_VERSION='1.1.0'
10+
CDMG_VERSION='1.1.1'
911

1012
# The full path to the "support/" directory this script is using
1113
# (This will be set up by code later in the script.)
1214
CDMG_SUPPORT_DIR=""
1315

16+
OS_FULL_VERSION="$(sw_vers | sed -n 2p | cut -d : -f 2 | tr -d '[:space:]' | cut -c1-)"
17+
OS_MAJOR_VERSION="$(echo $OS_FULL_VERSION | cut -d . -f 1)"
18+
OS_MINOR_VERSION="$(echo $OS_FULL_VERSION | cut -d . -f 2)"
1419
WINX=10
1520
WINY=60
1621
WINW=500
1722
WINH=350
1823
ICON_SIZE=128
1924
TEXT_SIZE=16
2025
FORMAT="UDZO"
26+
FILESYSTEM="HFS+"
2127
ADD_FILE_SOURCES=()
2228
ADD_FILE_TARGETS=()
2329
IMAGEKEY=""
@@ -33,6 +39,26 @@ function pure_version() {
3339
echo "$CDMG_VERSION"
3440
}
3541

42+
function hdiutil_detach_retry() {
43+
# Unmount
44+
unmounting_attempts=0
45+
until
46+
echo "Unmounting disk image..."
47+
(( unmounting_attempts++ ))
48+
hdiutil detach "$1"
49+
exit_code=$?
50+
(( exit_code == 0 )) && break # nothing goes wrong
51+
(( exit_code != 16 )) && exit $exit_code # exit with the original exit code
52+
# The above statement returns 1 if test failed (exit_code == 16).
53+
# It can make the code in the {do... done} block to be executed
54+
do
55+
(( unmounting_attempts == MAXIMUM_UNMOUNTING_ATTEMPTS )) && exit 16 # patience exhausted, exit with code EBUSY
56+
echo "Wait a moment..."
57+
sleep $(( 1 * (2 ** unmounting_attempts) ))
58+
done
59+
unset unmounting_attempts
60+
}
61+
3662
function version() {
3763
echo "create-dmg $(pure_version)"
3864
}
@@ -76,6 +102,8 @@ Options:
76102
disable automatic mount & copy
77103
--format <format>
78104
specify the final disk image format (UDZO|UDBZ|ULFO|ULMO) (default is UDZO)
105+
--filesystem <filesystem>
106+
specify the disk image filesystem (HFS+|APFS) (default is HFS+, APFS supports macOS 10.13 or newer)
79107
--add-file <target_name> <file>|<folder> <x> <y>
80108
add additional file or folder (can be used multiple times)
81109
--disk-image-size <x>
@@ -91,7 +119,7 @@ Options:
91119
--notarize <credentials>
92120
notarize the disk image (waits and staples) with the keychain stored credentials
93121
--sandbox-safe
94-
execute hdiutil with sandbox compatibility and do not bless
122+
execute hdiutil with sandbox compatibility and do not bless (not supported for APFS disk images)
95123
--version
96124
show create-dmg version number
97125
-h, --help
@@ -162,6 +190,9 @@ while [[ "${1:0:1}" = "-" ]]; do
162190
--format)
163191
FORMAT="$2"
164192
shift; shift;;
193+
--filesystem)
194+
FILESYSTEM="$2"
195+
shift; shift;;
165196
--add-file | --add-folder)
166197
ADD_FILE_TARGETS+=("$2")
167198
ADD_FILE_SOURCES+=("$3")
@@ -230,6 +261,16 @@ if [[ "${DMG_PATH: -4}" != ".dmg" ]]; then
230261
exit 1
231262
fi
232263

264+
if [[ "${FILESYSTEM}" != "HFS+" ]] && [[ "${FILESYSTEM}" != "APFS" ]]; then
265+
echo "Unknown disk image filesystem: ${FILESYSTEM}. Run 'create-dmg --help' for help."
266+
exit 1
267+
fi
268+
269+
if [[ "${FILESYSTEM}" == "APFS" ]] && [[ ${SANDBOX_SAFE} -eq 1 ]]; then
270+
echo "Creating an APFS disk image that is sandbox safe is not supported."
271+
exit 1
272+
fi
273+
233274
# Main script logic
234275

235276
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@@ -280,7 +321,12 @@ function blocks_to_megabytes() {
280321

281322
function get_size() {
282323
# Get block size in disk
283-
bytes_size=$(du -s "$1" | sed -e 's/ .*//g')
324+
if [[ $OS_MAJOR_VERSION -ge 12 ]]; then
325+
bytes_size=$(du -B 512 -s "$1")
326+
else
327+
bytes_size=$(du -s "$1")
328+
fi
329+
bytes_size=$(echo $bytes_size | sed -e 's/ .*//g')
284330
echo $(blocks_to_megabytes $bytes_size)
285331
}
286332

@@ -291,9 +337,14 @@ if [[ -n "$DISK_IMAGE_SIZE" ]]; then
291337
fi
292338

293339
if [[ $SANDBOX_SAFE -eq 0 ]]; then
340+
if [[ "$FILESYSTEM" == "APFS" ]]; then
341+
FILESYSTEM_ARGUMENTS=""
342+
else
343+
FILESYSTEM_ARGUMENTS="-c c=64,a=16,e=16"
344+
fi
294345
hdiutil create ${HDIUTIL_VERBOSITY} -srcfolder "$SRC_FOLDER" -volname "${VOLUME_NAME}" \
295-
-fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW ${CUSTOM_SIZE} "${DMG_TEMP_NAME}"
296-
else
346+
-fs "${FILESYSTEM}" -fsargs "${FILESYSTEM_ARGUMENTS}" -format UDRW ${CUSTOM_SIZE} "${DMG_TEMP_NAME}"
347+
else
297348
hdiutil makehybrid ${HDIUTIL_VERBOSITY} -default-volume-name "${VOLUME_NAME}" -hfs -o "${DMG_TEMP_NAME}" "$SRC_FOLDER"
298349
hdiutil convert -format UDRW -ov -o "${DMG_TEMP_NAME}" "${DMG_TEMP_NAME}"
299350
DISK_IMAGE_SIZE_CUSTOM=$DISK_IMAGE_SIZE
@@ -335,7 +386,7 @@ MOUNT_DIR="/Volumes/${VOLUME_NAME}"
335386
if [[ -d "${MOUNT_DIR}" ]]; then
336387
echo "Unmounting old disk image from $MOUNT_DIR..."
337388
DEV_NAME=$(hdiutil info | grep -E --color=never '^/dev/' | sed 1q | awk '{print $1}')
338-
hdiutil detach "${DEV_NAME}"
389+
hdiutil_detach_retry "${DEV_NAME}"
339390
fi
340391

341392
echo "Mounting disk image..."
@@ -399,7 +450,7 @@ else
399450
true
400451
else
401452
echo >&2 "Failed running AppleScript"
402-
hdiutil detach "${DEV_NAME}"
453+
hdiutil_detach_retry "${DEV_NAME}"
403454
exit 64
404455
fi
405456
echo "Done running the AppleScript..."
@@ -416,7 +467,11 @@ echo "Done fixing permissions"
416467
# Make the top window open itself on mount:
417468
if [[ $BLESS -eq 1 && $SANDBOX_SAFE -eq 0 ]]; then
418469
echo "Blessing started"
419-
bless --folder "${MOUNT_DIR}" --openfolder "${MOUNT_DIR}"
470+
if [ $(uname -m) == "arm64" ]; then
471+
bless --folder "${MOUNT_DIR}"
472+
else
473+
bless --folder "${MOUNT_DIR}" --openfolder "${MOUNT_DIR}"
474+
fi
420475
echo "Blessing finished"
421476
else
422477
echo "Skipping blessing on sandbox"
@@ -431,23 +486,7 @@ fi
431486
echo "Deleting .fseventsd"
432487
rm -rf "${MOUNT_DIR}/.fseventsd" || true
433488

434-
# Unmount
435-
unmounting_attempts=0
436-
until
437-
echo "Unmounting disk image..."
438-
(( unmounting_attempts++ ))
439-
hdiutil detach "${DEV_NAME}"
440-
exit_code=$?
441-
(( exit_code == 0 )) && break # nothing goes wrong
442-
(( exit_code != 16 )) && exit $exit_code # exit with the original exit code
443-
# The above statement returns 1 if test failed (exit_code == 16).
444-
# It can make the code in the {do... done} block to be executed
445-
do
446-
(( unmounting_attempts == MAXIMUM_UNMOUNTING_ATTEMPTS )) && exit 16 # patience exhausted, exit with code EBUSY
447-
echo "Wait a moment..."
448-
sleep $(( 1 * (2 ** unmounting_attempts) ))
449-
done
450-
unset unmounting_attempts
489+
hdiutil_detach_retry "${DEV_NAME}"
451490

452491
# Compress image
453492
echo "Compressing disk image..."

0 commit comments

Comments
 (0)