| 1 | #!/usr/bin/python3
|
|---|
| 2 | """
|
|---|
| 3 | Builds the OSX bundle from existing elements.
|
|---|
| 4 | App bundles are intended to be self-contained and portable.
|
|---|
| 5 | An SDK is required, usually included with Xcode. The SDK ensures
|
|---|
| 6 | that only those system libraries are used which are available on
|
|---|
| 7 | the chosen target and compatible systems.
|
|---|
| 8 |
|
|---|
| 9 | This is Python because plistlib is extremely strict about what it accepts
|
|---|
| 10 | and it's used by dmgbuild, and saving the Plist doesn't really work otherwise.
|
|---|
| 11 | """
|
|---|
| 12 | import argparse
|
|---|
| 13 | import datetime
|
|---|
| 14 | import glob
|
|---|
| 15 | import os
|
|---|
| 16 | import plistlib
|
|---|
| 17 | import shutil
|
|---|
| 18 |
|
|---|
| 19 | import dmgbuild
|
|---|
| 20 |
|
|---|
| 21 | parser = argparse.ArgumentParser()
|
|---|
| 22 | parser.add_argument('bundle_version', help='Bundle version')
|
|---|
| 23 | parser.add_argument('--min_osx', help='Minimum supported OSX version',
|
|---|
| 24 | default='10.12')
|
|---|
| 25 | parser.add_argument('--bundle_identifier', help='Bundle identifier',
|
|---|
| 26 | default='com.wildfiregames.0ad')
|
|---|
| 27 | parser.add_argument('--dev', help='Turn on dev mode, which isn\'t fit for release but faster',
|
|---|
| 28 | action="store_true")
|
|---|
| 29 | args = parser.parse_args()
|
|---|
| 30 |
|
|---|
| 31 | BUNDLE_IDENTIFIER = args.bundle_identifier
|
|---|
| 32 | BUNDLE_VERSION = args.bundle_version
|
|---|
| 33 | BUNDLE_MIN_OSX_VERSION = args.min_osx
|
|---|
| 34 |
|
|---|
| 35 | BUNDLE_DMG_NAME = f"0ad-{BUNDLE_VERSION}-alpha-osx64"
|
|---|
| 36 | BUNDLE_OUTPUT = "0 A.D..app"
|
|---|
| 37 | BUNDLE_CONTENTS = BUNDLE_OUTPUT + "/Contents"
|
|---|
| 38 | BUNDLE_BIN = BUNDLE_CONTENTS + "/MacOS"
|
|---|
| 39 | BUNDLE_RESOURCES = BUNDLE_CONTENTS + "/Resources"
|
|---|
| 40 | BUNDLE_FRAMEWORKS = BUNDLE_CONTENTS + "/Frameworks"
|
|---|
| 41 | BUNDLE_PLUGINS = BUNDLE_CONTENTS + "/PlugIns"
|
|---|
| 42 | BUNDLE_SHAREDSUPPORT = BUNDLE_CONTENTS + "/SharedSupport"
|
|---|
| 43 |
|
|---|
| 44 | print("Creating bundle directories")
|
|---|
| 45 |
|
|---|
| 46 | shutil.rmtree(BUNDLE_OUTPUT, ignore_errors=True)
|
|---|
| 47 | os.makedirs(BUNDLE_BIN)
|
|---|
| 48 | os.makedirs(BUNDLE_FRAMEWORKS)
|
|---|
| 49 | os.makedirs(BUNDLE_PLUGINS)
|
|---|
| 50 | os.makedirs(BUNDLE_RESOURCES)
|
|---|
| 51 | os.makedirs(BUNDLE_SHAREDSUPPORT)
|
|---|
| 52 |
|
|---|
| 53 | print("Copying binaries")
|
|---|
| 54 |
|
|---|
| 55 | # Only pyrogenesis for now, until we find a way to load
|
|---|
| 56 | # multiple binaries from one app bundle
|
|---|
| 57 | # TODO: Would be nicer if we could set this path in premake
|
|---|
| 58 | shutil.copy("binaries/system/pyrogenesis", BUNDLE_BIN)
|
|---|
| 59 |
|
|---|
| 60 | print("Copying libs")
|
|---|
| 61 | shutil.copy("binaries/system/libAtlasUI.dylib", BUNDLE_FRAMEWORKS)
|
|---|
| 62 | shutil.copy("binaries/system/libCollada.dylib", BUNDLE_FRAMEWORKS)
|
|---|
| 63 | shutil.copy("binaries/system/libMoltenVK.dylib", BUNDLE_FRAMEWORKS)
|
|---|
| 64 |
|
|---|
| 65 | if not args.dev:
|
|---|
| 66 | print("Copying archived game data from archives/")
|
|---|
| 67 | for mod in glob.glob("archives/*/"):
|
|---|
| 68 | print(f"Copying {mod}")
|
|---|
| 69 | shutil.copytree(mod, BUNDLE_RESOURCES + "/data/mods/" + mod.replace("archives/", ""))
|
|---|
| 70 | else:
|
|---|
| 71 | print("Symlinking mods")
|
|---|
| 72 | os.makedirs(BUNDLE_RESOURCES + "/data/mods")
|
|---|
| 73 | os.chdir(BUNDLE_RESOURCES + "/data/mods")
|
|---|
| 74 | for mod in glob.glob("../../../../../binaries/data/mods/*"):
|
|---|
| 75 | os.symlink(mod, mod.replace("../../../../../binaries/data/mods/", ""))
|
|---|
| 76 | os.chdir("../../../../../")
|
|---|
| 77 |
|
|---|
| 78 | print("Copying non-archived game data")
|
|---|
| 79 | shutil.copytree("binaries/data/config", BUNDLE_RESOURCES + "/data/config")
|
|---|
| 80 | shutil.copytree("binaries/data/l10n", BUNDLE_RESOURCES + "/data/l10n")
|
|---|
| 81 | shutil.copytree("binaries/data/tools", BUNDLE_RESOURCES + "/data/tools")
|
|---|
| 82 | # Remove the dev.cfg file or 0 A.D. will assume it's running a dev copy.
|
|---|
| 83 | os.unlink(BUNDLE_RESOURCES + "/data/config/dev.cfg")
|
|---|
| 84 |
|
|---|
| 85 | shutil.copy("build/resources/0ad.icns", BUNDLE_RESOURCES)
|
|---|
| 86 | shutil.copy("build/resources/InfoPlist.strings", BUNDLE_RESOURCES)
|
|---|
| 87 |
|
|---|
| 88 | print("Copying readmes")
|
|---|
| 89 | # TODO: Also want copies in the DMG - decide on layout
|
|---|
| 90 | for file in glob.glob("*.txt"):
|
|---|
| 91 | shutil.copy(file, BUNDLE_RESOURCES)
|
|---|
| 92 | shutil.copy("libraries/LICENSE.txt", BUNDLE_RESOURCES + "/LIB_LICENSE.txt")
|
|---|
| 93 |
|
|---|
| 94 | print("Creating Info.plist")
|
|---|
| 95 |
|
|---|
| 96 | with open(BUNDLE_CONTENTS + "/Info.plist", 'wb') as f:
|
|---|
| 97 | plistlib.dump({
|
|---|
| 98 | 'CFBundleName': '0 A.D.',
|
|---|
| 99 | 'CFBundleIdentifier': BUNDLE_IDENTIFIER,
|
|---|
| 100 | 'CFBundleVersion': BUNDLE_VERSION,
|
|---|
| 101 | 'CFBundlePackageType': 'APPL',
|
|---|
| 102 | 'CFBundleSignature': 'none',
|
|---|
| 103 | 'CFBundleExecutable': 'pyrogenesis',
|
|---|
| 104 | 'CFBundleShortVersionString': BUNDLE_VERSION,
|
|---|
| 105 | 'CFBundleDevelopmentRegion': 'English',
|
|---|
| 106 | 'CFBundleInfoDictionaryVersion': '6.0',
|
|---|
| 107 | 'CFBundleIconFile': '0ad',
|
|---|
| 108 | 'LSHasLocalizedDisplayName': True,
|
|---|
| 109 | 'LSMinimumSystemVersion': BUNDLE_MIN_OSX_VERSION,
|
|---|
| 110 | 'NSHumanReadableCopyright': f'Copyright © {datetime.datetime.now().year} Wildfire Games',
|
|---|
| 111 | 'UTExportedTypeDeclarations': [{
|
|---|
| 112 | 'UTTypeIdentifier': BUNDLE_IDENTIFIER,
|
|---|
| 113 | 'UTTypeTagSpecification': {
|
|---|
| 114 | 'public.filename-extension': ["pyromod"],
|
|---|
| 115 | },
|
|---|
| 116 | 'UTTypeConformsTo': ['public.zip-archive'],
|
|---|
| 117 | 'UTTypeDescription': '0 A.D. Zipped Mod',
|
|---|
| 118 | 'UTTypeIconFile': '0ad'
|
|---|
| 119 | }],
|
|---|
| 120 | 'CFBundleDocumentTypes': [{
|
|---|
| 121 | 'CFBundleTypeExtensions': ['pyromod'],
|
|---|
| 122 | 'CFBundleTypeRole': 'Editor',
|
|---|
| 123 | 'CFBundleTypeIconFile': '0ad',
|
|---|
| 124 | 'LSHandlerRank': 'Owner'
|
|---|
| 125 | },
|
|---|
| 126 | {
|
|---|
| 127 | 'CFBundleTypeExtensions': ['zip'],
|
|---|
| 128 | 'CFBundleTypeRole': 'Viewer',
|
|---|
| 129 | 'CFBundleTypeIconFile': '0ad',
|
|---|
| 130 | 'LSHandlerRank': 'Alternate'
|
|---|
| 131 | }],
|
|---|
| 132 | }, f)
|
|---|
| 133 |
|
|---|
| 134 | if args.dev:
|
|---|
| 135 | print(f"Dev mode bundle complete, located at {BUNDLE_OUTPUT}")
|
|---|
| 136 | exit(0)
|
|---|
| 137 |
|
|---|
| 138 | print("Creating .dmg")
|
|---|
| 139 |
|
|---|
| 140 | # Package the app into a dmg
|
|---|
| 141 | dmgbuild.build_dmg(
|
|---|
| 142 | filename=BUNDLE_DMG_NAME + ".dmg",
|
|---|
| 143 | volume_name=BUNDLE_DMG_NAME,
|
|---|
| 144 | settings_file="source/tools/dist/dmgbuild-settings.py",
|
|---|
| 145 | defines={
|
|---|
| 146 | "app": BUNDLE_OUTPUT,
|
|---|
| 147 | "background": "build/resources/dmgbackground.png",
|
|---|
| 148 | "icon": "build/resources/0ad.icns"
|
|---|
| 149 | })
|
|---|
| 150 |
|
|---|
| 151 | print(f"Bundle complete! Located in {BUNDLE_OUTPUT}, compressed as {BUNDLE_DMG_NAME}.dmg.")
|
|---|