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