Commit e377aa71 authored by gman@google.com's avatar gman@google.com

Add --clean support to gypbuild.

Also, re-arranged code to have a class per platform.

Review URL: http://codereview.chromium.org/341009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30292 0039d316-1c4b-4281-b951-d872f2087c98
parent 603a07f3
......@@ -37,71 +37,70 @@ from optparse import OptionParser
class GypBuilder(object):
"""A class to help build gyp projects in a cross platform way"""
def __init__(self, args):
self.execute = True
self.verbose = False
class Builder(object):
"""Base Class for building."""
modes = ["build", "presubmit", "selenium", "unit_tests"]
versions = ["Debug", "Release"]
def __init__(self, builder):
self.builder = builder
parser = OptionParser()
parser.add_option(
"--list-targets", action="store_true",
help="lists all available targets")
parser.add_option(
"--no-execute", action="store_true", default=False,
help="just print commands that would get executed")
parser.add_option(
"--verbose", action="store_true",
help="prints more output")
parser.add_option(
"--targets", action="append",
help="targets to build separated by commas.")
parser.add_option(
"--clean", action="store_true",
help="clean the targets")
parser.add_option(
"--version", choices=versions, default="Debug",
help="version to build. Versions are '%s'. Default='Debug' " %
"', '".join(versions))
parser.add_option(
"--mode", choices=modes, default="build",
help="mode to use. Valid modes are '%s'. Default='build' " %
"', '".join(modes))
def Log(self, *args):
"""Prints something if verbose is true."""
self.builder.Log(args)
(options, args) = parser.parse_args(args=args)
def Execute(self, args):
"""Executes an external program if execute is true."""
self.builder.Execute(args)
self.verbose = options.verbose
self.execute = not options.no_execute
def Dopresubmit(self, targets, options):
"""Builds and runs both the unit tests and selenium."""
self.Dounit_tests(targets, options)
self.Doselenium(targets, options)
if options.list_targets:
print "Not yet implemented"
sys.exit(0)
def Doselenium(self, targets, options):
"""Builds and runs the selenium tests."""
print "selenium not yet implemented."
self.Log("mode:", options.mode)
def Dounit_tests(self, targets, options):
"""Builds and runs the unit tests."""
print "unit_tests not yet implemented."
targets = options.targets
if targets:
# flatten the targets.
targets = sum([t.split(",") for t in targets], [])
def CleanTargets(self, targets, options):
"""Cleans the targets."""
print "clean not implemented for this platform."
# call a Do method based on the mode.
os.chdir("build")
func = getattr(self, "Do%s" % options.mode)
func(targets, options)
def Log(self, *args):
if self.verbose:
print args
class OSXBuilder(Builder):
"""Class for building on OSX."""
def Execute(self, args):
"""Executes an external program."""
if self.execute:
self.Log(" ".join(args))
if subprocess.call(args) > 0:
raise RuntimeError("FAILED: " + " ".join(args))
else:
print " ".join(args)
def __init__(self, builder):
GypBuilder.Builder.__init__(self, builder)
def GetSolutionPath(self):
"""Gets the solution path."""
return '%s.xcodeproj' % GypBuilder.base_name
def CleanTargets(self, targets, options):
"""Cleans the specifed targets."""
solution = self.GetSolutionPath()
self.Execute(['xcodebuild',
'-project', solution,
'clean'])
def Dobuild(self, targets, options):
"""Builds the specifed targets."""
solution = self.GetSolutionPath()
self.Execute(['xcodebuild',
'-project', solution])
class WinBuilder(Builder):
"""Class for building on Windows."""
def __init__(self, builder):
GypBuilder.Builder.__init__(self, builder)
def GetSolutionPath(self):
"""Gets the solution path."""
return os.path.abspath('%s.sln' % GypBuilder.base_name)
def CheckVisualStudioVersionVsSolution(self, solution):
"""Checks the solution matches the cl version."""
......@@ -148,14 +147,17 @@ class GypBuilder(object):
print "and run 'gclient runhooks --force'"
sys.exit(1)
def CleanTargets(self, targets, options):
"""Cleans the targets."""
solution = self.GetSolutionPath()
self.Execute(['devenv.exe',
solution,
'/clean',
options.version])
def Dobuild(self, targets, options):
"""Builds the specifed targets."""
# Use "o3d" for chrome only build.
name = "o3d_all"
if os.name == 'nt':
solution = os.path.abspath('%s.sln' % name)
solution = self.GetSolutionPath()
if not is_admin.IsAdmin():
print ("WARNING: selenium_ie will not run unless you run as admin "
"or turn off UAC.\nAfter switching to admin run "
......@@ -164,27 +166,120 @@ class GypBuilder(object):
self.Execute(['msbuild',
solution,
'/p:Configuration=%s' % options.version])
class LinuxBuilder(Builder):
"""Class for building on Linux."""
def __init__(self, builder):
GypBuilder.Builder.__init__(self, builder)
def GetSolutionPath(self):
"""Gets the solution path."""
return '%s_main.scons' % GypBuilder.base_name
def CleanTargets(self, targets, options):
"""Cleans the targets."""
solution = self.GetSolutionPath()
self.Execute(['hammer',
'-f', solution,
'--clean'])
def Dobuild(self, targets, options):
"""Builds the specifed targets."""
solution = self.GetSolutionPath()
self.Execute(['hammer',
'-f', solution])
# Use "o3d" for chrome only build?
base_name = "o3d_all"
def __init__(self, args):
self.execute = True
self.verbose = False
modes = ["build", "presubmit", "selenium", "unit_tests"]
versions = ["Debug", "Release"]
parser = OptionParser()
parser.add_option(
"--list-targets", action="store_true",
help="lists all available targets.")
parser.add_option(
"--no-execute", action="store_true", default=False,
help="just prints commands that would get executed.")
parser.add_option(
"--verbose", action="store_true",
help="prints more output.")
parser.add_option(
"--targets", action="append",
help="targets to build separated by commas.")
parser.add_option(
"--clean", action="store_true",
help="cleans the targets.")
parser.add_option(
"--rebuild", action="store_true",
help="cleans, then builds targets")
parser.add_option(
"--version", choices=versions, default="Debug",
help="version to build. Versions are '%s'. Default='Debug' " %
"', '".join(versions))
parser.add_option(
"--mode", choices=modes, default="build",
help="mode to use. Valid modes are '%s'. Default='build' " %
"', '".join(modes))
(options, args) = parser.parse_args(args=args)
self.verbose = options.verbose
self.execute = not options.no_execute
if options.list_targets:
print "Not yet implemented"
sys.exit(0)
self.Log("mode:", options.mode)
targets = options.targets
if targets:
# flatten the targets.
targets = sum([t.split(",") for t in targets], [])
os.chdir("build")
# Create a platform specific builder.
if os.name == 'nt':
builder = self.WinBuilder(self)
elif platform.system() == 'Darwin':
self.Execute(['xcodebuild',
'-project', '%s.xcodeproj' % name])
builder = self.OSXBuilder(self)
elif platform.system() == 'Linux':
self.Execute(['hammer',
'-f', '%s_main.scons' % name])
builder = self.LinuxBuilder(self)
else:
print "Error: Unknown platform", os.name
print "ERROR: Unknown platform."
sys.exit(1)
def Dopresubmit(self, targets, options):
"""Builds and runs both the unit tests and selenium."""
self.Dounit_tests(targets, options)
self.Doselenium(targets, options)
# clean if asked.
if options.clean or options.rebuild:
builder.CleanTargets(targets, options)
if not options.rebuild:
return
def Doselenium(self, targets, options):
"""Builds and runs the selenium tests."""
print "selenium not yet implemented."
# call a Do method based on the mode.
func = getattr(builder, "Do%s" % options.mode)
func(targets, options)
def Dounit_tests(self, targets, options):
"""Builds and runs the unit tests."""
print "unit_tests not yet implemented."
def Log(self, *args):
"""Prints something if verbose is true."""
if self.verbose:
print args
def Execute(self, args):
"""Executes an external program if execute is true."""
if self.execute:
self.Log(" ".join(args))
if subprocess.call(args) > 0:
raise RuntimeError("FAILED: " + " ".join(args))
else:
print " ".join(args)
def main(args):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment