OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
4 # for details. All rights reserved. Use of this source code is governed by a | |
5 # BSD-style license that can be found in the LICENSE file. | |
6 # | |
7 # A script which will be invoked from gyp to create a build of the editor. | |
8 # | |
9 # Usage: ./tools/create_editor.py | |
10 # [--mode <mode>] [--arch <arch>] [--out <output>] [--build <build>] | |
11 # | |
12 # DO NOT CALL THIS SCRIPT DIRECTLY, instead invoke: | |
13 # ./tools/build.py -mrelease editor | |
14 | |
15 import glob | |
16 import optparse | |
17 import os | |
18 import shutil | |
19 import subprocess | |
20 import sys | |
21 import utils | |
22 import zipfile | |
23 | |
24 from os.path import join | |
25 | |
26 OUTPUT = None | |
27 BUILD = None | |
28 | |
29 OS_CONFIG = { | |
30 'win32': 'win32, win32', | |
31 'linux': 'linux, gtk', | |
32 'macos': 'macosx, cocoa' | |
33 } | |
34 | |
35 ARCH_CONFIG = { | |
36 'ia32': 'x86', | |
37 'x64': 'x86_64' | |
38 } | |
39 | |
40 def AntPath(): | |
41 parent = join('third_party', 'apache_ant', '1.8.4', 'bin') | |
42 if utils.IsWindows(): | |
43 return join(parent, 'ant.bat') | |
44 else: | |
45 return join(parent, 'ant') | |
46 | |
47 | |
48 def ProcessEditorArchive(arch, archive, outDir): | |
49 tempDir = join(GetEditorTemp(), 'editor.out') | |
50 try: | |
51 os.makedirs(tempDir) | |
52 except OSError: | |
53 # Directory already exists. | |
54 pass | |
55 | |
56 if utils.IsWindows(): | |
57 f = zipfile.ZipFile(archive) | |
58 f.extractall(tempDir) | |
59 f.close() | |
60 else: | |
61 subprocess.call(['unzip', '-q', archive, '-d', tempDir]) | |
62 | |
63 if arch == 'x64': | |
64 if utils.GuessOS() == 'macos': | |
65 inifile = join(tempDir, 'dart', 'DartEditor.app', 'Contents', 'MacOS', | |
66 'DartEditor.ini') | |
67 else: | |
68 inifile = join(tempDir, 'dart', 'DartEditor.ini') | |
69 Modify64BitDartEditorIni(inifile) | |
70 | |
71 for src in glob.glob(join(tempDir, 'dart', '*')): | |
72 shutil.move(src, outDir) | |
73 | |
74 shutil.rmtree(tempDir) | |
75 os.unlink(archive) | |
76 | |
77 | |
78 def Modify64BitDartEditorIni(iniFilePath): | |
79 f = open(iniFilePath, 'r') | |
80 lines = f.readlines() | |
81 f.close() | |
82 lines[lines.index('-Xms40m\n')] = '-Xms256m\n' | |
83 lines[lines.index('-Xmx1024m\n')] = '-Xmx2000m\n' | |
84 # Add -d64 to give better error messages to user in 64 bit mode. | |
85 lines[lines.index('-vmargs\n')] = '-vmargs\n-d64\n' | |
86 f = open(iniFilePath, 'w') | |
87 f.writelines(lines) | |
88 f.close() | |
89 | |
90 | |
91 def GetEditorTemp(): | |
92 return join(BUILD, 'editor.build.temp') | |
93 | |
94 | |
95 def GetDownloadCache(): | |
96 return GetEclipseBuildRoot() | |
97 | |
98 | |
99 def GetEclipseBuildRoot(): | |
100 return join(BUILD, 'editor.build.cache') | |
101 | |
102 | |
103 def GetSdkPath(): | |
104 return join(os.path.dirname(OUTPUT), 'dart-sdk') | |
105 | |
106 | |
107 def GetOutputParent(): | |
108 return os.path.dirname(os.path.dirname(OUTPUT)) | |
109 | |
110 | |
111 def BuildOptions(): | |
112 options = optparse.OptionParser(usage='usage: %prog [options] <output>') | |
113 options.add_option("-m", "--mode", metavar='[debug,release]') | |
114 options.add_option("-a", "--arch", metavar='[ia32,x64]') | |
115 options.add_option("-o", "--out") | |
116 options.add_option("-b", "--build") | |
117 return options | |
118 | |
119 | |
120 def Main(): | |
121 global OUTPUT | |
122 global BUILD | |
123 | |
124 parser = BuildOptions() | |
125 (options, args) = parser.parse_args() | |
126 | |
127 if args: | |
128 parser.print_help() | |
129 return 1 | |
130 | |
131 osName = utils.GuessOS() | |
132 mode = 'debug' | |
133 arch = utils.GuessArchitecture() | |
134 | |
135 if not options.build: | |
136 print >> sys.stderr, 'Error: no --build option specified' | |
137 exit(1) | |
138 else: | |
139 BUILD = options.build | |
140 | |
141 if not options.out: | |
142 print >> sys.stderr, 'Error: no --out option specified' | |
143 exit(1) | |
144 else: | |
145 # TODO(devoncarew): Currently we scrape the output path to determine the | |
146 # mode and arch. This is fragile and should moved into one location | |
147 # (utils.py?) or made more explicit. | |
148 OUTPUT = options.out | |
149 mode = ('release', 'debug')['Debug' in OUTPUT] | |
150 arch = ('ia32', 'x64')['X64' in OUTPUT] | |
151 | |
152 # Use explicit mode and arch information. | |
153 if options.mode: | |
154 mode = options.mode | |
155 if options.arch: | |
156 arch = options.arch | |
157 | |
158 OUTPUT = os.path.abspath(OUTPUT) | |
159 BUILD = os.path.abspath(BUILD) | |
160 | |
161 print "\nBuilding the editor" | |
162 print " config : %s, %s, %s" % (osName, arch, mode) | |
163 print " output : %s" % OUTPUT | |
164 | |
165 # Clean the editor output directory. | |
166 print '\ncleaning %s' % OUTPUT | |
167 shutil.rmtree(OUTPUT, True) | |
168 | |
169 # These are the valid eclipse build configurations that we can produce. | |
170 # We synthesize these up from the OS_CONFIG and ARCH_CONFIG information. | |
171 # macosx, cocoa, x86 & macosx, cocoa, x86_64 | |
172 # win32, win32, x86 & win32, win32, x86_64 | |
173 # linux, gtk, x86 & linux, gtk, x86_64 | |
174 | |
175 buildConfig = OS_CONFIG[osName] + ', ' + ARCH_CONFIG[arch] | |
176 | |
177 print "\ninvoking build_rcp.xml with buildConfig = [%s]\n" % buildConfig | |
178 | |
179 sys.stdout.flush() | |
180 sys.stderr.flush() | |
181 | |
182 buildScript = join('editor', 'tools', 'features', | |
183 'com.google.dart.tools.deploy.feature_releng', | |
184 'build_rcp.xml') | |
185 build_cmd = [AntPath(), | |
186 '-lib', | |
187 join('third_party', 'bzip2', 'bzip2.jar'), | |
188 '-Dbuild.out=' + OUTPUT, | |
189 '-Dbuild.configs=' + buildConfig, | |
190 '-Dbuild.root=' + GetEclipseBuildRoot(), | |
191 '-Dbuild.downloads=' + GetDownloadCache(), | |
192 '-Dbuild.source=' + os.path.abspath('editor'), | |
193 '-Dbuild.dart.sdk=' + GetSdkPath(), | |
194 '-Dbuild.no.properties=true', | |
195 '-Dbuild.channel=' + utils.GetChannel(), | |
196 '-Dbuild.revision=' + utils.GetSVNRevision(), | |
197 '-Dbuild.version.qualifier=' + utils.GetEclipseVersionQualifier(), | |
198 '-Ddart.version.full=' + utils.GetVersion(), | |
199 '-buildfile', | |
200 buildScript] | |
201 print build_cmd | |
202 buildRcpStatus = subprocess.call(build_cmd, shell=utils.IsWindows()) | |
203 | |
204 if buildRcpStatus != 0: | |
205 sys.exit(buildRcpStatus) | |
206 | |
207 # build_rcp.xml will put the built editor archive in the OUTPUT directory | |
208 # (dart-editor-macosx.cocoa.x86.zip). It contains the editor application in a | |
209 # dart/ subdirectory. We unzip the contents of the archive into OUTPUT. It | |
210 # will use the ../dart-sdk directory as its SDK. | |
211 archives = glob.glob(join(OUTPUT, 'd*.zip')) | |
212 | |
213 if archives: | |
214 ProcessEditorArchive(arch, archives[0], OUTPUT) | |
215 | |
216 if os.path.exists(GetEditorTemp()): | |
217 shutil.rmtree(GetEditorTemp()) | |
218 | |
219 print('\nEditor build successful') | |
220 | |
221 | |
222 if __name__ == '__main__': | |
223 sys.exit(Main()) | |
OLD | NEW |