示例#1
0
  def __init__(self, buildPath, options, args):
    self.buildPath = buildPath
    self.options = options
    self.args = args
    self.cacheFolder = os.path.join(buildPath, '.ambuild2')
    self.dbpath = os.path.join(self.cacheFolder, 'graph')

    # This doesn't completely work yet because it's not communicated to child
    # processes. We'll have to send a message down or up to fix this.
    if self.options.no_color:
      util.DisableConsoleColors()

    with open(os.path.join(self.cacheFolder, 'vars'), 'rb') as fp:
      try:
        self.vars = util.pickle.load(fp)
      except ValueError as exn:
        sys.stderr.write('Build was configured with Python 3; use python3 instead.\n')
        sys.exit(1)
      except Exception as exn:
        if os.path.exists(os.path.join(self.cacheFolder, 'vars')):
          sys.stderr.write('There does not appear to be a build configured here.\n')
        else:
          sys.stderr.write('The build configured here looks corrupt; you will have to delete your objdir.\n')
        raise
        sys.exit(1)

    self.restore_environment()

    self.db = database.Database(self.dbpath)
    self.messagePump = MessagePump()
    self.procman = ProcessManager(self.messagePump)
    self.db.connect()
示例#2
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)
示例#3
0
文件: prep.py 项目: askovpen/ambuild
    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)