OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 5 # BSD-style license that can be found in the LICENSE file. |
6 # | 6 # |
7 # A script which will be invoked from gyp to create a build of the editor. | 7 # A script which will be invoked from gyp to create a build of the editor. |
8 # | 8 # |
9 # TODO(devoncarew): currently this script is not callable from tools/build.py | 9 # Usage: ./tools/create_editor.py |
10 # Usage: ./tools/build.py editor | 10 # [--mode <mode>] [--arch <arch>] [--out <output>] [--build <build>] |
11 # -or- | 11 # |
12 # Usage: ./tools/build_editor.py [--mode <mode>] [--arch <arch>] output | 12 # DO NOT CALL THIS SCRIPT DIRECTLY, instead invoke: |
| 13 # ./tools/build.py -mrelease editor |
13 | 14 |
14 import glob | 15 import glob |
15 import optparse | 16 import optparse |
16 import os | 17 import os |
17 import shutil | 18 import shutil |
18 import subprocess | 19 import subprocess |
19 import sys | 20 import sys |
20 import utils | 21 import utils |
21 import zipfile | 22 import zipfile |
22 | 23 |
23 from os.path import join | 24 from os.path import join |
24 | 25 |
25 OUTPUT = None | 26 OUTPUT = None |
| 27 BUILD = None |
26 | 28 |
27 OS_CONFIG = { | 29 OS_CONFIG = { |
28 'win32': 'win32, win32', | 30 'win32': 'win32, win32', |
29 'linux': 'linux, gtk', | 31 'linux': 'linux, gtk', |
30 'macos': 'macosx, cocoa' | 32 'macos': 'macosx, cocoa' |
31 } | 33 } |
32 | 34 |
33 ARCH_CONFIG = { | 35 ARCH_CONFIG = { |
34 'ia32': 'x86', | 36 'ia32': 'x86', |
35 'x64': 'x86_64' | 37 'x64': 'x86_64' |
(...skipping 18 matching lines...) Expand all Loading... |
54 subprocess.call(['unzip', '-q', archive, '-d', tempDir]) | 56 subprocess.call(['unzip', '-q', archive, '-d', tempDir]) |
55 | 57 |
56 for src in glob.glob(join(tempDir, 'dart', '*')): | 58 for src in glob.glob(join(tempDir, 'dart', '*')): |
57 shutil.move(src, outDir) | 59 shutil.move(src, outDir) |
58 | 60 |
59 shutil.rmtree(tempDir) | 61 shutil.rmtree(tempDir) |
60 os.unlink(archive) | 62 os.unlink(archive) |
61 | 63 |
62 | 64 |
63 def GetEditorTemp(): | 65 def GetEditorTemp(): |
64 return join(GetBuildRoot(), 'editor.build.temp') | 66 return join(BUILD, 'editor.build.temp') |
65 | 67 |
66 | 68 |
67 def GetDownloadCache(): | 69 def GetDownloadCache(): |
68 return GetEclipseBuildRoot() | 70 return GetEclipseBuildRoot() |
69 | 71 |
70 | 72 |
71 def GetBuildRoot(): | |
72 return os.path.abspath(utils.GetBuildRoot(utils.GuessOS())) | |
73 | |
74 | |
75 def GetEclipseBuildRoot(): | 73 def GetEclipseBuildRoot(): |
76 return join(GetBuildRoot(), 'editor.build.cache') | 74 return join(BUILD, 'editor.build.cache') |
77 | 75 |
78 | 76 |
79 def GetSdkPath(): | 77 def GetSdkPath(): |
80 return join(os.path.dirname(OUTPUT), 'dart-sdk') | 78 return join(os.path.dirname(OUTPUT), 'dart-sdk') |
81 | 79 |
82 | 80 |
83 def GetOutputParent(): | 81 def GetOutputParent(): |
84 return os.path.dirname(os.path.dirname(OUTPUT)) | 82 return os.path.dirname(os.path.dirname(OUTPUT)) |
85 | 83 |
86 | 84 |
87 def BuildOptions(): | 85 def BuildOptions(): |
88 options = optparse.OptionParser(usage='usage: %prog [options] <output>') | 86 options = optparse.OptionParser(usage='usage: %prog [options] <output>') |
89 options.add_option("-m", "--mode", | 87 options.add_option("-m", "--mode", metavar='[debug,release]') |
90 help='Build variant', | 88 options.add_option("-a", "--arch", metavar='[ia32,x64]') |
91 metavar='[debug,release]') | 89 options.add_option("-o", "--out") |
92 options.add_option("-a", "--arch", | 90 options.add_option("-b", "--build") |
93 help='Target architecture', | |
94 metavar='[ia32,x64]') | |
95 return options | 91 return options |
96 | 92 |
97 | 93 |
98 def Main(): | 94 def Main(): |
99 global OUTPUT | 95 global OUTPUT |
100 | 96 global BUILD |
| 97 |
101 parser = BuildOptions() | 98 parser = BuildOptions() |
102 (options, args) = parser.parse_args() | 99 (options, args) = parser.parse_args() |
103 | 100 |
104 if len(args) > 1: | 101 if args: |
105 parser.print_help() | 102 parser.print_help() |
106 return 1 | 103 return 1 |
107 | 104 |
108 osName = utils.GuessOS() | 105 osName = utils.GuessOS() |
109 mode = 'debug' | 106 mode = 'debug' |
110 arch = utils.GuessArchitecture() | 107 arch = utils.GuessArchitecture() |
111 | 108 |
112 if args: | 109 if not options.build: |
| 110 print >> sys.stderr, 'Error: no --build option specified' |
| 111 exit(1) |
| 112 else: |
| 113 BUILD = options.build |
| 114 |
| 115 if not options.out: |
| 116 print >> sys.stderr, 'Error: no --out option specified' |
| 117 exit(1) |
| 118 else: |
113 # TODO(devoncarew): Currently we scrape the output path to determine the | 119 # TODO(devoncarew): Currently we scrape the output path to determine the |
114 # mode and arch. This is fragile and should moved into one location | 120 # mode and arch. This is fragile and should moved into one location |
115 # (utils.py?) or made more explicit. | 121 # (utils.py?) or made more explicit. |
116 OUTPUT = args[0] | 122 OUTPUT = options.out |
117 | |
118 mode = ('release', 'debug')['Debug' in OUTPUT] | 123 mode = ('release', 'debug')['Debug' in OUTPUT] |
119 arch = ('ia32', 'x64')['X64' in OUTPUT] | 124 arch = ('ia32', 'x64')['X64' in OUTPUT] |
120 | 125 |
121 # Use explicit mode and arch information. | 126 # Use explicit mode and arch information. |
122 if options.mode: | 127 if options.mode: |
123 mode = options.mode | 128 mode = options.mode |
124 if options.arch: | 129 if options.arch: |
125 arch = options.arch | 130 arch = options.arch |
126 | 131 |
127 # If an output dir was not given, create one from os, mode, and arch. | |
128 if not OUTPUT: | |
129 OUTPUT = join(utils.GetBuildRoot(osName, mode, arch), 'editor') | |
130 | |
131 OUTPUT = os.path.abspath(OUTPUT) | 132 OUTPUT = os.path.abspath(OUTPUT) |
132 | 133 BUILD = os.path.abspath(BUILD) |
| 134 |
133 print "\nBuilding the editor" | 135 print "\nBuilding the editor" |
134 print " config : %s, %s, %s" % (osName, arch, mode) | 136 print " config : %s, %s, %s" % (osName, arch, mode) |
135 print " output : %s" % OUTPUT | 137 print " output : %s" % OUTPUT |
136 | 138 |
137 # Clean the editor output directory. | 139 # Clean the editor output directory. |
138 print ' cleaning %s' % OUTPUT | 140 print '\ncleaning %s' % OUTPUT |
139 shutil.rmtree(OUTPUT, True) | 141 shutil.rmtree(OUTPUT, True) |
140 | 142 |
141 # These are the valid eclipse build configurations that we can produce. | 143 # These are the valid eclipse build configurations that we can produce. |
142 # We synthesize these up from the OS_CONFIG and ARCH_CONFIG information. | 144 # We synthesize these up from the OS_CONFIG and ARCH_CONFIG information. |
143 # macosx, cocoa, x86 & macosx, cocoa, x86_64 | 145 # macosx, cocoa, x86 & macosx, cocoa, x86_64 |
144 # win32, win32, x86 & win32, win32, x86_64 | 146 # win32, win32, x86 & win32, win32, x86_64 |
145 # linux, gtk, x86 & linux, gtk, x86_64 | 147 # linux, gtk, x86 & linux, gtk, x86_64 |
146 | 148 |
147 buildConfig = OS_CONFIG[osName] + ', ' + ARCH_CONFIG[arch] | 149 buildConfig = OS_CONFIG[osName] + ', ' + ARCH_CONFIG[arch] |
148 | 150 |
149 print "\ninvoking build_rcp.xml with buildConfig = [%s]\n" % buildConfig | 151 print "\ninvoking build_rcp.xml with buildConfig = [%s]\n" % buildConfig |
150 | 152 |
151 sys.stdout.flush() | 153 sys.stdout.flush() |
152 sys.stderr.flush() | 154 sys.stderr.flush() |
153 | 155 |
154 buildScript = join('editor', 'tools', 'features', | 156 buildScript = join('editor', 'tools', 'features', |
155 'com.google.dart.tools.deploy.feature_releng', | 157 'com.google.dart.tools.deploy.feature_releng', |
156 'build_rcp.xml') | 158 'build_rcp.xml') |
157 | 159 build_cmd = [AntPath(), |
158 buildRcpStatus = subprocess.call( | |
159 [AntPath(), | |
160 '-lib', | 160 '-lib', |
161 join('third_party', 'bzip2', 'bzip2.jar'), | 161 join('third_party', 'bzip2', 'bzip2.jar'), |
162 '-Dbuild.out=' + OUTPUT, | 162 '-Dbuild.out=' + OUTPUT, |
163 '-Dbuild.configs=' + buildConfig, | 163 '-Dbuild.configs=' + buildConfig, |
164 '-Dbuild.revision=' + utils.GetSVNRevision(), | 164 '-Dbuild.revision=' + utils.GetSVNRevision(), |
165 '-Ddart.version.full=' + utils.GetVersion(), | 165 '-Ddart.version.full=' + utils.GetVersion(), |
166 '-Dbuild.root=' + GetEclipseBuildRoot(), | 166 '-Dbuild.root=' + GetEclipseBuildRoot(), |
167 '-Dbuild.downloads=' + GetDownloadCache(), | 167 '-Dbuild.downloads=' + GetDownloadCache(), |
168 '-Dbuild.source=' + os.path.abspath('editor'), | 168 '-Dbuild.source=' + os.path.abspath('editor'), |
169 '-Dbuild.dart.sdk=' + GetSdkPath(), | 169 '-Dbuild.dart.sdk=' + GetSdkPath(), |
170 '-Dbuild.no.properties=true', | 170 '-Dbuild.no.properties=true', |
171 '-buildfile', | 171 '-buildfile', |
172 buildScript], | 172 buildScript] |
173 shell=utils.IsWindows()) | 173 print build_cmd |
| 174 buildRcpStatus = subprocess.call(build_cmd, shell=utils.IsWindows()) |
174 | 175 |
175 if buildRcpStatus != 0: | 176 if buildRcpStatus != 0: |
176 sys.exit(buildRcpStatus) | 177 sys.exit(buildRcpStatus) |
177 | 178 |
178 # build_rcp.xml will put the built editor archive in the OUTPUT directory | 179 # build_rcp.xml will put the built editor archive in the OUTPUT directory |
179 # (dart-editor-macosx.cocoa.x86.zip). It contains the editor application in a | 180 # (dart-editor-macosx.cocoa.x86.zip). It contains the editor application in a |
180 # dart/ subdirectory. We unzip the contents of the archive into OUTPUT. It | 181 # dart/ subdirectory. We unzip the contents of the archive into OUTPUT. It |
181 # will use the ../dart-sdk directory as its SDK. | 182 # will use the ../dart-sdk directory as its SDK. |
182 archives = glob.glob(join(OUTPUT, '*.zip')) | 183 archives = glob.glob(join(OUTPUT, '*.zip')) |
183 | 184 |
184 if archives: | 185 if archives: |
185 ProcessEditorArchive(archives[0], OUTPUT) | 186 ProcessEditorArchive(archives[0], OUTPUT) |
186 | 187 |
187 if os.path.exists(GetEditorTemp()): | 188 if os.path.exists(GetEditorTemp()): |
188 shutil.rmtree(GetEditorTemp()) | 189 shutil.rmtree(GetEditorTemp()) |
189 | 190 |
190 print('\nEditor build successful') | 191 print('\nEditor build successful') |
191 | 192 |
192 | 193 |
193 if __name__ == '__main__': | 194 if __name__ == '__main__': |
194 sys.exit(Main()) | 195 sys.exit(Main()) |
OLD | NEW |