Add an originalCwd property to builders (bug 6037, r=ds).
authorDavid Anderson <dvander@alliedmods.net>
Fri Feb 07 22:54:58 2014 -0800 (2014-02-07)
changeset 236aa23c47cb040
parent 235 fd0f5f1a7a10
child 237 a3ab09e0556b
Add an originalCwd property to builders (bug 6037, r=ds).
ambuild2/context.py
ambuild2/frontend/amb2/gen.py
ambuild2/frontend/base_gen.py
ambuild2/frontend/prep.py
tests/originalcwd/AMBuildScript
tests/originalcwd/configure.py
     1.1 --- a/ambuild2/context.py	Sun Feb 02 14:00:01 2014 -0800
     1.2 +++ b/ambuild2/context.py	Fri Feb 07 22:54:58 2014 -0800
     1.3 @@ -80,14 +80,7 @@
     1.4      )
     1.5  
     1.6      from ambuild2.frontend.amb2.gen import Generator
     1.7 -    gen = Generator(
     1.8 -      self.vars['sourcePath'],
     1.9 -      self.vars['buildPath'],
    1.10 -      self.vars['options'],
    1.11 -      self.vars['args'],
    1.12 -      self.db,
    1.13 -      self.options.refactor
    1.14 -    )
    1.15 +    gen = Generator.FromVars(self.vars, self.db, self.options.refactor)
    1.16      try:
    1.17        gen.generate()
    1.18      except:
     2.1 --- a/ambuild2/frontend/amb2/gen.py	Sun Feb 02 14:00:01 2014 -0800
     2.2 +++ b/ambuild2/frontend/amb2/gen.py	Fri Feb 07 22:54:58 2014 -0800
     2.3 @@ -27,8 +27,8 @@
     2.4      self.debug = debug_outputs
     2.5  
     2.6  class Generator(base_gen.Generator):
     2.7 -  def __init__(self, sourcePath, buildPath, options, args, db=None, refactoring=False):
     2.8 -    super(Generator, self).__init__(sourcePath, buildPath, options, args)
     2.9 +  def __init__(self, sourcePath, buildPath, originalCwd, options, args, db=None, refactoring=False):
    2.10 +    super(Generator, self).__init__(sourcePath, buildPath, originalCwd, options, args)
    2.11      self.cacheFolder = os.path.join(self.buildPath, '.ambuild2')
    2.12      self.old_scripts_ = set()
    2.13      self.old_folders_ = set()
    2.14 @@ -40,6 +40,28 @@
    2.15      self.is_bootstrap = not self.db
    2.16      self.refactoring = refactoring
    2.17  
    2.18 +  @classmethod
    2.19 +  def FromVars(cls, vars, db, refactoring):
    2.20 +    # Backwards compatibility: for an automatic reconfigure on an older build,
    2.21 +    # just assume the source path is the cwd. If the AMBuildScript suddenly
    2.22 +    # has decided to depend on originalCwd, then the user may have to manually
    2.23 +    # run configure.py again, until we remove configure.py entirely.
    2.24 +    if 'originalCwd' in vars:
    2.25 +      originalCwd = vars['originalCwd']
    2.26 +    else:
    2.27 +      originalCwd = vars['sourcePath']
    2.28 +
    2.29 +    gen = cls(
    2.30 +      sourcePath = vars['sourcePath'],
    2.31 +      buildPath = vars['buildPath'],
    2.32 +      originalCwd = originalCwd,
    2.33 +      options = vars['options'],
    2.34 +      args = vars['args'],
    2.35 +      db = db,
    2.36 +      refactoring = refactoring
    2.37 +    )
    2.38 +    return gen
    2.39 +
    2.40    def preGenerate(self):
    2.41      if not os.path.isdir(self.cacheFolder):
    2.42        os.mkdir(self.cacheFolder)
    2.43 @@ -137,6 +159,7 @@
    2.44      vars = {
    2.45        'sourcePath': self.sourcePath,
    2.46        'buildPath': self.buildPath,
    2.47 +      'originalCwd': self.originalCwd,
    2.48        'options': self.options,
    2.49        'args': self.args
    2.50      }
     3.1 --- a/ambuild2/frontend/base_gen.py	Sun Feb 02 14:00:01 2014 -0800
     3.2 +++ b/ambuild2/frontend/base_gen.py	Fri Feb 07 22:54:58 2014 -0800
     3.3 @@ -84,6 +84,10 @@
     3.4    def host_platform(self):
     3.5      return self.generator.host_platform
     3.6  
     3.7 +  @property
     3.8 +  def originalCwd(self):
     3.9 +    return self.generator.originalCwd
    3.10 +
    3.11    def SetBuildFolder(self, folder):
    3.12      if folder == '/' or folder == '.' or folder == './':
    3.13        self.buildFolder = ''
    3.14 @@ -139,9 +143,10 @@
    3.15      return self.generator.addConfigureFile(self, path)
    3.16  
    3.17  class Generator(object):
    3.18 -  def __init__(self, sourcePath, buildPath, options, args):
    3.19 +  def __init__(self, sourcePath, buildPath, originalCwd, options, args):
    3.20      self.sourcePath = sourcePath
    3.21      self.buildPath = os.path.normpath(buildPath)
    3.22 +    self.originalCwd = originalCwd
    3.23      self.options = options
    3.24      self.args = args
    3.25      self.compiler = None
     4.1 --- a/ambuild2/frontend/prep.py	Sun Feb 02 14:00:01 2014 -0800
     4.2 +++ b/ambuild2/frontend/prep.py	Fri Feb 07 22:54:58 2014 -0800
     4.3 @@ -97,10 +97,7 @@
     4.4  
     4.5      if options.generator == 'ambuild2':
     4.6        from ambuild2.frontend.amb2 import gen
     4.7 -      builder = gen.Generator(self.sourcePath, self.buildPath, options, args)
     4.8 -    elif options.generator == 'vcxproj':
     4.9 -      from ambuild2.frontend import vcxproj_gen
    4.10 -      builder = vcxproj_gen.Generator(self.sourcePath, self.buildPath, options, args)
    4.11 +      builder = gen.Generator(self.sourcePath, self.buildPath, os.getcwd(), options, args)
    4.12      else:
    4.13        sys.stderr.write('Unrecognized build generator: ' + options.generator + '\n')
    4.14        sys.exit(1)
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tests/originalcwd/AMBuildScript	Fri Feb 07 22:54:58 2014 -0800
     5.3 @@ -0,0 +1,6 @@
     5.4 +# vim: set ts=8 sts=2 tw=99 et ft=python: 
     5.5 +import os, sys
     5.6 +
     5.7 +# This should print the same thing as when configure.py'd, no matter where
     5.8 +# we build from, when AMBuildScript changes.
     5.9 +print(builder.originalCwd)
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tests/originalcwd/configure.py	Fri Feb 07 22:54:58 2014 -0800
     6.3 @@ -0,0 +1,6 @@
     6.4 +# vim: set sts=2 ts=8 sw=2 tw=99 et:
     6.5 +import sys
     6.6 +from ambuild2 import run
     6.7 +
     6.8 +builder = run.PrepareBuild(sourcePath = sys.path[0])
     6.9 +builder.Configure()