blob: 379bd6d8f1f453bb330d4f206ab7f84da438b75d [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2013, 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.
# A script which will be invoked from gyp to create a build of the editor.
# TODO(devoncarew): currently this script is not callable from tools/
# Usage: ./tools/ editor
# -or-
# Usage: ./tools/ [--mode <mode>] [--arch <arch>] output
import glob
import optparse
import os
import shutil
import subprocess
import sys
import utils
import zipfile
from os.path import join
'win32': 'win32, win32',
'linux': 'linux, gtk',
'macos': 'macosx, cocoa'
'ia32': 'x86',
'x64': 'x86_64'
def AntPath():
parent = join('third_party', 'apache_ant', '1.8.4', 'bin')
if utils.IsWindows():
return join(parent, 'ant.bat')
return join(parent, 'ant')
def ProcessEditorArchive(archive, outDir):
tempDir = join(GetEditorTemp(), 'editor.out')
if utils.IsWindows():
f = zipfile.ZipFile(archive)
else:['unzip', '-q', archive, '-d', tempDir])
for src in glob.glob(join(tempDir, 'dart', '*')):
shutil.move(src, outDir)
def GetEditorTemp():
return join(GetBuildRoot(), '')
def GetDownloadCache():
return GetEclipseBuildRoot()
def GetBuildRoot():
return os.path.abspath(utils.GetBuildRoot(utils.GuessOS()))
def GetEclipseBuildRoot():
return join(GetBuildRoot(), '')
def GetSdkPath():
return join(os.path.dirname(OUTPUT), 'dart-sdk')
def GetOutputParent():
return os.path.dirname(os.path.dirname(OUTPUT))
def BuildOptions():
options = optparse.OptionParser(usage='usage: %prog [options] <output>')
options.add_option("-m", "--mode",
help='Build variant',
options.add_option("-a", "--arch",
help='Target architecture',
return options
def Main():
global OUTPUT
parser = BuildOptions()
(options, args) = parser.parse_args()
if len(args) > 1:
return 1
osName = utils.GuessOS()
mode = 'debug'
arch = utils.GuessArchitecture()
if args:
# TODO(devoncarew): Currently we scrape the output path to determine the
# mode and arch. This is fragile and should moved into one location
# ( or made more explicit.
OUTPUT = args[0]
mode = ('release', 'debug')['Debug' in OUTPUT]
arch = ('ia32', 'x64')['X64' in OUTPUT]
# Use explicit mode and arch information.
if options.mode:
mode = options.mode
if options.arch:
arch = options.arch
# If an output dir was not given, create one from os, mode, and arch.
if not OUTPUT:
OUTPUT = join(utils.GetBuildRoot(osName, mode, arch), 'editor')
OUTPUT = os.path.abspath(OUTPUT)
print "\nBuilding the editor"
print " config : %s, %s, %s" % (osName, arch, mode)
print " output : %s" % OUTPUT
# Clean the editor output directory.
print ' cleaning %s' % OUTPUT
shutil.rmtree(OUTPUT, True)
# These are the valid eclipse build configurations that we can produce.
# We synthesize these up from the OS_CONFIG and ARCH_CONFIG information.
# macosx, cocoa, x86 & macosx, cocoa, x86_64
# win32, win32, x86 & win32, win32, x86_64
# linux, gtk, x86 & linux, gtk, x86_64
buildConfig = OS_CONFIG[osName] + ', ' + ARCH_CONFIG[arch]
print "\ninvoking build_rcp.xml with buildConfig = [%s]\n" % buildConfig
buildScript = join('editor', 'tools', 'features',
buildRcpStatus =
join('third_party', 'bzip2', 'bzip2.jar'),
'-Dbuild.out=' + OUTPUT,
'-Dbuild.configs=' + buildConfig,
'-Dbuild.revision=' + utils.GetSVNRevision(),
'-Ddart.version.full=' + utils.GetVersion(),
'-Dbuild.root=' + GetEclipseBuildRoot(),
'-Dbuild.downloads=' + GetDownloadCache(),
'-Dbuild.source=' + os.path.abspath('editor'),
'-Dbuild.dart.sdk=' + GetSdkPath(),
if buildRcpStatus != 0:
# build_rcp.xml will put the built editor archive in the OUTPUT directory
# ( It contains the editor application in a
# dart/ subdirectory. We unzip the contents of the archive into OUTPUT. It
# will use the ../dart-sdk directory as its SDK.
archives = glob.glob(join(OUTPUT, '*.zip'))
if archives:
ProcessEditorArchive(archives[0], OUTPUT)
if os.path.exists(GetEditorTemp()):
print('\nEditor build successful')
if __name__ == '__main__':