forked from dart-lang/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildapp.py
executable file
·80 lines (59 loc) · 2.65 KB
/
buildapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
#!/usr/bin/env python3
#
# This script builds a Chrome App file (.crx) for Swarm
import os
import platform
import subprocess
import sys
DART_PATH = os.path.normpath(os.path.dirname(__file__) + '/../../..')
CLIENT_PATH = os.path.normpath(DART_PATH + '/client')
# Add the tools directory so we can find utils.py.
sys.path.append(os.path.abspath(DART_PATH + '/tools'))
import utils
buildRoot = CLIENT_PATH + '/' + utils.GetBuildRoot(utils.GuessOS(), 'debug',
'dartc')
def execute(*command):
'''
Executes the given command in a new process. If the command fails (returns
non-zero) halts the script and returns that exit code.
'''
exitcode = subprocess.call(command)
if exitcode != 0:
sys.exit(exitcode)
def createChromeApp(buildRoot, antTarget, resultFile):
buildDir = os.path.join(buildRoot, 'war')
# Use ant to create the 'war' directory
# TODO(jmesserly): we should factor out as much as possible from the ant file
# It's not really doing anything useful for us besides compiling Dart code
# with DartC and copying files. But for now, it helps us share code with
# our appengine update.py, which is good.
execute(DART_PATH + '/third_party/apache_ant/v1_7_1/bin/ant', '-f',
'build-appengine.xml', '-Dbuild.dir=' + buildRoot, antTarget)
# Call Dartium (could be any Chrome--but we know Dartium will be there) and
# ask it to create the .crx file for us using the checked in developer key.
chrome = CLIENT_PATH + '/tests/drt/chrome'
# On Mac Chrome is under a .app folder
if platform.system() == 'Darwin':
chrome = CLIENT_PATH + '/tests/drt/Chromium.app/Contents/MacOS/Chromium'
keyFile = DART_PATH + '/samples/swarm/swarm-dev.pem'
execute(chrome, '--pack-extension=' + buildDir,
'--pack-extension-key=' + keyFile)
resultFile = os.path.join(buildRoot, resultFile)
os.rename(buildDir + '.crx', resultFile)
return os.path.abspath(resultFile)
def main():
# Create a DartC and Dartium app
dartiumResult = createChromeApp(buildRoot, 'build_dart_app', 'swarm.crx')
dartCResult = createChromeApp(buildRoot, 'build_js_app', 'swarm-js.crx')
print('''
Successfully created Chrome apps!
Dartium: file://%s
DartC/JS: file://%s
To install, open this URL in Chrome and select Continue at the bottom.
''' % (dartiumResult, dartCResult))
return 0
if __name__ == '__main__':
sys.exit(main())