2020-11-06 11:54:53 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
|
|
|
import inspect
|
|
|
|
import subprocess
|
|
|
|
import argparse
|
|
|
|
import shutil
|
|
|
|
import glob
|
2021-02-07 14:51:12 -05:00
|
|
|
import itertools
|
2020-11-06 11:54:53 -05:00
|
|
|
|
|
|
|
root = os.path.dirname(
|
|
|
|
os.path.dirname(
|
2020-11-06 12:00:25 -05:00
|
|
|
os.path.dirname(
|
|
|
|
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
|
|
|
)
|
2020-11-06 11:54:53 -05:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-02-07 14:51:12 -05:00
|
|
|
def codesign(path, entitlements, identity):
|
|
|
|
run(
|
|
|
|
[
|
|
|
|
"codesign",
|
|
|
|
"--sign",
|
|
|
|
identity,
|
|
|
|
"--entitlements",
|
|
|
|
str(entitlements),
|
|
|
|
"--timestamp",
|
|
|
|
"--deep",
|
|
|
|
str(path),
|
|
|
|
"--force",
|
|
|
|
"--options",
|
|
|
|
"runtime",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-11-06 11:54:53 -05:00
|
|
|
def run(cmd, cwd=None):
|
|
|
|
subprocess.run(cmd, cwd=cwd, check=True)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
# Parse arguments
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"--with-codesign",
|
|
|
|
action="store_true",
|
|
|
|
dest="with_codesign",
|
|
|
|
help="Codesign the app bundle",
|
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
cli_dir = os.path.join(root, "cli")
|
|
|
|
desktop_dir = os.path.join(root, "desktop")
|
|
|
|
|
2020-11-09 21:36:31 -05:00
|
|
|
print("○ Clean up from last build")
|
2020-11-09 21:38:55 -05:00
|
|
|
if os.path.exists(os.path.join(cli_dir, "dist")):
|
2020-11-09 21:36:31 -05:00
|
|
|
shutil.rmtree(os.path.join(cli_dir, "dist"))
|
|
|
|
if os.path.exists(os.path.join(desktop_dir, "macOS")):
|
|
|
|
shutil.rmtree(os.path.join(desktop_dir, "macOS"))
|
|
|
|
|
2021-02-07 17:40:13 -05:00
|
|
|
print("○ Build onionshare-cli")
|
2020-11-06 11:54:53 -05:00
|
|
|
run(["poetry", "install"], cli_dir)
|
|
|
|
run(["poetry", "build"], cli_dir)
|
2020-11-06 16:24:43 -05:00
|
|
|
whl_filename = glob.glob(os.path.join(cli_dir, "dist", "*.whl"))[0]
|
2020-11-06 11:54:53 -05:00
|
|
|
whl_basename = os.path.basename(whl_filename)
|
|
|
|
shutil.copyfile(whl_filename, os.path.join(desktop_dir, whl_basename))
|
|
|
|
|
|
|
|
print("○ Create app bundle")
|
|
|
|
run(["briefcase", "create"], desktop_dir)
|
2021-05-05 23:39:14 -04:00
|
|
|
app_path = os.path.join(desktop_dir, "macOS", "app", "OnionShare", "OnionShare.app")
|
2021-02-07 17:40:13 -05:00
|
|
|
|
|
|
|
print("○ Delete unused Qt5 frameworks from app bundle")
|
|
|
|
for framework in [
|
|
|
|
"Qt3DAnimation",
|
|
|
|
"Qt3DCore",
|
|
|
|
"Qt3DExtras",
|
|
|
|
"Qt3DInput",
|
|
|
|
"Qt3DLogic",
|
|
|
|
"Qt3DQuick",
|
|
|
|
"Qt3DQuickAnimation",
|
|
|
|
"Qt3DQuickExtras",
|
|
|
|
"Qt3DQuickInput",
|
|
|
|
"Qt3DQuickRender",
|
|
|
|
"Qt3DQuickScene2D",
|
|
|
|
"Qt3DRender",
|
|
|
|
"QtBluetooth",
|
|
|
|
"QtBodymovin",
|
|
|
|
"QtCharts",
|
|
|
|
"QtConcurrent",
|
|
|
|
"QtDataVisualization",
|
|
|
|
"QtDesigner",
|
|
|
|
"QtDesignerComponents",
|
|
|
|
"QtGamepad",
|
|
|
|
"QtHelp",
|
|
|
|
"QtLocation",
|
|
|
|
"QtMultimedia",
|
|
|
|
"QtMultimediaQuick",
|
|
|
|
"QtMultimediaWidgets",
|
|
|
|
"QtNfc",
|
|
|
|
"QtOpenGL",
|
|
|
|
"QtPdf",
|
|
|
|
"QtPdfWidgets",
|
|
|
|
"QtPositioning",
|
|
|
|
"QtPositioningQuick",
|
|
|
|
"QtPurchasing",
|
|
|
|
"QtQuick",
|
|
|
|
"QtQuick3D",
|
|
|
|
"QtQuick3DAssetImport",
|
|
|
|
"QtQuick3DRender",
|
|
|
|
"QtQuick3DRuntimeRender",
|
|
|
|
"QtQuick3DUtils",
|
|
|
|
"QtQuickControls2",
|
|
|
|
"QtQuickParticles",
|
|
|
|
"QtQuickShapes",
|
|
|
|
"QtQuickTemplates2",
|
|
|
|
"QtQuickTest",
|
|
|
|
"QtQuickWidgets",
|
|
|
|
"QtRemoteObjects",
|
|
|
|
"QtRepParser",
|
|
|
|
"QtScript",
|
|
|
|
"QtScriptTools",
|
|
|
|
"QtScxml",
|
|
|
|
"QtSensors",
|
|
|
|
"QtSerialBus",
|
|
|
|
"QtSerialPort",
|
|
|
|
"QtSql",
|
|
|
|
"QtSvg",
|
|
|
|
"QtTest",
|
|
|
|
"QtTextToSpeech",
|
|
|
|
"QtUiPlugin",
|
|
|
|
"QtVirtualKeyboard",
|
|
|
|
"QtWebChannel",
|
|
|
|
"QtWebEngine",
|
|
|
|
"QtWebEngineCore",
|
|
|
|
"QtWebEngineWidgets",
|
|
|
|
"QtWebSockets",
|
|
|
|
"QtWebView",
|
|
|
|
"QtXml",
|
|
|
|
"QtXmlPatterns",
|
|
|
|
]:
|
|
|
|
shutil.rmtree(
|
|
|
|
os.path.join(
|
|
|
|
app_path,
|
|
|
|
"Contents",
|
|
|
|
"Resources",
|
|
|
|
"app_packages",
|
|
|
|
"PySide2",
|
|
|
|
"Qt",
|
|
|
|
"lib",
|
|
|
|
f"{framework}.framework",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
os.remove(
|
|
|
|
os.path.join(
|
|
|
|
app_path,
|
|
|
|
"Contents",
|
|
|
|
"Resources",
|
|
|
|
"app_packages",
|
|
|
|
"PySide2",
|
|
|
|
f"{framework}.abi3.so",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
os.remove(
|
|
|
|
os.path.join(
|
|
|
|
app_path,
|
|
|
|
"Contents",
|
|
|
|
"Resources",
|
|
|
|
"app_packages",
|
|
|
|
"PySide2",
|
|
|
|
f"{framework}.pyi",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
shutil.rmtree(
|
|
|
|
os.path.join(
|
|
|
|
app_path,
|
|
|
|
"Contents",
|
|
|
|
"Resources",
|
|
|
|
"app_packages",
|
|
|
|
"PySide2",
|
|
|
|
"Designer.app",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-11-06 11:54:53 -05:00
|
|
|
print(f"○ Unsigned app bundle: {app_path}")
|
|
|
|
|
|
|
|
if args.with_codesign:
|
|
|
|
identity_name_application = "Developer ID Application: Micah Lee (N9B95FDWH4)"
|
2021-02-07 14:51:12 -05:00
|
|
|
entitlements_plist_path = os.path.join(
|
2020-11-06 11:54:53 -05:00
|
|
|
desktop_dir, "package", "macos", "Entitlements.plist"
|
|
|
|
)
|
|
|
|
|
2021-02-07 17:40:13 -05:00
|
|
|
print("○ Code sign app bundle")
|
2021-02-07 14:51:12 -05:00
|
|
|
for path in itertools.chain(
|
2021-02-07 17:40:13 -05:00
|
|
|
glob.glob(
|
|
|
|
f"{app_path}/Contents/Resources/app_packages/**/*.dylib", recursive=True
|
|
|
|
),
|
|
|
|
glob.glob(
|
|
|
|
f"{app_path}/Contents/Resources/app_packages/**/*.so", recursive=True
|
|
|
|
),
|
|
|
|
glob.glob(
|
|
|
|
f"{app_path}/Contents/Resources/Support/**/*.dylib", recursive=True
|
|
|
|
),
|
2021-02-07 14:51:12 -05:00
|
|
|
glob.glob(f"{app_path}/Contents/Resources/Support/**/*.so", recursive=True),
|
2021-02-07 17:40:13 -05:00
|
|
|
glob.glob(
|
|
|
|
f"{app_path}/Contents/Resources/app_packages/PySide2/Qt/lib/**/Versions/5/*",
|
|
|
|
recursive=True,
|
|
|
|
),
|
|
|
|
[
|
|
|
|
f"{app_path}/Contents/Resources/app_packages/PySide2/pyside2-lupdate",
|
|
|
|
f"{app_path}/Contents/Resources/app_packages/PySide2/rcc",
|
|
|
|
f"{app_path}/Contents/Resources/app_packages/PySide2/uic",
|
|
|
|
app_path,
|
|
|
|
],
|
2021-02-07 14:51:12 -05:00
|
|
|
):
|
|
|
|
codesign(path, entitlements_plist_path, identity_name_application)
|
|
|
|
codesign(app_path, entitlements_plist_path, identity_name_application)
|
2020-11-06 11:54:53 -05:00
|
|
|
print(f"○ Signed app bundle: {app_path}")
|
|
|
|
|
2020-11-06 12:33:37 -05:00
|
|
|
if not os.path.exists("/usr/local/bin/create-dmg"):
|
|
|
|
print("○ Error: create-dmg is not installed")
|
|
|
|
return
|
|
|
|
|
2021-02-07 17:40:13 -05:00
|
|
|
print("○ Create DMG")
|
2020-11-06 12:33:37 -05:00
|
|
|
dmg_path = os.path.join(desktop_dir, "macOS", "OnionShare.dmg")
|
|
|
|
run(
|
|
|
|
[
|
|
|
|
"create-dmg",
|
|
|
|
"--volname",
|
|
|
|
"OnionShare",
|
|
|
|
"--volicon",
|
|
|
|
os.path.join(
|
|
|
|
desktop_dir, "src", "onionshare", "resources", "onionshare.icns"
|
|
|
|
),
|
|
|
|
"--window-size",
|
|
|
|
"400",
|
|
|
|
"200",
|
|
|
|
"--icon-size",
|
|
|
|
"100",
|
|
|
|
"--icon",
|
|
|
|
"OnionShare.app",
|
|
|
|
"100",
|
|
|
|
"70",
|
|
|
|
"--hide-extension",
|
|
|
|
"OnionShare.app",
|
|
|
|
"--app-drop-link",
|
|
|
|
"300",
|
|
|
|
"70",
|
|
|
|
dmg_path,
|
|
|
|
app_path,
|
|
|
|
"--identity",
|
|
|
|
identity_name_application,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
print(f"○ Finished building DMG: {dmg_path}")
|
2020-11-06 11:54:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-02-07 17:40:13 -05:00
|
|
|
main()
|