create an app bundle and package it in dmg

Fix resource lookup, add package prefs

fix tidy issues
This commit is contained in:
Connor Brewster 2016-06-28 07:40:57 -06:00
parent 00af25b685
commit 96b7a19ca0
5 changed files with 164 additions and 42 deletions

View file

@ -1,34 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleGetInfoString</key>
<string>English</string> <string>Servo</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>Servo</string> <string>run-servo</string>
<key>CFBundleIconFile</key> <key>CFBundleIdentifier</key>
<string>Calculator.icns</string> <string>org.servo.Servo22</string>
<key>CFBundleIdentifier</key> <key>CFBundleName</key>
<string>org.mozilla.servo</string> <string>Servo</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleIconFile</key>
<string>6.0</string> <string>servo.icns</string>
<key>CFBundleName</key> <key>CFBundleShortVersionString</key>
<string>Servo</string> <string>0.0.1</string>
<key>CFBundlePackageType</key> <key>CFBundleInfoDictionaryVersion</key>
<string>APPL</string> <string>6.0</string>
<key>CFBundleShortVersionString</key> <key>CFBundlePackageType</key>
<string>0.1</string> <string>APPL</string>
<key>CFBundleSignature</key> <key>NSHighResolutionCapable</key>
<string>????</string> <true/>
<key>CFBundleVersion</key> <key>NSPrincipalClass</key>
<string>0.1</string> <string>NSApplication</string>
<key>LSHasLocalizedDisplayName</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.3</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsSuddenTermination</key>
<false/>
</dict> </dict>
</plist> </plist>

View file

@ -39,20 +39,13 @@ pub fn resources_dir_path() -> PathBuf {
let mut path = env::current_exe().expect("can't get exe path"); let mut path = env::current_exe().expect("can't get exe path");
// Follow symlink // Follow symlink
path = path.canonicalize().expect("path does not exist"); path = path.canonicalize().expect("path does not exist");
path.pop();
path.push("resources"); while path.pop() {
if !path.is_dir() { // resources dir not in same dir as exe?
// exe is probably in target/{debug,release} so we need to go back to topdir
path.pop();
path.pop();
path.pop();
path.push("resources"); path.push("resources");
if !path.is_dir() { if path.is_dir() {
// exe is probably in target/$target_triple/{debug,release} so go back one more break;
path.pop();
path.pop();
path.push("resources");
} }
path.pop();
} }
*dir = Some(path.to_str().unwrap().to_owned()); *dir = Some(path.to_str().unwrap().to_owned());
path path

View file

@ -24,7 +24,7 @@ from mach.decorators import (
Command, Command,
) )
from servo.command_base import CommandBase, cd, BuildNotFound from servo.command_base import CommandBase, cd, BuildNotFound, is_macosx
from servo.post_build_commands import find_dep_path_newest from servo.post_build_commands import find_dep_path_newest
@ -35,6 +35,17 @@ def delete(path):
shutil.rmtree(path) # Remove it and all its contents. shutil.rmtree(path) # Remove it and all its contents.
def otool(s):
o = subprocess.Popen(['/usr/bin/otool', '-L', s], stdout=subprocess.PIPE)
for l in o.stdout:
if l[0] == '\t':
yield l.split(' ', 1)[0][1:]
def install_name_tool(old, new, binary):
subprocess.call(['install_name_tool', '-change', old, '@executable_path/' + new, binary])
@CommandProvider @CommandProvider
class PackageCommands(CommandBase): class PackageCommands(CommandBase):
@Command('package', @Command('package',
@ -71,6 +82,69 @@ class PackageCommands(CommandBase):
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print("Packaging Android exited with return value %d" % e.returncode) print("Packaging Android exited with return value %d" % e.returncode)
return e.returncode return e.returncode
elif is_macosx():
dir_to_build = '/'.join(binary_path.split('/')[:-1])
dir_to_dmg = '/'.join(binary_path.split('/')[:-2]) + '/dmg'
dir_to_app = dir_to_dmg + '/Servo.app'
dir_to_resources = dir_to_app + '/Contents/Resources/'
dir_to_root = '/'.join(binary_path.split('/')[:-3])
if os.path.exists(dir_to_dmg):
print("Cleaning up from previous packaging")
delete(dir_to_dmg)
browserhtml_path = find_dep_path_newest('browserhtml', binary_path)
if browserhtml_path is None:
print("Could not find browserhtml package; perhaps you haven't built Servo.")
return 1
print("Copying files")
shutil.copytree(dir_to_root + '/resources', dir_to_resources)
shutil.copytree(browserhtml_path, dir_to_resources + browserhtml_path.split('/')[-1])
shutil.copy2(dir_to_root + '/Info.plist', dir_to_app + '/Contents/Info.plist')
os.makedirs(dir_to_app + '/Contents/MacOS/')
shutil.copy2(dir_to_build + '/servo', dir_to_app + '/Contents/MacOS/')
print("Swapping prefs")
delete(dir_to_resources + '/prefs.json')
shutil.copy2(dir_to_resources + 'package-prefs.json', dir_to_resources + 'prefs.json')
delete(dir_to_resources + '/package-prefs.json')
print("Finding dylibs to be copied")
need = set([dir_to_app + '/Contents/MacOS/servo'])
done = set()
while need:
needed = set(need)
need = set()
for f in needed:
need.update(otool(f))
done.update(needed)
need.difference_update(done)
print("Copying dylibs")
for f in sorted(done):
if '/System/Library' not in f and '/usr/lib' not in f and 'servo' not in f:
shutil.copyfile(f, dir_to_app + '/Contents/MacOS/' + f.split('/')[-1])
install_name_tool(f, f.split('/')[-1], dir_to_app + '/Contents/MacOS/servo')
print("Writing run-servo")
bhtml_path = path.join('${0%/*}/../Resources', browserhtml_path.split('/')[-1], 'out', 'index.html')
runservo = os.open(dir_to_app + '/Contents/MacOS/run-servo', os.O_WRONLY | os.O_CREAT, int("0755", 8))
os.write(runservo, '#!/bin/bash\nexec ${0%/*}/servo ' + bhtml_path)
os.close(runservo)
print("Creating dmg")
os.symlink('/Applications', dir_to_dmg + '/Applications')
dmg_path = '/'.join(dir_to_build.split('/')[:-1]) + '/'
dmg_path += datetime.utcnow().replace(microsecond=0).isoformat()
dmg_path += "-servo-tech-demo.dmg"
try:
subprocess.check_call(['hdiutil', 'create', '-volname', 'Servo', dmg_path, '-srcfolder', dir_to_dmg])
except subprocess.CalledProcessError as e:
print("Packaging MacOS dmg exited with return value %d" % e.returncode)
return e.returncode
print("Cleaning up")
delete(dir_to_dmg)
print("Packaged Servo into " + dmg_path)
else: else:
dir_to_package = '/'.join(binary_path.split('/')[:-1]) dir_to_package = '/'.join(binary_path.split('/')[:-1])
browserhtml_path = find_dep_path_newest('browserhtml', binary_path) browserhtml_path = find_dep_path_newest('browserhtml', binary_path)

View file

@ -0,0 +1,63 @@
{
"dom.bluetooth.enabled": false,
"dom.forcetouch.enabled": true,
"dom.mouseevent.which.enabled": false,
"dom.mozbrowser.enabled": true,
"dom.serviceworker.timeout_seconds": 60,
"dom.testable_crash.enabled": false,
"dom.testbinding.enabled": false,
"gfx.webrender.enabled": true,
"js.baseline.enabled": true,
"js.ion.enabled": true,
"js.asmjs.enabled": true,
"js.strict.enabled": false,
"js.strict.debug.enabled": false,
"js.throw_on_asmjs_validation_failure.enabled": false,
"js.native_regexp.enabled": true,
"js.parallel_parsing.enabled": true,
"js.ion.offthread_compilation.enabled": true,
"js.baseline.unsafe_eager_compilation.enabled": false,
"js.ion.unsafe_eager_compilation.enabled": false,
"js.discard_system_source.enabled": false,
"js.asyncstack.enabled": false,
"js.throw_on_debuggee_would_run.enabled": false,
"js.dump_stack_on_debuggee_would_run.enabled": false,
"js.werror.enabled": false,
"js.strict.enabled": false,
"js.shared_memory.enabled": true,
"js.mem.high_water_mark": 128,
"js.mem.max": -1,
"js.mem.gc.per_compartment.enabled": true,
"js.mem.gc.incremental.enabled": true,
"js.mem.gc.incremental.slice_ms": 10,
"js.mem.gc.compacting.enabled": true,
"js.mem.gc.high_frequency_time_limit_ms": 1000,
"js.mem.gc.dynamic_mark_slice.enabled": true,
"js.mem.gc.refresh_frame_slices.enabled": true,
"js.mem.gc.dynamic_heap_growth.enabled": true,
"js.mem.gc.low_frequency_heap_growth": 150,
"js.mem.gc.high_frequency_heap_growth_min": 150,
"js.mem.gc.high_frequency_heap_growth_max": 300,
"js.mem.gc.high_frequency_low_limit_mb": 100,
"js.mem.gc.high_frequency_high_limit_mb": 500,
"js.mem.gc.allocation_threshold_mb": 30,
"js.mem.gc.decommit_threshold_mb": 32,
"js.mem.gc.empty_chunk_count_min": 1,
"js.mem.gc.empty_chunk_count_max": 30,
"js.mem.gc.zeal.level": 0,
"js.mem.gc.zeal.frequency": 100,
"layout.columns.enabled": false,
"layout.column-width.enabled": false,
"layout.column-count.enabled": false,
"layout.column-gap.enabled": false,
"layout.flex.enabled": false,
"layout.flex-direction.enabled": false,
"layout.text-orientation.enabled": false,
"layout.viewport.enabled": false,
"layout.writing-mode.enabled": false,
"network.http.redirection-limit": 20,
"network.mime.sniff": false,
"shell.homepage": "https://servo.org",
"shell.native-titlebar.enabled": false,
"shell.builtin-key-shortcuts.enabled": false
}

BIN
resources/servo.icns Normal file

Binary file not shown.