Build Tools Cleanup

Cleans up Python Code in Build Tools

TEST: build everything and run tests
BUG: https://code.google.com/p/dart/issues/detail?id=19592

R=ricow@google.com

Review URL: https://codereview.chromium.org//350483003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@38573 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
whesse@google.com 2014-07-25 11:47:59 +00:00
parent 172abd603f
commit c7d5711688
23 changed files with 547 additions and 558 deletions

View file

@ -11,7 +11,6 @@ Usage:
[linker args]
"""
import optparse
import os
import subprocess
import sys
@ -69,7 +68,7 @@ def main():
sys.exit(0)
# Set up path to the Android NDK.
CheckDirExists(THIRD_PARTY_ROOT, 'third party tools');
CheckDirExists(THIRD_PARTY_ROOT, 'third party tools')
android_tools = os.path.join(THIRD_PARTY_ROOT, 'android_tools')
CheckDirExists(android_tools, 'Android tools')
android_ndk_root = os.path.join(android_tools, 'ndk')

View file

@ -19,19 +19,19 @@ import uuid
GCS_FOLDER = 'dart-crashes'
def CreateTarball(dir, tarname):
print 'Creating tar file: %s' % (tarname)
def CreateTarball(input_dir, tarname):
print 'Creating tar file: %s' % tarname
tar = tarfile.open(tarname, mode='w:gz')
tar.add(dir)
tar.add(input_dir)
tar.close()
def CopyToGCS(filename):
gs_location = 'gs://%s/%s/' % (GCS_FOLDER, uuid.uuid4())
cmd = ['gsutil', 'cp', filename, gs_location]
print 'Running command: %s' % (cmd)
print 'Running command: %s' % cmd
subprocess.check_call(cmd)
archived_filename = '%s%s' % (gs_location, filename.split('/').pop())
print 'Dump now available in %s' % (archived_filename)
print 'Dump now available in %s' % archived_filename
def Main():
if utils.GuessOS() != 'linux':
@ -41,7 +41,7 @@ def Main():
num_dumps = 0
for v in os.listdir('/tmp'):
if v.startswith('coredump'):
fullpath = '/tmp/%s' % (v)
fullpath = '/tmp/%s' % v
if os.path.isdir(fullpath):
num_dumps += 1
tarname = '%s.tar.gz' % fullpath
@ -49,7 +49,7 @@ def Main():
CopyToGCS(tarname)
os.unlink(tarname)
shutil.rmtree(fullpath)
print 'Found %s core dumps' % (num_dumps)
print 'Found %s core dumps' % num_dumps
if __name__ == '__main__':
sys.exit(Main())

View file

@ -8,7 +8,6 @@
import optparse
import os
import re
import shutil
import subprocess
import sys
import time
@ -70,10 +69,10 @@ def BuildOptions():
return result
def ProcessOsOption(os):
if os == 'host':
def ProcessOsOption(os_name):
if os_name == 'host':
return HOST_OS
return os
return os_name
def ProcessOptions(options, args):
@ -96,26 +95,26 @@ def ProcessOptions(options, args):
if not arch in archs:
print "Unknown arch %s" % arch
return False
options.os = [ProcessOsOption(os) for os in options.os]
for os in options.os:
if not os in ['android', 'freebsd', 'linux', 'macos', 'win32']:
print "Unknown os %s" % os
options.os = [ProcessOsOption(os_name) for os_name in options.os]
for os_name in options.os:
if not os_name in ['android', 'freebsd', 'linux', 'macos', 'win32']:
print "Unknown os %s" % os_name
return False
if os != HOST_OS:
if os != 'android':
print "Unsupported target os %s" % os
if os_name != HOST_OS:
if os_name != 'android':
print "Unsupported target os %s" % os_name
return False
if not HOST_OS in ['linux']:
print ("Cross-compilation to %s is not supported on host os %s."
% (os, HOST_OS))
% (os_name, HOST_OS))
return False
if not arch in ['ia32', 'arm', 'mips']:
print ("Cross-compilation to %s is not supported for architecture %s."
% (os, arch))
% (os_name, arch))
return False
# We have not yet tweaked the v8 dart build to work with the Android
# NDK/SDK, so don't try to build it.
if args == []:
if not args:
print "For android builds you must specify a target, such as 'runtime'."
return False
return True
@ -146,7 +145,6 @@ def GetToolchainPrefix(target_os, arch, options):
return None
def SetTools(arch, target_os, options):
toolsOverride = None
@ -185,7 +183,7 @@ def GetAndroidToolchainDir(host_os, target_arch):
raise Exception('Unsupported target architecture %s' % target_arch)
# Set up path to the Android NDK.
CheckDirExists(THIRD_PARTY_ROOT, 'third party tools');
CheckDirExists(THIRD_PARTY_ROOT, 'third party tools')
android_tools = os.path.join(THIRD_PARTY_ROOT, 'android_tools')
CheckDirExists(android_tools, 'Android tools')
android_ndk_root = os.path.join(android_tools, 'ndk')
@ -242,9 +240,9 @@ PhaseScriptExecution "Action \"upload_sdk_py\"" xcodebuild/dart.build/...
"""
def is_empty_chunk(chunk):
def is_empty_chunk(input):
empty_chunk = ['', 'Check dependencies', '']
return not chunk or (len(chunk) == 4 and chunk[1:] == empty_chunk)
return not input or (len(input) == 4 and input[1:] == empty_chunk)
def unbuffered(callable):
# Use iter to disable buffering in for-in.
@ -322,7 +320,7 @@ def NotifyBuildDone(build_config, success, start):
# Display a notification if build time exceeded DART_BUILD_NOTIFICATION_DELAY.
notification_delay = float(
os.getenv('DART_BUILD_NOTIFICATION_DELAY', default=sys.float_info.max))
os.getenv('DART_BUILD_NOTIFICATION_DELAY', sys.float_info.max))
if (time.time() - start) < notification_delay:
return
@ -534,7 +532,8 @@ def Main():
if BuildCrossSdk(options, target_os, mode, arch) != 0:
return 1
else:
if BuildOneConfig(options, target, target_os, mode, arch, cross_build) != 0:
if BuildOneConfig(options, target, target_os,
mode, arch, cross_build) != 0:
return 1
return 0

View file

@ -2,7 +2,7 @@
# 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.
# This python script compiles a set of java files and puts them all into a
# This python script compiles a set of java files and puts them all into a
# single .jar file.
import os
@ -13,7 +13,7 @@ from optparse import OptionParser
# Filters out all arguments until the next '--' argument
# occurs.
def ListArgCallback(option, opt_str, value, parser):
def ListArgCallback(option, value, parser):
if value is None:
value = []
@ -45,7 +45,7 @@ def javaCompile(javac, srcDirectories, srcList, classpath,
javaFilesTempFile = os.fdopen(tempFileDescriptor, "w")
try:
if srcDirectories:
def findJavaFiles(arg, dirName, names):
def findJavaFiles(dirName, names):
for fileName in names:
(base, ext) = os.path.splitext(fileName)
if ext == '.java':
@ -63,11 +63,9 @@ def javaCompile(javac, srcDirectories, srcList, classpath,
javaFilesTempFile.close()
# Prepare javac command.
command = [javac]
# Use a large enough heap to be able to compile all of the classes in one
# big compilation step.
command.append('-J-Xmx256m')
command = [javac, '-J-Xmx256m']
if buildConfig == 'Debug':
command.append('-g')
@ -102,16 +100,16 @@ def javaCompile(javac, srcDirectories, srcList, classpath,
os.remove(javaFilesTempFileName)
def copyProperties(propertyFiles, classOutputDir):
for file in propertyFiles:
if not os.path.isfile(file):
sys.stderr.write('property file not found: ' + file + '\n')
for property_file in propertyFiles:
if not os.path.isfile(property_file):
sys.stderr.write('property file not found: ' + property_file + '\n')
return False
if not os.path.exists(classOutputDir):
sys.stderr.write('classes dir not found: ' + classOutputDir + '\n')
return False
if propertyFiles == []:
if not propertyFiles:
return True
command = ['cp'] + propertyFiles + [classOutputDir]
@ -136,7 +134,7 @@ def createJar(classOutputDir, jarFileName):
return True
def main(args):
def main():
try:
# Parse input.
parser = OptionParser()
@ -180,7 +178,7 @@ def main(args):
sys.stderr.write('--jarFileName not specified\n')
return -1
if len(options.sourceDirs) > 0 and options.sourceList:
sys.stderr.write("--sourceDir and --sourceList cannot be both specified");
sys.stderr.write("--sourceDir and --sourceList cannot be both specified")
return -1
# Compile and put into .jar file.
@ -201,4 +199,4 @@ def main(args):
return -1
if __name__ == '__main__':
sys.exit(main(sys.argv))
sys.exit(main())

View file

@ -94,7 +94,7 @@ class Generator:
def generate(self):
self._list_files()
file_name = self.output + '.gypi';
file_name = self.output + '.gypi'
gypi = self._make_output(file_name)
gypi.write("{\n 'variables': {\n")
self._print_gypi_files(gypi, self.name + '_sources', self.sources)
@ -110,7 +110,7 @@ class Generator:
ant.write("</project>\n")
self._close(file_name, ant)
file_name = self.output + '.txt';
file_name = self.output + '.txt'
txt = self._make_output(file_name)
self._print_txt_files(txt, self.sources)
self._close(file_name, txt)

View file

@ -6,10 +6,9 @@
import fileinput
import sys
import shutil
import os
import re
from os.path import abspath, basename, dirname, exists, isabs, join
from os.path import basename, dirname, exists, isabs, join
from glob import glob
re_directive = re.compile(
@ -76,7 +75,7 @@ def mergefiles(srcs, dstfile):
def main(outdir = None, *inputs):
if not outdir or not inputs:
print "Usage: %s OUTDIR INPUTS" % args[0]
print "Usage: %s OUTDIR INPUTS" % sys.argv[0]
print " OUTDIR is the war directory to copy to"
print " INPUTS is a list of files or patterns used to specify the input"
print " .dart files"
@ -124,7 +123,7 @@ def main(outdir = None, *inputs):
else:
f.write("library %s;\n\n" % basename(lib))
for importfile in library.imports:
f.write("import %s;\n" % (importfile))
f.write("import %s;\n" % importfile)
f.write('%s' % (''.join(library.code)))
mergefiles([normjoin(dirname(lib), s) for s in library.sources], f)
@ -132,7 +131,7 @@ def main(outdir = None, *inputs):
m = re.match(r'[\'"]([^\'"]+)[\'"](\s+as\s+\w+)?.*$', suffix)
uri = m.group(1)
if not uri.startswith('dart:'):
worklist.append(normjoin(dirname(lib), uri));
worklist.append(normjoin(dirname(lib), uri))
return 0

View file

@ -10,12 +10,10 @@
# binary packages.
import optparse
import platform
import sys
import tarfile
import subprocess
import utils
import os
from os.path import join, exists, abspath
from shutil import copyfile
@ -67,17 +65,17 @@ def BuildDebianPackage(tarball, out_dir, arch):
# Build source package.
print "Building source package"
RunBuildPackage(['-S', '-us', '-uc'], join(temp_dir, tarroot));
RunBuildPackage(['-S', '-us', '-uc'], join(temp_dir, tarroot))
# Build 32-bit binary package.
if ('ia32' in arch):
if 'ia32' in arch:
print "Building i386 package"
RunBuildPackage(['-B', '-ai386', '-us', '-uc'], join(temp_dir, tarroot));
RunBuildPackage(['-B', '-ai386', '-us', '-uc'], join(temp_dir, tarroot))
# Build 64-bit binary package.
if ('x64' in arch):
if 'x64' in arch:
print "Building amd64 package"
RunBuildPackage(['-B', '-aamd64', '-us', '-uc'], join(temp_dir, tarroot));
RunBuildPackage(['-B', '-aamd64', '-us', '-uc'], join(temp_dir, tarroot))
# Copy the Debian package files to the build directory.
debbase = 'dart_%s' % version
@ -95,10 +93,10 @@ def BuildDebianPackage(tarball, out_dir, arch):
for name in source_package:
copyfile(join(temp_dir, name), join(out_dir, name))
if ('ia32' in arch):
if 'ia32' in arch:
for name in i386_package:
copyfile(join(temp_dir, name), join(out_dir, name))
if ('x64' in arch):
if 'x64' in arch:
for name in amd64_package:
copyfile(join(temp_dir, name), join(out_dir, name))
@ -115,11 +113,11 @@ def Main():
arch = options.arch.split(',')
if not options.out_dir:
out_dir = join(DART_DIR, utils.GetBuildDir(HOST_OS, HOST_OS))
out_dir = join(DART_DIR, utils.GetBuildDir(HOST_OS))
if not tar_filename:
tar_filename = join(DART_DIR,
utils.GetBuildDir(HOST_OS, HOST_OS),
utils.GetBuildDir(HOST_OS),
'dart-%s.tar.gz' % utils.GetVersion())
BuildDebianPackage(tar_filename, out_dir, arch)

View file

@ -84,7 +84,7 @@ def Modify64BitDartEditorIni(iniFilePath):
# Add -d64 to give better error messages to user in 64 bit mode.
lines[lines.index('-vmargs\n')] = '-vmargs\n-d64\n'
f = open(iniFilePath, 'w')
f.writelines(lines);
f.writelines(lines)
f.close()

View file

@ -48,19 +48,19 @@
# ......(more will come here)
import glob
import optparse
import os
import re
import sys
import subprocess
import tempfile
import utils
HOST_OS = utils.GuessOS()
# TODO(dgrove): Only import modules following Google style guide.
from os.path import basename, dirname, join, realpath, exists, isdir
from os.path import basename, dirname, join, realpath, exists
# TODO(dgrove): Only import modules following Google style guide.
from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move
@ -76,8 +76,8 @@ def GetOptions():
def ReplaceInFiles(paths, subs):
'''Reads a series of files, applies a series of substitutions to each, and
saves them back out. subs should by a list of (pattern, replace) tuples.'''
"""Reads a series of files, applies a series of substitutions to each, and
saves them back out. subs should by a list of (pattern, replace) tuples."""
for path in paths:
contents = open(path).read()
for pattern, replace in subs:
@ -94,8 +94,8 @@ def Copy(src, dest):
def CopyShellScript(src_file, dest_dir):
'''Copies a shell/batch script to the given destination directory. Handles
using the appropriate platform-specific file extension.'''
"""Copies a shell/batch script to the given destination directory. Handles
using the appropriate platform-specific file extension."""
file_extension = ''
if HOST_OS == 'win32':
file_extension = '.bat'
@ -119,7 +119,7 @@ def CopySnapshots(snapshots, sdk_root):
join(sdk_root, 'bin', 'snapshots', snapshot))
def Main(argv):
def Main():
# Pull in all of the gypi files which will be munged into the sdk.
HOME = dirname(dirname(realpath(__file__)))
@ -258,4 +258,4 @@ def Main(argv):
move(SDK_tmp, SDK)
if __name__ == '__main__':
sys.exit(Main(sys.argv))
sys.exit(Main())

View file

@ -25,10 +25,11 @@ import datetime
import optparse
import sys
import tarfile
from os import listdir
from os.path import join, split, abspath
import utils
from os import listdir, makedirs
from os.path import join, exists, split, dirname, abspath
HOST_OS = utils.GuessOS()
DART_DIR = abspath(join(__file__, '..', '..'))
@ -115,7 +116,7 @@ def CreateTarball(tarfilename):
debian_dir = 'tools/linux_dist_support/debian'
# Don't include the build directory in the tarball (ignored paths
# are relative to DART_DIR).
builddir = utils.GetBuildDir(HOST_OS, HOST_OS)
builddir = utils.GetBuildDir(HOST_OS)
ignoredPaths.append(builddir)
print 'Creating tarball: %s' % tarfilename
@ -128,9 +129,9 @@ def CreateTarball(tarfilename):
with utils.TempDir() as temp_dir:
# Generate and add debian/copyright
copyright = join(temp_dir, 'copyright')
GenerateCopyright(copyright)
tar.add(copyright, arcname='%s/debian/copyright' % versiondir)
copyright_file = join(temp_dir, 'copyright')
GenerateCopyright(copyright_file)
tar.add(copyright_file, arcname='%s/debian/copyright' % versiondir)
# Generate and add debian/changelog
change_log = join(temp_dir, 'changelog')
@ -158,7 +159,7 @@ def Main():
tar_filename = options.tar_filename
if not tar_filename:
tar_filename = join(DART_DIR,
utils.GetBuildDir(HOST_OS, HOST_OS),
utils.GetBuildDir(HOST_OS),
'dart-%s.tar.gz' % utils.GetVersion())
CreateTarball(tar_filename)

View file

@ -1,392 +1,391 @@
#!/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 to generate a windows installer for the editor bundle.
# As input the script takes a zip file, a version and the location
# to store the resulting msi file in.
#
# Usage: ./tools/create_windows_installer.py --version <version>
# --zip_file_location <zip_file> --msi_location <output>
# [--wix_bin <wix_bin_location>]
# [--print_wxs]
#
# This script assumes that wix is either in path or passed in as --wix_bin.
# You can get wix from http://wixtoolset.org/.
import optparse
import os
import shutil
import subprocess
import sys
import utils
import zipfile
# This should _never_ change, please don't change this value.
UPGRADE_CODE = '7bacdc33-2e76-4f36-a206-ea58220c0b44'
# The content of the xml
xml_content = []
# The components we want to add to our feature.
feature_components = []
# Indentation level, each level is indented 2 spaces
current_indentation = 0
def GetOptions():
options = optparse.OptionParser(usage='usage: %prog [options]')
options.add_option("--zip_file_location",
help='Where the zip file including the editor is located.')
options.add_option("--input_directory",
help='Directory where all the files needed is located.')
options.add_option("--msi_location",
help='Where to store the resulting msi.')
options.add_option("--version",
help='The version specified as Major.Minor.Build.Patch.')
options.add_option("--wix_bin",
help='The location of the wix binary files.')
options.add_option("--print_wxs", action="store_true", dest="print_wxs",
default=False,
help="Prints the generated wxs to stdout.")
(options, args) = options.parse_args()
if len(args) > 0:
raise Exception("This script takes no arguments, only options")
ValidateOptions(options)
return options
def ValidateOptions(options):
if not options.version:
raise Exception('You must supply a version')
if options.zip_file_location and options.input_directory:
raise Exception('Please pass either zip_file_location or input_directory')
if not options.zip_file_location and not options.input_directory:
raise Exception('Please pass either zip_file_location or input_directory')
if (options.zip_file_location and
not os.path.isfile(options.zip_file_location)):
raise Exception('Passed in zip file not found')
if (options.input_directory and
not os.path.isdir(options.input_directory)):
raise Exception('Passed in directory not found')
def GetInputDirectory(options, temp_dir):
if options.zip_file_location:
ExtractZipFile(options.zip_file_location, temp_dir)
return os.path.join(temp_dir, 'dart')
return options.input_directory
# We combine the build and patch into a single entry since
# the windows installer does _not_ consider a change in Patch
# to require a new install.
# In addition to that, the limits on the size are:
# Major: 256
# Minor: 256
# Patch: 65536
# To circumvent this we create the version like this:
# Major.Minor.X
# from "major.minor.patch-prerelease.prerelease_patch"
# where X is "patch<<10 + prerelease<<5 + prerelease_patch"
# Example version 1.2.4-dev.2.3 will go to 1.2.4163
def GetMicrosoftProductVersion(version):
version_parts = version.split('.')
if len(version_parts) is not 5:
raise Exception(
"Version string (%s) does not follow specification" % version)
(major, minor, patch, prerelease, prerelease_patch) = map(int, version_parts)
if major > 255 or minor > 255:
raise Exception('Major/Minor can not be above 256')
if patch > 63:
raise Exception('Patch can not be above 63')
if prerelease > 31:
raise Exception('Prerelease can not be above 31')
if prerelease_patch > 31:
raise Exception('PrereleasePatch can not be above 31')
combined = (patch << 10) + (prerelease << 5) + prerelease_patch
return '%s.%s.%s' % (major, minor, combined)
# Append using the current indentation level
def Append(data, new_line=True):
str = ((' ' * current_indentation) +
data +
('\n' if new_line else ''))
xml_content.append(str)
# Append without any indentation at the current position
def AppendRaw(data, new_line=True):
xml_content.append(data + ('\n' if new_line else ''))
def AppendComment(comment):
Append('<!--%s-->' % comment)
def AppendBlankLine():
Append('')
def GetContent():
return ''.join(xml_content)
def XmlHeader():
Append('<?xml version="1.0" encoding="UTF-8"?>')
def TagIndent(str, indentation_string):
return ' ' * len(indentation_string) + str
def IncreaseIndentation():
global current_indentation
current_indentation += 1
def DecreaseIndentation():
global current_indentation
current_indentation -= 1
class WixAndProduct(object):
def __init__(self, version):
self.version = version
self.product_name = 'Dart Editor'
self.manufacturer = 'Google Inc.'
self.upgrade_code = UPGRADE_CODE
def __enter__(self):
self.start_wix()
self.start_product()
def __exit__(self, *_):
self.close_product()
self.close_wix()
def get_product_id(self):
# This needs to change on every install to guarantee that
# we get a full uninstall + reinstall
# We let wix choose. If we need to do patch releases later on
# we need to retain the value over several installs.
return '*'
def start_product(self):
product = '<Product '
Append(product, new_line=False)
AppendRaw('Id="%s"' % self.get_product_id())
Append(TagIndent('Version="%s"' % self.version, product))
Append(TagIndent('Name="%s"' % self.product_name, product))
Append(TagIndent('UpgradeCode="%s"' % self.upgrade_code,
product))
Append(TagIndent('Language="1033"', product))
Append(TagIndent('Manufacturer="%s"' % self.manufacturer,
product),
new_line=False)
AppendRaw('>')
IncreaseIndentation()
def close_product(self):
DecreaseIndentation()
Append('</Product>')
def start_wix(self):
Append('<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">')
IncreaseIndentation()
def close_wix(self):
DecreaseIndentation()
Append('</Wix>')
class Directory(object):
def __init__(self, id, name=None):
self.id = id
self.name = name
def __enter__(self):
directory = '<Directory '
Append(directory, new_line=False)
AppendRaw('Id="%s"' % self.id, new_line=self.name is not None)
if self.name:
Append(TagIndent('Name="%s"' % self.name, directory), new_line=False)
AppendRaw('>')
IncreaseIndentation()
def __exit__(self, *_):
DecreaseIndentation()
Append('</Directory>')
class Component(object):
def __init__(self, id):
self.id = 'CMP_%s' % id
def __enter__(self):
component = '<Component '
Append(component, new_line=False)
AppendRaw('Id="%s"' % self.id)
Append(TagIndent('Guid="*">', component))
IncreaseIndentation()
def __exit__(self, *_):
DecreaseIndentation()
Append('</Component>')
feature_components.append(self.id)
class Feature(object):
def __enter__(self):
feature = '<Feature '
Append(feature, new_line=False)
AppendRaw('Id="MainFeature"')
Append(TagIndent('Title="Dart Editor"', feature))
# Install by default
Append(TagIndent('Level="1">', feature))
IncreaseIndentation()
def __exit__(self, *_):
DecreaseIndentation()
Append('</Feature>')
def Package():
package = '<Package '
Append(package, new_line=False)
AppendRaw('InstallerVersion="301"')
Append(TagIndent('Compressed="yes" />', package))
def MediaTemplate():
Append('<MediaTemplate EmbedCab="yes" />')
def File(name, id):
file = '<File '
Append(file, new_line=False)
AppendRaw('Id="FILE_%s"' % id)
Append(TagIndent('Source="%s"' % name, file))
Append(TagIndent('KeyPath="yes" />', file))
def Shortcut(id, name, ref):
shortcut = '<Shortcut '
Append(shortcut, new_line=False)
AppendRaw('Id="%s"' % id)
Append(TagIndent('Name="%s"' % name, shortcut))
Append(TagIndent('Target="%s" />' % ref, shortcut))
def RemoveFolder(id):
remove = '<RemoveFolder '
Append(remove, new_line=False)
AppendRaw('Id="%s"' % id)
Append(TagIndent('On="uninstall" />', remove))
def RegistryEntry(location):
registry = '<RegistryValue '
Append(registry, new_line=False)
AppendRaw('Root="HKCU"')
Append(TagIndent('Key="Software\\Microsoft\\%s"' % location, registry))
Append(TagIndent('Name="installed"', registry))
Append(TagIndent('Type="integer"', registry))
Append(TagIndent('Value="1"', registry))
Append(TagIndent('KeyPath="yes" />', registry))
def MajorUpgrade():
upgrade = '<MajorUpgrade '
Append(upgrade, new_line=False)
down_message = 'You already have a never version installed.'
AppendRaw('DowngradeErrorMessage="%s" />' % down_message)
# This is a very simplistic id generation.
# Unfortunately there is no easy way to generate good names,
# since there is a 72 character limit, and we have way longer
# paths. We don't really have an issue with files and ids across
# releases since we do full installs.
counter = 0
def FileToId(name):
global counter
counter += 1
return '%s' % counter
def ListFiles(path):
for entry in os.listdir(path):
full_path = os.path.join(path, entry)
id = FileToId(full_path)
if os.path.isdir(full_path):
with Directory('DIR_%s' % id, entry):
ListFiles(full_path)
elif os.path.isfile(full_path):
# We assume 1 file per component, a File is always a KeyPath.
# A KeyPath on a file makes sure that we can always repair and
# remove that file in a consistent manner. A component
# can only have one child with a KeyPath.
with Component(id):
File(full_path, id)
def ComponentRefs():
for component in feature_components:
Append('<ComponentRef Id="%s" />' % component)
def ExtractZipFile(zip, temp_dir):
print 'Extracting files'
f = zipfile.ZipFile(zip)
f.extractall(temp_dir)
f.close()
def GenerateInstaller(wxs_content, options, temp_dir):
wxs_file = os.path.join(temp_dir, 'installer.wxs')
wixobj_file = os.path.join(temp_dir, 'installer.wixobj')
print 'Saving wxs output to: %s' % wxs_file
with open(wxs_file, 'w') as f:
f.write(wxs_content)
candle_bin = 'candle.exe'
light_bin = 'light.exe'
if options.wix_bin:
candle_bin = os.path.join(options.wix_bin, 'candle.exe')
light_bin = os.path.join(options.wix_bin, 'light.exe')
print 'Calling candle on %s' % wxs_file
subprocess.check_call('%s %s -o %s' % (candle_bin, wxs_file,
wixobj_file))
print 'Calling light on %s' % wixobj_file
subprocess.check_call('%s %s -o %s' % (light_bin, wixobj_file,
options.msi_location))
print 'Created msi file to %s' % options.msi_location
def Main(argv):
if sys.platform != 'win32':
raise Exception("This script can only be run on windows")
options = GetOptions()
version = GetMicrosoftProductVersion(options.version)
with utils.TempDir('installer') as temp_dir:
input_location = GetInputDirectory(options, temp_dir)
print "Generating wix XML"
XmlHeader()
with WixAndProduct(version):
AppendBlankLine()
Package()
MediaTemplate()
AppendComment('We always do a major upgrade, at least for now')
MajorUpgrade()
AppendComment('Directory structure')
with Directory('TARGETDIR', 'SourceDir'):
with Directory('ProgramFilesFolder'):
with Directory('RootInstallDir', 'Dart Editor'):
AppendComment("Add all files and directories")
print 'Installing files and directories in xml'
ListFiles(input_location)
AppendBlankLine()
AppendComment("Create shortcuts")
with Directory('ProgramMenuFolder'):
with Directory('ShortcutFolder', 'Dart Editor'):
with Component('shortcut'):
# When generating a shortcut we need an entry with
# a KeyPath (RegistryEntry) below - to be able to remove
# the shortcut again. The RemoveFolder tag is needed
# to clean up everything
Shortcut('editor_shortcut', 'Dart Editor',
'[RootInstallDir]DartEditor.exe')
RemoveFolder('RemoveShortcuts')
RegistryEntry('DartEditor')
with Feature():
# We have only one feature and that consist of all the
# files=components we have listed above"
ComponentRefs()
xml = GetContent()
if options.print_wxs:
print xml
GenerateInstaller(xml, options, temp_dir)
if __name__ == '__main__':
sys.exit(Main(sys.argv))
#!/usr/bin/env python
#
# Copyright (c) 2011, 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 to generate a windows installer for the editor bundle.
# As input the script takes a zip file, a version and the location
# to store the resulting msi file in.
#
# Usage: ./tools/create_windows_installer.py --version <version>
# --zip_file_location <zip_file> --msi_location <output>
# [--wix_bin <wix_bin_location>]
# [--print_wxs]
#
# This script assumes that wix is either in path or passed in as --wix_bin.
# You can get wix from http://wixtoolset.org/.
import optparse
import os
import subprocess
import sys
import utils
import zipfile
# This should _never_ change, please don't change this value.
UPGRADE_CODE = '7bacdc33-2e76-4f36-a206-ea58220c0b44'
# The content of the xml
xml_content = []
# The components we want to add to our feature.
feature_components = []
# Indentation level, each level is indented 2 spaces
current_indentation = 0
def GetOptions():
options = optparse.OptionParser(usage='usage: %prog [options]')
options.add_option("--zip_file_location",
help='Where the zip file including the editor is located.')
options.add_option("--input_directory",
help='Directory where all the files needed is located.')
options.add_option("--msi_location",
help='Where to store the resulting msi.')
options.add_option("--version",
help='The version specified as Major.Minor.Build.Patch.')
options.add_option("--wix_bin",
help='The location of the wix binary files.')
options.add_option("--print_wxs", action="store_true", dest="print_wxs",
default=False,
help="Prints the generated wxs to stdout.")
(options, args) = options.parse_args()
if len(args) > 0:
raise Exception("This script takes no arguments, only options")
ValidateOptions(options)
return options
def ValidateOptions(options):
if not options.version:
raise Exception('You must supply a version')
if options.zip_file_location and options.input_directory:
raise Exception('Please pass either zip_file_location or input_directory')
if not options.zip_file_location and not options.input_directory:
raise Exception('Please pass either zip_file_location or input_directory')
if (options.zip_file_location and
not os.path.isfile(options.zip_file_location)):
raise Exception('Passed in zip file not found')
if (options.input_directory and
not os.path.isdir(options.input_directory)):
raise Exception('Passed in directory not found')
def GetInputDirectory(options, temp_dir):
if options.zip_file_location:
ExtractZipFile(options.zip_file_location, temp_dir)
return os.path.join(temp_dir, 'dart')
return options.input_directory
# We combine the build and patch into a single entry since
# the windows installer does _not_ consider a change in Patch
# to require a new install.
# In addition to that, the limits on the size are:
# Major: 256
# Minor: 256
# Patch: 65536
# To circumvent this we create the version like this:
# Major.Minor.X
# from "major.minor.patch-prerelease.prerelease_patch"
# where X is "patch<<10 + prerelease<<5 + prerelease_patch"
# Example version 1.2.4-dev.2.3 will go to 1.2.4163
def GetMicrosoftProductVersion(version):
version_parts = version.split('.')
if len(version_parts) is not 5:
raise Exception(
"Version string (%s) does not follow specification" % version)
(major, minor, patch, prerelease, prerelease_patch) = map(int, version_parts)
if major > 255 or minor > 255:
raise Exception('Major/Minor can not be above 256')
if patch > 63:
raise Exception('Patch can not be above 63')
if prerelease > 31:
raise Exception('Prerelease can not be above 31')
if prerelease_patch > 31:
raise Exception('PrereleasePatch can not be above 31')
combined = (patch << 10) + (prerelease << 5) + prerelease_patch
return '%s.%s.%s' % (major, minor, combined)
# Append using the current indentation level
def Append(data, new_line=True):
str = ((' ' * current_indentation) +
data +
('\n' if new_line else ''))
xml_content.append(str)
# Append without any indentation at the current position
def AppendRaw(data, new_line=True):
xml_content.append(data + ('\n' if new_line else ''))
def AppendComment(comment):
Append('<!--%s-->' % comment)
def AppendBlankLine():
Append('')
def GetContent():
return ''.join(xml_content)
def XmlHeader():
Append('<?xml version="1.0" encoding="UTF-8"?>')
def TagIndent(str, indentation_string):
return ' ' * len(indentation_string) + str
def IncreaseIndentation():
global current_indentation
current_indentation += 1
def DecreaseIndentation():
global current_indentation
current_indentation -= 1
class WixAndProduct(object):
def __init__(self, version):
self.version = version
self.product_name = 'Dart Editor'
self.manufacturer = 'Google Inc.'
self.upgrade_code = UPGRADE_CODE
def __enter__(self):
self.start_wix()
self.start_product()
def __exit__(self, *_):
self.close_product()
self.close_wix()
def get_product_id(self):
# This needs to change on every install to guarantee that
# we get a full uninstall + reinstall
# We let wix choose. If we need to do patch releases later on
# we need to retain the value over several installs.
return '*'
def start_product(self):
product = '<Product '
Append(product, new_line=False)
AppendRaw('Id="%s"' % self.get_product_id())
Append(TagIndent('Version="%s"' % self.version, product))
Append(TagIndent('Name="%s"' % self.product_name, product))
Append(TagIndent('UpgradeCode="%s"' % self.upgrade_code,
product))
Append(TagIndent('Language="1033"', product))
Append(TagIndent('Manufacturer="%s"' % self.manufacturer,
product),
new_line=False)
AppendRaw('>')
IncreaseIndentation()
def close_product(self):
DecreaseIndentation()
Append('</Product>')
def start_wix(self):
Append('<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">')
IncreaseIndentation()
def close_wix(self):
DecreaseIndentation()
Append('</Wix>')
class Directory(object):
def __init__(self, id, name=None):
self.id = id
self.name = name
def __enter__(self):
directory = '<Directory '
Append(directory, new_line=False)
AppendRaw('Id="%s"' % self.id, new_line=self.name is not None)
if self.name:
Append(TagIndent('Name="%s"' % self.name, directory), new_line=False)
AppendRaw('>')
IncreaseIndentation()
def __exit__(self, *_):
DecreaseIndentation()
Append('</Directory>')
class Component(object):
def __init__(self, id):
self.id = 'CMP_%s' % id
def __enter__(self):
component = '<Component '
Append(component, new_line=False)
AppendRaw('Id="%s"' % self.id)
Append(TagIndent('Guid="*">', component))
IncreaseIndentation()
def __exit__(self, *_):
DecreaseIndentation()
Append('</Component>')
feature_components.append(self.id)
class Feature(object):
def __enter__(self):
feature = '<Feature '
Append(feature, new_line=False)
AppendRaw('Id="MainFeature"')
Append(TagIndent('Title="Dart Editor"', feature))
# Install by default
Append(TagIndent('Level="1">', feature))
IncreaseIndentation()
def __exit__(self, *_):
DecreaseIndentation()
Append('</Feature>')
def Package():
package = '<Package '
Append(package, new_line=False)
AppendRaw('InstallerVersion="301"')
Append(TagIndent('Compressed="yes" />', package))
def MediaTemplate():
Append('<MediaTemplate EmbedCab="yes" />')
def File(name, id):
file = '<File '
Append(file, new_line=False)
AppendRaw('Id="FILE_%s"' % id)
Append(TagIndent('Source="%s"' % name, file))
Append(TagIndent('KeyPath="yes" />', file))
def Shortcut(id, name, ref):
shortcut = '<Shortcut '
Append(shortcut, new_line=False)
AppendRaw('Id="%s"' % id)
Append(TagIndent('Name="%s"' % name, shortcut))
Append(TagIndent('Target="%s" />' % ref, shortcut))
def RemoveFolder(id):
remove = '<RemoveFolder '
Append(remove, new_line=False)
AppendRaw('Id="%s"' % id)
Append(TagIndent('On="uninstall" />', remove))
def RegistryEntry(location):
registry = '<RegistryValue '
Append(registry, new_line=False)
AppendRaw('Root="HKCU"')
Append(TagIndent('Key="Software\\Microsoft\\%s"' % location, registry))
Append(TagIndent('Name="installed"', registry))
Append(TagIndent('Type="integer"', registry))
Append(TagIndent('Value="1"', registry))
Append(TagIndent('KeyPath="yes" />', registry))
def MajorUpgrade():
upgrade = '<MajorUpgrade '
Append(upgrade, new_line=False)
down_message = 'You already have a never version installed.'
AppendRaw('DowngradeErrorMessage="%s" />' % down_message)
# This is a very simplistic id generation.
# Unfortunately there is no easy way to generate good names,
# since there is a 72 character limit, and we have way longer
# paths. We don't really have an issue with files and ids across
# releases since we do full installs.
counter = 0
def FileToId(name):
global counter
counter += 1
return '%s' % counter
def ListFiles(path):
for entry in os.listdir(path):
full_path = os.path.join(path, entry)
id = FileToId(full_path)
if os.path.isdir(full_path):
with Directory('DIR_%s' % id, entry):
ListFiles(full_path)
elif os.path.isfile(full_path):
# We assume 1 file per component, a File is always a KeyPath.
# A KeyPath on a file makes sure that we can always repair and
# remove that file in a consistent manner. A component
# can only have one child with a KeyPath.
with Component(id):
File(full_path, id)
def ComponentRefs():
for component in feature_components:
Append('<ComponentRef Id="%s" />' % component)
def ExtractZipFile(zip, temp_dir):
print 'Extracting files'
f = zipfile.ZipFile(zip)
f.extractall(temp_dir)
f.close()
def GenerateInstaller(wxs_content, options, temp_dir):
wxs_file = os.path.join(temp_dir, 'installer.wxs')
wixobj_file = os.path.join(temp_dir, 'installer.wixobj')
print 'Saving wxs output to: %s' % wxs_file
with open(wxs_file, 'w') as f:
f.write(wxs_content)
candle_bin = 'candle.exe'
light_bin = 'light.exe'
if options.wix_bin:
candle_bin = os.path.join(options.wix_bin, 'candle.exe')
light_bin = os.path.join(options.wix_bin, 'light.exe')
print 'Calling candle on %s' % wxs_file
subprocess.check_call('%s %s -o %s' % (candle_bin, wxs_file,
wixobj_file))
print 'Calling light on %s' % wixobj_file
subprocess.check_call('%s %s -o %s' % (light_bin, wixobj_file,
options.msi_location))
print 'Created msi file to %s' % options.msi_location
def Main(argv):
if sys.platform != 'win32':
raise Exception("This script can only be run on windows")
options = GetOptions()
version = GetMicrosoftProductVersion(options.version)
with utils.TempDir('installer') as temp_dir:
input_location = GetInputDirectory(options, temp_dir)
print "Generating wix XML"
XmlHeader()
with WixAndProduct(version):
AppendBlankLine()
Package()
MediaTemplate()
AppendComment('We always do a major upgrade, at least for now')
MajorUpgrade()
AppendComment('Directory structure')
with Directory('TARGETDIR', 'SourceDir'):
with Directory('ProgramFilesFolder'):
with Directory('RootInstallDir', 'Dart Editor'):
AppendComment("Add all files and directories")
print 'Installing files and directories in xml'
ListFiles(input_location)
AppendBlankLine()
AppendComment("Create shortcuts")
with Directory('ProgramMenuFolder'):
with Directory('ShortcutFolder', 'Dart Editor'):
with Component('shortcut'):
# When generating a shortcut we need an entry with
# a KeyPath (RegistryEntry) below - to be able to remove
# the shortcut again. The RemoveFolder tag is needed
# to clean up everything
Shortcut('editor_shortcut', 'Dart Editor',
'[RootInstallDir]DartEditor.exe')
RemoveFolder('RemoveShortcuts')
RegistryEntry('DartEditor')
with Feature():
# We have only one feature, and it consists of all the
# files=components we have listed above"
ComponentRefs()
xml = GetContent()
if options.print_wxs:
print xml
GenerateInstaller(xml, options, temp_dir)
if __name__ == '__main__':
sys.exit(Main(sys.argv))

View file

@ -96,7 +96,7 @@ def HasBotoConfig():
def InRunhooks():
'''True if this script was called by "gclient runhooks" or "gclient sync"'''
"""True if this script was called by "gclient runhooks" or "gclient sync\""""
return 'runhooks' in sys.argv
@ -132,22 +132,21 @@ def GetDartiumRevision(name, bot, directory, version_file, latest_pattern,
"""
osdict = {'Darwin':'mac', 'Linux':'lucid64', 'Windows':'win'}
def FindPermanentUrl(out, osname, revision_num):
def FindPermanentUrl(out, osname, the_revision_num):
output_lines = out.split()
latest = output_lines[-1]
if not revision_num:
revision_num = latest[latest.rindex('-') + 1 : latest.index('.')]
if not the_revision_num:
latest = (permanent_prefix[:permanent_prefix.rindex('/')] % { 'osname' :
osname, 'bot' : bot } + latest[latest.rindex('/'):])
else:
latest = (permanent_prefix % { 'osname' : osname, 'num1' : revision_num,
'num2' : revision_num, 'bot' : bot })
latest = (permanent_prefix % { 'osname' : osname, 'num1' : the_revision_num,
'num2' : the_revision_num, 'bot' : bot })
foundURL = False
while not foundURL:
# Test to ensure this URL exists because the dartium-archive builds can
# have unusual numbering (a range of CL numbers) sometimes.
result, out = Gsutil('ls', permanent_prefix % {'osname' : osname,
'num1': revision_num, 'num2': '*', 'bot': bot })
'num1': the_revision_num, 'num2': '*', 'bot': bot })
if result == 0:
# First try to find one with the the second number the same as the
# requested number.
@ -163,12 +162,12 @@ def GetDartiumRevision(name, bot, directory, version_file, latest_pattern,
# Unable to download this item (most likely because something went
# wrong on the upload and the permissions are bad). Keep looking for
# a different URL.
revision_num = int(revision_num) - 1
the_revision_num = int(the_revision_num) - 1
shutil.rmtree(temp_dir)
else:
# Now try to find one with a nearby CL num.
revision_num = int(revision_num) - 1
if revision_num <= 0:
the_revision_num = int(the_revision_num) - 1
if the_revision_num <= 0:
TooEarlyError()
return latest

View file

@ -3,11 +3,11 @@
# 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.
'''Tool for listing files whose name match a pattern.
"""Tool for listing files whose name match a pattern.
Usage:
python tools/list_files.py PATTERN DIRECTORY...
'''
"""
import os
import re

View file

@ -3,13 +3,13 @@
# 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.
'''Tool for listing the directories under pkg, with their lib directories.
"""Tool for listing the directories under pkg, with their lib directories.
Used in pkg.gyp. Lists all of the directories in the directory passed in as an
argument to this script which have a lib subdirectory.
Usage:
python tools/list_pkg_directories.py OPTIONS DIRECTORY
'''
"""
import optparse
import os

View file

@ -4,7 +4,7 @@
# BSD-style license that can be found in the LICENSE file.
'''Tool for creating symlinks from SOURCES to TARGET.
"""Tool for creating symlinks from SOURCES to TARGET.
For each SOURCE in SOURCES create a link from SOURCE to TARGET. If a
SOURCE ends with .../lib, the lib suffix is ignored when determining
@ -15,7 +15,7 @@ removed.
Usage:
python tools/make_links.py OPTIONS TARGET SOURCES...
'''
"""
import optparse
import os

View file

@ -50,7 +50,7 @@ def main(args):
sys.stderr.write('--input not specified\n')
return -1
files = [ ]
files = []
for arg in args:
files.append(arg)

View file

@ -7,7 +7,7 @@
"""
Wrapper around a build action that should only be executed in release mode.
The mode is defined via an environment varible DART_BUILD_MODE.
The mode is defined via an environment variable DART_BUILD_MODE.
The arguments to the script are:
@ -29,7 +29,7 @@ def Main():
outputs = sys.argv[1:separator_index]
arguments = sys.argv[separator_index + 1:]
arguments[0] = os.path.normpath(arguments[0])
mode = os.getenv('DART_BUILD_MODE', default='release')
mode = os.getenv('DART_BUILD_MODE', 'release')
if mode != 'release':
print >> sys.stderr, 'Not running %s in mode=%s' % (arguments, mode)
for output in outputs:

View file

@ -13,7 +13,6 @@
import os
import os.path
import re
import shutil
import sys
import subprocess
@ -33,13 +32,13 @@ def Main(argv):
lines = pubspecFile.readlines()
version = None
foundSdkContraint = False
foundSdkConstraint = False
inDependencies = False
for line in lines:
if line.startswith('dependencies:'):
inDependencies = True
elif line.startswith('environment:'):
foundSdkContraint = True
foundSdkConstraint = True
elif line[0].isalpha():
inDependencies = False
if line.startswith('version:'):
@ -54,7 +53,7 @@ def Main(argv):
print 'Error in %s: did not find package version.' % pubspec
return -1
if not foundSdkContraint:
if not foundSdkConstraint:
print 'Error in %s: did not find SDK version constraint.' % pubspec
return -1
@ -69,7 +68,7 @@ def Main(argv):
if not os.path.exists(os.path.join(tmpDir, pkgName, 'LICENSE')):
with open(os.path.join(tmpDir, pkgName, 'LICENSE'), 'w') as licenseFile:
licenseFile.write(
'''Copyright 2013, the Dart project authors. All rights reserved.
'''Copyright 2014, the Dart project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
@ -95,7 +94,7 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
''');
''')
print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n'

View file

@ -22,7 +22,7 @@ def parse_args():
'8..10, or 8:10).')
args, _ = parser.parse_args()
revision_range = args.rev_range
if revision_range == None:
if revision_range is None:
maybe_fail('You must specify at least one revision number to revert.')
if revision_range.find('-') > -1 or revision_range.find(':') > -1 or \
revision_range.find('..') > -1:
@ -82,7 +82,7 @@ def has_new_code(is_git):
p = subprocess.Popen(['git', 'log', '-1'], stdout=subprocess.PIPE,
shell=(platform.system()=='Windows'))
output, _ = p.communicate()
if find_git_info(output) == None:
if find_git_info(output) is None:
return True
return False
@ -97,7 +97,7 @@ def run_cmd(cmd_list, suppress_output=False, std_in=''):
print output
if stderr and not suppress_output:
print stderr
return (output, stderr)
return output, stderr
def runs_git():
"""Returns True if we're standing in an svn-git repository."""
@ -105,7 +105,7 @@ def runs_git():
stderr=subprocess.PIPE,
shell=(platform.system()=='Windows'))
output, err = p.communicate()
if err != None and 'is not a working copy' in err:
if err is not None and 'is not a working copy' in err:
p = subprocess.Popen(['git', 'status'], stdout=subprocess.PIPE,
shell=(platform.system()=='Windows'))
output, _ = p.communicate()
@ -127,7 +127,7 @@ def find_git_info(git_log, rev_num=None):
revision_number = int(tokens[1].split('@')[1])
if revision_number == rev_num:
return current_commit_id
if rev_num == None:
if rev_num is None:
return revision_number
def revert(start, end, is_git):
@ -157,16 +157,16 @@ def revert(start, end, is_git):
reverts = range(start, end + 1)
reverts.reverse()
commit_msg = '%s-%d"' % (commit_msg[:-1], end)
for revert in reverts:
git_commit_id = find_git_info(output, revert)
if git_commit_id == None:
for the_revert in reverts:
git_commit_id = find_git_info(output, the_revert)
if git_commit_id is None:
maybe_fail('Error: Revision number not found. Is this earlier than your'
' git checkout history?')
_, err = run_cmd(['git', 'revert', '-n', git_commit_id])
if 'error: could not revert' in err or 'unmerged' in err:
command_sequence = ''
for revert in reverts:
git_commit_id = find_git_info(output, revert)
for a_revert in reverts:
git_commit_id = find_git_info(output, a_revert)
command_sequence += 'git revert -n %s\n' % git_commit_id
maybe_fail('There are conflicts while reverting. Please resolve these '
'after manually running:\n' + command_sequence + 'and then '

View file

@ -12,12 +12,12 @@
import optparse
import os
import signal
import shutil
import string
import subprocess
import sys
import utils
os_name = utils.GuessOS()
POSIX_INFO = 'ps -p %s -o args'
@ -118,13 +118,13 @@ def GetPidsWindows(process_name):
return results
def GetPids(process_name):
if (os_name == "win32"):
if os_name == "win32":
return GetPidsWindows(process_name)
else:
return GetPidsPosix(process_name)
def PrintPidInfo(pid):
# We asume that the list command will return lines in the format:
# We assume that the list command will return lines in the format:
# EXECUTABLE_PATH ARGS
# There may be blank strings in the output
p = subprocess.Popen(INFO_COMMAND[os_name] % pid,
@ -146,7 +146,7 @@ def PrintPidInfo(pid):
def KillPosix(pid):
try:
os.kill(int(pid), signal.SIGKILL);
os.kill(int(pid), signal.SIGKILL)
except:
# Ignore this, the process is already dead from killing another process.
pass
@ -161,19 +161,19 @@ def KillWindows(pid):
p.communicate()
def Kill(name):
if (name not in EXECUTABLE_NAMES[os_name]):
if name not in EXECUTABLE_NAMES[os_name]:
return 0
print("***************** Killing %s *****************" % name)
platform_name = EXECUTABLE_NAMES[os_name][name]
pids = GetPids(platform_name)
for pid in pids:
PrintPidInfo(pid);
if (os_name == "win32"):
PrintPidInfo(pid)
if os_name == "win32":
KillWindows(pid)
else:
KillPosix(pid)
print("Killed pid: %s" % pid)
if (len(pids) == 0):
if len(pids) == 0:
print(" No %s processes found." % name)
return len(pids)
@ -205,13 +205,13 @@ def KillEditor():
def Main():
options = GetOptions()
status = 0
if (options.kill_dart):
status += KillDart();
if (options.kill_vc):
status += KillVCSystems();
if (options.kill_browsers):
if options.kill_dart:
status += KillDart()
if options.kill_vc:
status += KillVCSystems()
if options.kill_browsers:
status += KillBrowsers()
if (options.kill_editor):
if options.kill_editor:
status += KillEditor()
return status

View file

@ -4,7 +4,6 @@
# BSD-style license that can be found in the LICENSE file.
import os
import platform
import string
import subprocess
import sys
@ -15,8 +14,6 @@ import utils
def Main():
args = sys.argv[1:]
tools_dir = os.path.dirname(os.path.realpath(__file__))
current_directory = os.path.abspath('');
client = os.path.abspath(os.path.join(tools_dir, '..'));
dart_script_name = 'test.dart'
dart_test_script = string.join([tools_dir, dart_script_name], os.sep)
command = [utils.DartBinary(), '--checked', dart_test_script] + args

View file

@ -109,7 +109,7 @@ class GoogleBasedInstaller(object):
os_str = 'linux64'
if self.project_name == 'chromedriver' and (
os_str == 'mac' or os_str == 'win'):
os_str = os_str + '32'
os_str += '32'
return os_str
def run(self):

View file

@ -11,8 +11,8 @@ import platform
import re
import shutil
import subprocess
import sys
import tempfile
import sys
class Version(object):
def __init__(self, channel, major, minor, patch, prerelease,
@ -26,20 +26,20 @@ class Version(object):
# Try to guess the host operating system.
def GuessOS():
id = platform.system()
if id == "Linux":
os_id = platform.system()
if os_id == "Linux":
return "linux"
elif id == "Darwin":
elif os_id == "Darwin":
return "macos"
elif id == "Windows" or id == "Microsoft":
elif os_id == "Windows" or os_id == "Microsoft":
# On Windows Vista platform.system() can return "Microsoft" with some
# versions of Python, see http://bugs.python.org/issue1082 for details.
return "win32"
elif id == 'FreeBSD':
elif os_id == 'FreeBSD':
return 'freebsd'
elif id == 'OpenBSD':
elif os_id == 'OpenBSD':
return 'openbsd'
elif id == 'SunOS':
elif os_id == 'SunOS':
return 'solaris'
else:
return None
@ -47,22 +47,23 @@ def GuessOS():
# Try to guess the host architecture.
def GuessArchitecture():
id = platform.machine()
if id.startswith('arm'):
os_id = platform.machine()
if os_id.startswith('arm'):
return 'arm'
elif id.startswith('aarch64'):
elif os_id.startswith('aarch64'):
return 'arm64'
elif id.startswith('mips'):
elif os_id.startswith('mips'):
return 'mips'
elif (not id) or (not re.match('(x|i[3-6])86', id) is None):
elif (not os_id) or (not re.match('(x|i[3-6])86', os_id) is None):
return 'ia32'
elif id == 'i86pc':
elif os_id == 'i86pc':
return 'ia32'
elif '64' in id:
elif '64' in os_id:
return 'x64'
else:
guess_os = GuessOS()
print "Warning: Guessing architecture %s based on os %s\n" % (id, guess_os)
print "Warning: Guessing architecture %s based on os %s\n"\
% (os_id, guess_os)
if guess_os == 'win32':
return 'ia32'
return None
@ -97,7 +98,7 @@ def GuessVisualStudioPath():
defaultExecutable = "devenv.com"
if not IsWindows():
return (defaultPath, defaultExecutable)
return defaultPath, defaultExecutable
keyNamesAndExecutables = [
# Pair for non-Express editions.
@ -122,7 +123,7 @@ def GuessVisualStudioPath():
while True:
try:
subkeyName = _winreg.EnumKey(key, subkeyCounter)
subkeyCounter = subkeyCounter + 1
subkeyCounter += 1
except WindowsError:
# Reached end of enumeration. Moving on the next key.
break
@ -140,7 +141,7 @@ def GuessVisualStudioPath():
if not isExpress and subkeyName == '10.0':
# Stop search since if we found non-Express VS2010 version
# installed, which is preferred version.
return (installDir, executable)
return installDir, executable
else:
version = float(subkeyName)
# We prefer higher version of Visual Studio and given equal
@ -172,7 +173,7 @@ def ReadLinesFrom(name):
# Filters out all arguments until the next '--' argument
# occurs.
def ListArgCallback(option, opt_str, value, parser):
def ListArgCallback(option, value, parser):
if value is None:
value = []
@ -187,7 +188,7 @@ def ListArgCallback(option, opt_str, value, parser):
# Filters out all argument until the first non '-' or the
# '--' argument occurs.
def ListDartArgCallback(option, opt_str, value, parser):
def ListDartArgCallback(option, value, parser):
if value is None:
value = []
@ -259,11 +260,11 @@ def GetBuildConf(mode, arch, conf_os=None):
cross_build = 'X'
return '%s%s%s' % (GetBuildMode(mode), cross_build, arch.upper())
def GetBuildDir(host_os, target_os):
def GetBuildDir(host_os):
return BUILD_ROOT[host_os]
def GetBuildRoot(host_os, mode=None, arch=None, target_os=None):
build_root = GetBuildDir(host_os, target_os)
def GetBuildRoot(host_os, mode=None, arch=None):
build_root = GetBuildDir(host_os)
if mode:
build_root = os.path.join(build_root, GetBuildConf(mode, arch, target_os))
return build_root
@ -320,8 +321,8 @@ def GetUserName():
return os.environ.get(key, '')
def ReadVersionFile():
def match_against(pattern, content):
match = re.search(pattern, content, flags=re.MULTILINE)
def match_against(pattern, file_content):
match = re.search(pattern, file_content, flags=re.MULTILINE)
if match:
return match.group(1)
return None
@ -415,7 +416,7 @@ def RewritePathSeparator(path, workspace):
# Paths in test files are always specified using '/'
# as the path separator. Replace with the actual
# path separator before use.
if ('/' in path):
if '/' in path:
split_path = path.split('/')
path = os.sep.join(split_path)
path = os.path.join(workspace, path)
@ -439,7 +440,7 @@ def ParseTestOptionsMultiple(pattern, source, workspace):
for match in matches:
if len(match) > 0:
result.append(
[RewritePathSeparator(o, workspace) for o in match.split(' ')]);
[RewritePathSeparator(o, workspace) for o in match.split(' ')])
else:
result.append([])
return result
@ -457,7 +458,7 @@ def ConfigureJava():
if proc.wait() != 0:
return None
new = stdout.strip()
current = os.getenv('JAVA_HOME', default=new)
current = os.getenv('JAVA_HOME', new)
if current != new:
sys.stderr.write('Please set JAVA_HOME to %s\n' % new)
os.putenv('JAVA_HOME', new)
@ -474,14 +475,14 @@ def Daemonize():
return False
os.setsid()
if os.fork() > 0:
os._exit(0)
exit(0)
raise
return True
def PrintError(str):
def PrintError(string):
"""Writes and flushes a string to stderr."""
sys.stderr.write(str)
sys.stderr.write(string)
sys.stderr.write('\n')
@ -493,7 +494,7 @@ def CheckedUnlink(name):
PrintError("os.unlink() " + str(e))
def Main(argv):
def Main():
print "GuessOS() -> ", GuessOS()
print "GuessArchitecture() -> ", GuessArchitecture()
print "GuessCpus() -> ", GuessCpus()
@ -541,7 +542,7 @@ def ExecuteCommand(cmd):
output = pipe.communicate()
if pipe.returncode != 0:
raise Exception('Execution failed: ' + str(output))
return (pipe.returncode, output)
return pipe.returncode, output
def DartBinary():
@ -595,4 +596,4 @@ class ChangedWorkingDirectory(object):
if __name__ == "__main__":
import sys
Main(sys.argv)
Main()