# HG changeset patch # User David Anderson # Date 1391842498 28800 # Node ID aa23c47cb040c88aaec0ad44e085328e033f93b3 # Parent fd0f5f1a7a10e18ed5fce2e163377c7ebaf55b5f Add an originalCwd property to builders (bug 6037, r=ds). diff -r fd0f5f1a7a10 -r aa23c47cb040 ambuild2/context.py --- a/ambuild2/context.py Sun Feb 02 14:00:01 2014 -0800 +++ b/ambuild2/context.py Fri Feb 07 22:54:58 2014 -0800 @@ -80,14 +80,7 @@ ) from ambuild2.frontend.amb2.gen import Generator - gen = Generator( - self.vars['sourcePath'], - self.vars['buildPath'], - self.vars['options'], - self.vars['args'], - self.db, - self.options.refactor - ) + gen = Generator.FromVars(self.vars, self.db, self.options.refactor) try: gen.generate() except: diff -r fd0f5f1a7a10 -r aa23c47cb040 ambuild2/frontend/amb2/gen.py --- a/ambuild2/frontend/amb2/gen.py Sun Feb 02 14:00:01 2014 -0800 +++ b/ambuild2/frontend/amb2/gen.py Fri Feb 07 22:54:58 2014 -0800 @@ -27,8 +27,8 @@ self.debug = debug_outputs class Generator(base_gen.Generator): - def __init__(self, sourcePath, buildPath, options, args, db=None, refactoring=False): - super(Generator, self).__init__(sourcePath, buildPath, options, args) + def __init__(self, sourcePath, buildPath, originalCwd, options, args, db=None, refactoring=False): + super(Generator, self).__init__(sourcePath, buildPath, originalCwd, options, args) self.cacheFolder = os.path.join(self.buildPath, '.ambuild2') self.old_scripts_ = set() self.old_folders_ = set() @@ -40,6 +40,28 @@ self.is_bootstrap = not self.db self.refactoring = refactoring + @classmethod + def FromVars(cls, vars, db, refactoring): + # Backwards compatibility: for an automatic reconfigure on an older build, + # just assume the source path is the cwd. If the AMBuildScript suddenly + # has decided to depend on originalCwd, then the user may have to manually + # run configure.py again, until we remove configure.py entirely. + if 'originalCwd' in vars: + originalCwd = vars['originalCwd'] + else: + originalCwd = vars['sourcePath'] + + gen = cls( + sourcePath = vars['sourcePath'], + buildPath = vars['buildPath'], + originalCwd = originalCwd, + options = vars['options'], + args = vars['args'], + db = db, + refactoring = refactoring + ) + return gen + def preGenerate(self): if not os.path.isdir(self.cacheFolder): os.mkdir(self.cacheFolder) @@ -137,6 +159,7 @@ vars = { 'sourcePath': self.sourcePath, 'buildPath': self.buildPath, + 'originalCwd': self.originalCwd, 'options': self.options, 'args': self.args } diff -r fd0f5f1a7a10 -r aa23c47cb040 ambuild2/frontend/base_gen.py --- a/ambuild2/frontend/base_gen.py Sun Feb 02 14:00:01 2014 -0800 +++ b/ambuild2/frontend/base_gen.py Fri Feb 07 22:54:58 2014 -0800 @@ -84,6 +84,10 @@ def host_platform(self): return self.generator.host_platform + @property + def originalCwd(self): + return self.generator.originalCwd + def SetBuildFolder(self, folder): if folder == '/' or folder == '.' or folder == './': self.buildFolder = '' @@ -139,9 +143,10 @@ return self.generator.addConfigureFile(self, path) class Generator(object): - def __init__(self, sourcePath, buildPath, options, args): + def __init__(self, sourcePath, buildPath, originalCwd, options, args): self.sourcePath = sourcePath self.buildPath = os.path.normpath(buildPath) + self.originalCwd = originalCwd self.options = options self.args = args self.compiler = None diff -r fd0f5f1a7a10 -r aa23c47cb040 ambuild2/frontend/prep.py --- a/ambuild2/frontend/prep.py Sun Feb 02 14:00:01 2014 -0800 +++ b/ambuild2/frontend/prep.py Fri Feb 07 22:54:58 2014 -0800 @@ -97,10 +97,7 @@ if options.generator == 'ambuild2': from ambuild2.frontend.amb2 import gen - builder = gen.Generator(self.sourcePath, self.buildPath, options, args) - elif options.generator == 'vcxproj': - from ambuild2.frontend import vcxproj_gen - builder = vcxproj_gen.Generator(self.sourcePath, self.buildPath, options, args) + builder = gen.Generator(self.sourcePath, self.buildPath, os.getcwd(), options, args) else: sys.stderr.write('Unrecognized build generator: ' + options.generator + '\n') sys.exit(1) diff -r fd0f5f1a7a10 -r aa23c47cb040 tests/originalcwd/AMBuildScript --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/originalcwd/AMBuildScript Fri Feb 07 22:54:58 2014 -0800 @@ -0,0 +1,6 @@ +# vim: set ts=8 sts=2 tw=99 et ft=python: +import os, sys + +# This should print the same thing as when configure.py'd, no matter where +# we build from, when AMBuildScript changes. +print(builder.originalCwd) diff -r fd0f5f1a7a10 -r aa23c47cb040 tests/originalcwd/configure.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/originalcwd/configure.py Fri Feb 07 22:54:58 2014 -0800 @@ -0,0 +1,6 @@ +# vim: set sts=2 ts=8 sw=2 tw=99 et: +import sys +from ambuild2 import run + +builder = run.PrepareBuild(sourcePath = sys.path[0]) +builder.Configure()