Esempio n. 1
0
    def importScript(self, context, file, vars=None):
        path = os.path.normpath(os.path.join(context.sourcePath, file))
        self.addConfigureFile(context, path)

        new_vars = copy.copy(vars or {})
        new_vars['builder'] = context

        code = self.compileScript(path)
        exec(code, new_vars)

        obj = util.Expando()
        for key in new_vars:
            setattr(obj, key, new_vars[key])
        return obj
Esempio n. 2
0
    def importScriptImpl(self, parent, path, vars):
        assert isinstance(path, util.StringType())

        sourceFolder, _, scriptFile = self.computeScriptPaths(parent, path)

        # Get the absolute script path.
        scriptPath = os.path.join(self.sourcePath, scriptFile)
        self.addConfigureFile(parent, scriptPath)

        # Make the new context.
        cx = EmptyContext(self, parent, vars, scriptPath)
        scriptGlobals = self.execContext(cx)

        # Only return variables that changed.
        obj = util.Expando()
        for key in scriptGlobals:
            if (not key in cx.vars_) or (scriptGlobals[key]
                                         is not cx.vars_[key]):
                setattr(obj, key, scriptGlobals[key])
        return obj
Esempio n. 3
0
    def Configure(self):
        args = self.options.parse_args()

        # In order to support pickling, we need to rewrite |options| to not use
        # optparse.Values, since its implementation changes across Python versions.
        options = util.Expando()
        for attr in vars(args):
            setattr(options, attr, getattr(args, attr))

        if options.list_gen:
            print('Available build system generators:')
            print('  {0:24} - AMBuild 2 (default)'.format('ambuild2'))
            print('  {0:24} - Visual Studio'.format('vs'))
            print('')
            print('Extra options:')
            print(
                '  --vs-version=N        Visual Studio: IDE version (2015 or 14 default)'
            )
            print(
                '  --vs-split            Visual Studio: generate one project file per configuration'
            )
            sys.exit(0)

        if options.no_color:
            util.DisableConsoleColors()

        source_abspath = os.path.normpath(os.path.abspath(self.sourcePath))
        build_abspath = os.path.normpath(os.path.abspath(self.buildPath))
        if source_abspath == build_abspath:
            if util.IsString(self.default_build_folder):
                objfolder = self.default_build_folder
            else:
                objfolder = self.default_build_folder(self)
            new_buildpath = os.path.join(self.buildPath, objfolder)

            util.con_err(
                util.ConsoleHeader,
                'Warning: build is being configured in the source tree.',
                util.ConsoleNormal)
            if os.path.exists(os.path.join(new_buildpath)):
                has_amb2 = os.path.exists(
                    os.path.join(new_buildpath, '.ambuild2'))
                if not has_amb2 and len(os.listdir(
                        new_buildpath)) and options.generator == 'ambuild2':
                    util.con_err(util.ConsoleRed, 'Tried to use ',
                                 util.ConsoleBlue, objfolder, util.ConsoleRed,
                                 ' as a build folder, but it is not empty!',
                                 util.ConsoleNormal)
                    raise Exception('build folder has unrecognized files')

                util.con_err(util.ConsoleHeader, 'Re-using build folder: ',
                             util.ConsoleBlue, '{0}'.format(objfolder),
                             util.ConsoleNormal)
            else:
                util.con_err(util.ConsoleHeader, 'Creating "',
                             util.ConsoleBlue, '{0}'.format(objfolder),
                             util.ConsoleHeader, '" as a build folder.',
                             util.ConsoleNormal)
                os.mkdir(new_buildpath)
            self.buildPath = new_buildpath

        from ambuild2.frontend.v2_2.context_manager import ContextManager

        cm = ContextManager(self.sourcePath, self.buildPath, os.getcwd(),
                            options, args)

        with util.FolderChanger(self.buildPath):
            try:
                if not cm.generate(options.generator):
                    sys.stderr.write('Configure failed.\n')
                    sys.exit(1)
            except Exception as e:
                traceback.print_exc()
                util.con_err(util.ConsoleRed, 'Configure failed: {}'.format(e),
                             util.ConsoleNormal)
Esempio n. 4
0
    def Configure(self):
        if self.target_arch is None:
            self.options.add_option("--target-arch",
                                    type="string",
                                    dest="target_arch",
                                    default=None,
                                    help="Override the target architecture.")

        v_options, args = self.options.parse_args()

        # In order to support pickling, we need to rewrite |options| to not use
        # optparse.Values, since its implementation changes across Python versions.
        options = util.Expando()
        ignore_attrs = set(dir(Values))
        for attr in dir(v_options):
            if attr in ignore_attrs:
                continue
            setattr(options, attr, getattr(v_options, attr))

        # Propagate the overridden architecture.
        if self.target_arch is not None:
            assert getattr(options, 'target_arch', None) is None
            options.target_arch = self.target_arch

        if options.list_gen:
            print('Available build system generators:')
            print('  {0:24} - AMBuild 2 (default)'.format('ambuild2'))
            print('  {0:24} - Visual Studio'.format('vs'))
            print('')
            print('Extra options:')
            print(
                '  --vs-version=N        Visual Studio: IDE version (2010 or 10 default)'
            )
            print(
                '  --vs-split            Visual Studio: generate one project file per configuration'
            )
            sys.exit(0)

        if options.no_color:
            util.DisableConsoleColors()

        source_abspath = os.path.normpath(os.path.abspath(self.sourcePath))
        build_abspath = os.path.normpath(os.path.abspath(self.buildPath))
        if source_abspath == build_abspath:
            if util.IsString(self.default_build_folder):
                objfolder = self.default_build_folder
            else:
                objfolder = self.default_build_folder(self)
            new_buildpath = os.path.join(self.buildPath, objfolder)

            util.con_err(
                util.ConsoleHeader,
                'Warning: build is being configured in the source tree.',
                util.ConsoleNormal)
            if os.path.exists(os.path.join(new_buildpath)):
                has_amb2 = os.path.exists(
                    os.path.join(new_buildpath, '.ambuild2'))
                if not has_amb2 and len(os.listdir(new_buildpath)):
                    util.con_err(util.ConsoleRed, 'Tried to use ',
                                 util.ConsoleBlue, objfolder, util.ConsoleRed,
                                 ' as a build folder, but it is not empty!',
                                 util.ConsoleNormal)
                    raise Exception('build folder has unrecognized files')

                util.con_err(util.ConsoleHeader, 'Re-using build folder: ',
                             util.ConsoleBlue, '{0}'.format(objfolder),
                             util.ConsoleNormal)
            else:
                util.con_err(util.ConsoleHeader, 'Creating "',
                             util.ConsoleBlue, '{0}'.format(objfolder),
                             util.ConsoleHeader, '" as a build folder.',
                             util.ConsoleNormal)
                os.mkdir(new_buildpath)
            self.buildPath = new_buildpath

        if options.generator == 'ambuild2':
            from ambuild2.frontend.v2_1.amb2 import gen
            builder = gen.Generator(self.sourcePath, self.buildPath,
                                    os.getcwd(), options, args)
        elif options.generator == 'vs':
            from ambuild2.frontend.v2_1.vs import gen
            builder = gen.Generator(self.sourcePath, self.buildPath,
                                    os.getcwd(), options, args)
        else:
            sys.stderr.write('Unrecognized build generator: ' +
                             options.generator + '\n')
            sys.exit(1)

        with util.FolderChanger(self.buildPath):
            if not builder.generate():
                sys.stderr.write('Configure failed.\n')
                sys.exit(1)