| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright (c) 2012, 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/build.py editor |
| 10 # ./tools/build_editor.py <output> |
| 11 |
| 12 import glob |
| 13 import os |
| 14 import shutil |
| 15 import subprocess |
| 16 import sys |
| 17 import utils |
| 18 import zipfile |
| 19 |
| 20 from os.path import join |
| 21 |
| 22 OUTPUT = None |
| 23 BUILDER_CLOBBER = 'BUILDBOT_CLOBBER' |
| 24 |
| 25 OS_CONFIG = { |
| 26 'win32': 'win32, win32', |
| 27 'linux': 'linux, gtk', |
| 28 'macos': 'macosx, cocoa' |
| 29 } |
| 30 |
| 31 ARCH_CONFIG = { |
| 32 'ia32': 'x86', |
| 33 'x64': 'x86_64' |
| 34 } |
| 35 |
| 36 def Main(argv): |
| 37 global OUTPUT |
| 38 |
| 39 OUTPUT = argv[1] |
| 40 |
| 41 osName = utils.GuessOS() |
| 42 mode = 'release' |
| 43 arch = 'ia32' |
| 44 |
| 45 if 'DebugIA32' in OUTPUT: |
| 46 mode = 'debug' |
| 47 elif 'ReleaseX64' in OUTPUT: |
| 48 arch = 'x64' |
| 49 elif 'DebugX64' in OUTPUT: |
| 50 mode = 'debug' |
| 51 arch = 'x64' |
| 52 |
| 53 print "\nBuilding the editor" |
| 54 print " config : %s, %s, %s" % (osName, arch, mode) |
| 55 print " output : %s" % OUTPUT |
| 56 |
| 57 if GetShouldClobber(): |
| 58 shutil.rmtree(OUTPUT, True) |
| 59 shutil.rmtree(GetDownloadCache(), True) |
| 60 shutil.rmtree(GetEditorTemp(), True) |
| 61 shutil.rmtree(GetEclipseBuildRoot(), True) |
| 62 else: |
| 63 DeleteDirContents(OUTPUT) |
| 64 |
| 65 # macosx, cocoa, x86 & macosx, cocoa, x86_64 |
| 66 # win32, win32, x86 & win32, win32, x86_64 |
| 67 # linux, gtk, x86 & linux, gtk, x86_64 |
| 68 |
| 69 buildConfig = OS_CONFIG[osName] + ', ' + ARCH_CONFIG[arch] |
| 70 |
| 71 print "\ninvoking build_rcp.xml with buildConfig = [%s]\n" % buildConfig |
| 72 |
| 73 sys.stdout.flush() |
| 74 sys.stderr.flush() |
| 75 |
| 76 buildScript = join('editor', 'tools', 'features', |
| 77 'com.google.dart.tools.deploy.feature_releng', |
| 78 'build_rcp.xml') |
| 79 |
| 80 buildRcpStatus = subprocess.call( |
| 81 [AntPath(), |
| 82 '-lib', |
| 83 join('third_party', 'bzip2', 'bzip2.jar'), |
| 84 '-Dbuild.out=' + OUTPUT, |
| 85 '-Dbuild.configs=' + buildConfig, |
| 86 '-Dbuild.revision=' + utils.GetSVNRevision(), |
| 87 '-Ddart.version.full=' + utils.GetVersion(), |
| 88 '-Dbuild.root=' + GetEclipseBuildRoot(), |
| 89 '-Dbuild.downloads=' + GetDownloadCache(), |
| 90 '-Dbuild.source=' + os.path.abspath('editor'), |
| 91 '-Dbuild.dart.sdk=' + GetSdkPath(), |
| 92 '-Dbuild.no.properties=true', |
| 93 '-buildfile', |
| 94 buildScript], |
| 95 shell=utils.IsWindows()) |
| 96 |
| 97 if buildRcpStatus != 0: |
| 98 sys.exit(buildRcpStatus) |
| 99 |
| 100 # build_rcp.xml will put the built editor archive in the OUTPUT directory |
| 101 # (dart-editor-macosx.cocoa.x86.zip). It contains the editor application in a |
| 102 # dart/ subdirectory. We unzip the contents of the archive into OUTPUT. It |
| 103 # will use the ../dart-sdk directory as its SDK. |
| 104 archives = glob.glob(join(OUTPUT, '*.zip')) |
| 105 |
| 106 if (archives): |
| 107 ProcessEditorArchive(archives[0], OUTPUT) |
| 108 |
| 109 if os.path.exists(GetEditorTemp()): |
| 110 shutil.rmtree(GetEditorTemp()) |
| 111 |
| 112 print('\nEditor build successful') |
| 113 |
| 114 |
| 115 def AntPath(): |
| 116 parent = join('third_party', 'apache_ant', 'v1_7_1', 'bin') |
| 117 if utils.IsWindows(): |
| 118 return join(parent, 'ant.bat') |
| 119 else: |
| 120 return join(parent, 'ant') |
| 121 |
| 122 |
| 123 def ProcessEditorArchive(archive, outDir): |
| 124 tempDir = join(GetEditorTemp(), 'editor.out') |
| 125 os.makedirs(tempDir) |
| 126 |
| 127 if utils.IsWindows(): |
| 128 f = zipfile.ZipFile(archive) |
| 129 f.extractall(tempDir) |
| 130 else: |
| 131 subprocess.call(['unzip', '-q', archive, '-d', tempDir]) |
| 132 |
| 133 for src in glob.glob(join(tempDir, 'dart', '*')): |
| 134 shutil.move(src, outDir) |
| 135 |
| 136 shutil.rmtree(tempDir) |
| 137 os.unlink(archive) |
| 138 |
| 139 |
| 140 def GetEditorTemp(): |
| 141 return join(GetOutputParent(), 'editor.build.temp') |
| 142 |
| 143 |
| 144 def GetDownloadCache(): |
| 145 return join(os.path.expanduser('~'), '.editor.download.cache') |
| 146 |
| 147 |
| 148 def GetEclipseBuildRoot(): |
| 149 return join(GetOutputParent(), 'editor.build.cache') |
| 150 |
| 151 |
| 152 def GetSdkPath(): |
| 153 return join(os.path.dirname(OUTPUT), 'dart-sdk') |
| 154 |
| 155 |
| 156 def GetOutputParent(): |
| 157 return os.path.dirname(os.path.dirname(OUTPUT)) |
| 158 |
| 159 |
| 160 def DeleteDirContents(directory): |
| 161 for root, dirs, files in os.walk(directory): |
| 162 for f in files: |
| 163 os.unlink(join(root, f)) |
| 164 for d in dirs: |
| 165 shutil.rmtree(join(root, d)) |
| 166 |
| 167 |
| 168 def GetShouldClobber(): |
| 169 return os.environ.get(BUILDER_CLOBBER) == "1" |
| 170 |
| 171 |
| 172 if __name__ == '__main__': |
| 173 sys.exit(Main(sys.argv)) |
| OLD | NEW |