summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-28 00:26:41 +0000
committergman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-28 00:26:41 +0000
commite377aa714343faf54f3e72f04acc7ca76fefd579 (patch)
tree0e99d1ece0cdf10e1f3ccbd789d15a31ce5d766d
parent603a07f3de22e75e6dcc11b45f42861525a7b674 (diff)
downloadchromium_src-e377aa714343faf54f3e72f04acc7ca76fefd579.zip
chromium_src-e377aa714343faf54f3e72f04acc7ca76fefd579.tar.gz
chromium_src-e377aa714343faf54f3e72f04acc7ca76fefd579.tar.bz2
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
-rwxr-xr-xo3d/gypbuild.py275
1 files changed, 185 insertions, 90 deletions
diff --git a/o3d/gypbuild.py b/o3d/gypbuild.py
index d8409d6..b42e43a3 100755
--- a/o3d/gypbuild.py
+++ b/o3d/gypbuild.py
@@ -37,6 +37,162 @@ from optparse import OptionParser
class GypBuilder(object):
"""A class to help build gyp projects in a cross platform way"""
+ class Builder(object):
+ """Base Class for building."""
+
+ def __init__(self, builder):
+ self.builder = builder
+
+ def Log(self, *args):
+ """Prints something if verbose is true."""
+ self.builder.Log(args)
+
+ def Execute(self, args):
+ """Executes an external program if execute is true."""
+ self.builder.Execute(args)
+
+ def Dopresubmit(self, targets, options):
+ """Builds and runs both the unit tests and selenium."""
+ self.Dounit_tests(targets, options)
+ self.Doselenium(targets, options)
+
+ def Doselenium(self, targets, options):
+ """Builds and runs the selenium tests."""
+ print "selenium not yet implemented."
+
+ def Dounit_tests(self, targets, options):
+ """Builds and runs the unit tests."""
+ print "unit_tests not yet implemented."
+
+ def CleanTargets(self, targets, options):
+ """Cleans the targets."""
+ print "clean not implemented for this platform."
+
+
+ class OSXBuilder(Builder):
+ """Class for building on OSX."""
+
+ 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."""
+ f = open(solution, "r")
+ line = f.readline()
+ f.close()
+ m = re.search(r'Format Version (\d+)\.', line)
+ if m:
+ solution_version = int(m.group(1))
+ else:
+ print "FAILURE: Unknown solution version in %s" % solution
+ sys.exit(1)
+
+ output = subprocess.Popen(['cl.exe'],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE).communicate()[1]
+ m = re.search(r'Compiler Version (\d+)\.', output)
+ if m:
+ compiler_version = int(m.group(1))
+ else:
+ print "FAILURE: Unknown cl.exe version."
+ sys.exit(1)
+
+ # Compiler Solution
+ # Visual Studio .NET 2005 14 9
+ # Visual Studio .NET 2008 15 10
+ # Visual Studio .NET 2010 ?? ??
+ if (compiler_version - 14) > (solution_version - 9):
+ vs_map = {
+ 14: '2005',
+ 15: '2008',
+ 16: '2010',
+ }
+ sln_map = {
+ 9: '2005',
+ 10: '2008',
+ 11: '2010',
+ }
+ vs_version = vs_map[compiler_version]
+ print ("ERROR: solution (%s) version does not match "
+ "Visual Studio version (%s)" %
+ (sln_map[solution_version], vs_version))
+ print "You should 'set GYP_MSVS_VERSION=auto'"
+ 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."""
+ 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 "
+ "'gclient runhooks --force'")
+ self.CheckVisualStudioVersionVsSolution(solution)
+ 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
@@ -47,19 +203,22 @@ class GypBuilder(object):
parser = OptionParser()
parser.add_option(
"--list-targets", action="store_true",
- help="lists all available targets")
+ help="lists all available targets.")
parser.add_option(
"--no-execute", action="store_true", default=False,
- help="just print commands that would get executed")
+ help="just prints commands that would get executed.")
parser.add_option(
"--verbose", action="store_true",
- help="prints more output")
+ 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")
+ 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' " %
@@ -85,17 +244,36 @@ class GypBuilder(object):
# flatten the targets.
targets = sum([t.split(",") for t in targets], [])
- # call a Do method based on the mode.
os.chdir("build")
- func = getattr(self, "Do%s" % options.mode)
+
+ # Create a platform specific builder.
+ if os.name == 'nt':
+ builder = self.WinBuilder(self)
+ elif platform.system() == 'Darwin':
+ builder = self.OSXBuilder(self)
+ elif platform.system() == 'Linux':
+ builder = self.LinuxBuilder(self)
+ else:
+ print "ERROR: Unknown platform."
+ sys.exit(1)
+
+ # clean if asked.
+ if options.clean or options.rebuild:
+ builder.CleanTargets(targets, options)
+ if not options.rebuild:
+ return
+
+ # call a Do method based on the mode.
+ func = getattr(builder, "Do%s" % options.mode)
func(targets, options)
def Log(self, *args):
+ """Prints something if verbose is true."""
if self.verbose:
print args
def Execute(self, args):
- """Executes an external program."""
+ """Executes an external program if execute is true."""
if self.execute:
self.Log(" ".join(args))
if subprocess.call(args) > 0:
@@ -103,89 +281,6 @@ class GypBuilder(object):
else:
print " ".join(args)
- def CheckVisualStudioVersionVsSolution(self, solution):
- """Checks the solution matches the cl version."""
- f = open(solution, "r")
- line = f.readline()
- f.close()
- m = re.search(r'Format Version (\d+)\.', line)
- if m:
- solution_version = int(m.group(1))
- else:
- print "FAILURE: Unknown solution version in %s" % solution
- sys.exit(1)
-
- output = subprocess.Popen(['cl.exe'],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE).communicate()[1]
- m = re.search(r'Compiler Version (\d+)\.', output)
- if m:
- compiler_version = int(m.group(1))
- else:
- print "FAILURE: Unknown cl.exe version."
- sys.exit(1)
-
- # Compiler Solution
- # Visual Studio .NET 2005 14 9
- # Visual Studio .NET 2008 15 10
- # Visual Studio .NET 2010 ?? ??
- if (compiler_version - 14) > (solution_version - 9):
- vs_map = {
- 14: '2005',
- 15: '2008',
- 16: '2010',
- }
- sln_map = {
- 9: '2005',
- 10: '2008',
- 11: '2010',
- }
- vs_version = vs_map[compiler_version]
- print ("ERROR: solution (%s) version does not match "
- "Visual Studio version (%s)" %
- (sln_map[solution_version], vs_version))
- print "You should 'set GYP_MSVS_VERSION=auto'"
- print "and run 'gclient runhooks --force'"
- sys.exit(1)
-
- 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)
- 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 "
- "'gclient runhooks --force'")
- self.CheckVisualStudioVersionVsSolution(solution)
- self.Execute(['msbuild',
- solution,
- '/p:Configuration=%s' % options.version])
- elif platform.system() == 'Darwin':
- self.Execute(['xcodebuild',
- '-project', '%s.xcodeproj' % name])
- elif platform.system() == 'Linux':
- self.Execute(['hammer',
- '-f', '%s_main.scons' % name])
- else:
- print "Error: Unknown platform", os.name
-
- def Dopresubmit(self, targets, options):
- """Builds and runs both the unit tests and selenium."""
- self.Dounit_tests(targets, options)
- self.Doselenium(targets, options)
-
- def Doselenium(self, targets, options):
- """Builds and runs the selenium tests."""
- print "selenium not yet implemented."
-
- def Dounit_tests(self, targets, options):
- """Builds and runs the unit tests."""
- print "unit_tests not yet implemented."
-
def main(args):
GypBuilder(args[1:])