Commit 657a8c43 authored by Roman Grigorev's avatar Roman Grigorev Committed by intellij-monorepo-bot
Browse files

[build scripts] macOS: rewrite makedmg.pl on python

Added new python file which implements same functionality as in makedmg.pl
but in python and with using os independent library.

(cherry picked from commit 915a250f30dc7b80a607e54082411a8a78821c0e)
(cherry picked from commit 364c4bc2a60537e7b9cdd75eae9007b64d7c3ba1)
(cherry picked from commit 55ed4a51cf3e5993d60ffd60fbf037e12b249af4)

GitOrigin-RevId: 0c817791fcbfeb3cb211a9220923a0da4050870e
parent 62d8db29
Showing with 76 additions and 2 deletions
+76 -2
......@@ -266,7 +266,7 @@ final class MacDmgBuilder {
uploadRegular(sftp, dmgImageCopy)
Path scripts = buildContext.paths.communityHomeDir.resolve("platform/build-scripts/tools/mac/scripts")
uploadExecutable(sftp, scripts.resolve("makedmg.sh"))
uploadExecutable(sftp, scripts.resolve("makedmg.pl"))
uploadExecutable(sftp, scripts.resolve("makedmg.py"))
sshExec(ssh, "$remoteDir/makedmg.sh ${targetFileName} ${buildContext.fullBuildNumber}", "makedmg-${targetFileName}.log")
......
#!/usr/local/bin/python3 -w
import sys
import struct
from ds_store import *
from mac_alias import *
"""
Script generates needed configuration for MacOS installation dialog.
Original available docs for options are in perl module
https://metacpan.org/dist/Mac-Finder-DSStore/view/DSStoreFormat.pod
Python module docs are not so great:
https://ds-store.readthedocs.io/en/latest/
Many options, which are used here could be found in
https://dmgbuild.readthedocs.io/en/latest/settings.html
https://github.com/al45tair/dmgbuild/blob/master/dmgbuild/core.py
Some details about binary formats
https://0day.work/parsing-the-ds_store-file-format/
"""
name = sys.argv[1]
bgPic = sys.argv[2]
mountName = sys.argv[3]
print(f"Process ds store in /Volumes/{mountName}/.DS_Store")
with DSStore.open(f"/Volumes/{mountName}/.DS_Store", "w+") as d:
d[".background"]["Iloc"] = (560, 170)
d[".DS_Store"]["Iloc"] = (610, 170)
d[".fseventsd"]["Iloc"] = (660, 170)
d[".Trashes"]["Iloc"] = (710, 170)
d["Applications"]["Iloc"] = (340, 167)
byte_stream = struct.pack('>H', 100) + struct.pack('>H', 400) + \
struct.pack('>H', 396) + struct.pack('>H', 855) + \
bytes('icnv', 'ascii') + bytearray([0] * 4)
d['.']['fwi0'] = ('blob', byte_stream)
d['.']['fwsw'] = ('long', 170)
d['.']['fwvh'] = ('shor', 296)
d['.']['ICVO'] = ('bool', True)
alias = Alias.for_file(f"/Volumes/{mountName}/.background/{bgPic}")
d['.']['icvp'] = {
'viewOptionsVersion': 1,
'backgroundType': 2,
'backgroundImageAlias': alias.to_bytes(),
'backgroundColorRed': 1.0,
'backgroundColorGreen': 1.0,
'backgroundColorBlue': 1.0,
'gridOffsetX': 0,
'gridOffsetY': 0,
'gridSpacing': 100,
'arrangeBy': 'none',
'showIconPreview': True,
'showItemInfo': False,
'labelOnBottom': True,
'textSize': 12.0,
'iconSize': 100.0,
'scrollPositionX': 0.0,
'scrollPositionY': 0.0
}
d['.']['icvt'] = ('shor', 12)
d[f"{name}.app"]["Iloc"] = (110, 167)
......@@ -78,7 +78,13 @@ find "/Volumes/$1" -maxdepth 1
log "Updating $VOLNAME disk image styles..."
stat "/Volumes/$1/DSStorePlaceHolder"
rm "/Volumes/$1/DSStorePlaceHolder"
perl makedmg.pl "$VOLNAME" "$BG_PIC" "$1"
if python3 -c "import ds_store; import mac_alias;" >/dev/null 2>/dev/null; then
python3 makedmg.py "$VOLNAME" "$BG_PIC" "$1"
log "DMG/DS_Store is generated"
else
log "DMG/DS_Store generation is skipped. If you need it please install python3 and ds_store library."
fi
rm -rf "/Volumes/$1/.fseventsd"
sync;sync;sync
hdiutil detach "$device"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment