This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

source: ps/trunk/source/tools/dist/build-osx-bundle.py

Last change on this file was 27965, checked in by Vladislav Belov, 13 months ago

Revert non-ASCII characters from source and configuration files introduced in rP27786.

Fixes #6846

Differential Revision: https://code.wildfiregames.com/D5185

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#!/usr/bin/python3
2"""
3Builds the OSX bundle from existing elements.
4App bundles are intended to be self-contained and portable.
5An SDK is required, usually included with Xcode. The SDK ensures
6that only those system libraries are used which are available on
7the chosen target and compatible systems.
8
9This is Python because plistlib is extremely strict about what it accepts
10and it's used by dmgbuild, and saving the Plist doesn't really work otherwise.
11"""
12import argparse
13import datetime
14import glob
15import os
16import plistlib
17import shutil
18
19import dmgbuild
20
21parser = argparse.ArgumentParser()
22parser.add_argument('bundle_version', help='Bundle version')
23parser.add_argument('--min_osx', help='Minimum supported OSX version',
24 default='10.12')
25parser.add_argument('--bundle_identifier', help='Bundle identifier',
26 default='com.wildfiregames.0ad')
27parser.add_argument('--dev', help='Turn on dev mode, which isn\'t fit for release but faster',
28 action="store_true")
29args = parser.parse_args()
30
31BUNDLE_IDENTIFIER = args.bundle_identifier
32BUNDLE_VERSION = args.bundle_version
33BUNDLE_MIN_OSX_VERSION = args.min_osx
34
35BUNDLE_DMG_NAME = f"0ad-{BUNDLE_VERSION}-alpha-osx64"
36BUNDLE_OUTPUT = "0 A.D..app"
37BUNDLE_CONTENTS = BUNDLE_OUTPUT + "/Contents"
38BUNDLE_BIN = BUNDLE_CONTENTS + "/MacOS"
39BUNDLE_RESOURCES = BUNDLE_CONTENTS + "/Resources"
40BUNDLE_FRAMEWORKS = BUNDLE_CONTENTS + "/Frameworks"
41BUNDLE_PLUGINS = BUNDLE_CONTENTS + "/PlugIns"
42BUNDLE_SHAREDSUPPORT = BUNDLE_CONTENTS + "/SharedSupport"
43
44print("Creating bundle directories")
45
46shutil.rmtree(BUNDLE_OUTPUT, ignore_errors=True)
47os.makedirs(BUNDLE_BIN)
48os.makedirs(BUNDLE_FRAMEWORKS)
49os.makedirs(BUNDLE_PLUGINS)
50os.makedirs(BUNDLE_RESOURCES)
51os.makedirs(BUNDLE_SHAREDSUPPORT)
52
53print("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
58shutil.copy("binaries/system/pyrogenesis", BUNDLE_BIN)
59
60print("Copying libs")
61shutil.copy("binaries/system/libAtlasUI.dylib", BUNDLE_FRAMEWORKS)
62shutil.copy("binaries/system/libCollada.dylib", BUNDLE_FRAMEWORKS)
63shutil.copy("binaries/system/libMoltenVK.dylib", BUNDLE_FRAMEWORKS)
64
65if 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/", ""))
70else:
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
78print("Copying non-archived game data")
79shutil.copytree("binaries/data/config", BUNDLE_RESOURCES + "/data/config")
80shutil.copytree("binaries/data/l10n", BUNDLE_RESOURCES + "/data/l10n")
81shutil.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.
83os.unlink(BUNDLE_RESOURCES + "/data/config/dev.cfg")
84
85shutil.copy("build/resources/0ad.icns", BUNDLE_RESOURCES)
86shutil.copy("build/resources/InfoPlist.strings", BUNDLE_RESOURCES)
87
88print("Copying readmes")
89# TODO: Also want copies in the DMG - decide on layout
90for file in glob.glob("*.txt"):
91 shutil.copy(file, BUNDLE_RESOURCES)
92shutil.copy("libraries/LICENSE.txt", BUNDLE_RESOURCES + "/LIB_LICENSE.txt")
93
94print("Creating Info.plist")
95
96with 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
134if args.dev:
135 print(f"Dev mode bundle complete, located at {BUNDLE_OUTPUT}")
136 exit(0)
137
138print("Creating .dmg")
139
140# Package the app into a dmg
141dmgbuild.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
151print(f"Bundle complete! Located in {BUNDLE_OUTPUT}, compressed as {BUNDLE_DMG_NAME}.dmg.")
Note: See TracBrowser for help on using the repository browser.