예제 #1
0
파일: Build.py 프로젝트: GelvinBelson/gooz
    def BuildLibrary(self, library_ppath, object_ppaths):
        """Builds a static library.

    Args:
      library_path: The library target project path.
      object_paths: The objects project paths.
    """
        library_apath = os.path.join(self._output_dir, library_ppath)
        misc.MakeDirectoriesFor(library_apath)
        object_apaths = [
            os.path.join(self._output_dir, ppath) for ppath in object_ppaths
        ]
        if self.IsUpToDate(object_ppaths, [library_ppath]):
            logging.info('%s is up to date', library_ppath)
            return
        for object_apath in object_apaths:
            assert os.path.exists(object_apath), ('Cannot find object: %s' %
                                                  object_apath)
        command = ([self.vars.AR, 'rc', library_apath] + object_apaths)
        logging.info('Building library: %s', library_ppath)
        self.Exec(command)

        assert os.path.exists(library_apath)
        command = [self.vars.RANLIB, library_apath]
        self.Exec(command)

        self.RecordMetadata(object_ppaths, [library_ppath])
예제 #2
0
파일: Build.py 프로젝트: GelvinBelson/gooz
    def CompileCC(self, source_ppath):
        """Compiles a C++ source file into an object file.

    Args:
      source_ppath: .cc file project path.
    """
        source_apath = self.GetSourceAbsolutePath(source_ppath)
        object_ppath = misc.SwitchSuffix(source_ppath, '.cc', '.o')
        object_apath = os.path.join(self._output_dir, object_ppath)

        source_ppaths = set([source_ppath])
        source_ppaths.update(self.GetCCIncludesClosure(source_ppath))
        target_ppaths = [object_ppath]
        if self.IsUpToDate(source_ppaths, target_ppaths):
            logging.info('%s -> %s is up to date', source_ppath, object_ppath)
            return

        misc.MakeDirectoriesFor(object_apath)
        command = (self.vars.CXX_COMPILER_COMMAND + self.vars.CXX_FLAGS + [
            '-I' + self._source_dir,
            '-I' + self._output_dir,
            '-c',
            source_apath,
            '-o',
            object_apath,
        ])
        logging.info('Compiling C++: %s', source_ppath)
        self.Exec(command)

        self.RecordMetadata(source_ppaths, target_ppaths)
예제 #3
0
파일: Build.py 프로젝트: GelvinBelson/gooz
    def LinkProgram(self,
                    program_ppath,
                    object_ppaths,
                    library_ppaths,
                    link_flags=Default):
        """Links a C++ binary."""
        if link_flags is Default: link_flags = self.vars.LINK_OPTIONS
        program_apath = os.path.join(self._output_dir, program_ppath)
        misc.MakeDirectoriesFor(program_apath)
        object_apaths = [
            self.GetSourceAbsolutePath(ppath) for ppath in object_ppaths
        ]
        library_apaths = [
            self.GetSourceAbsolutePath(ppath) for ppath in library_ppaths
        ]

        # Check if program is already up-to-date
        source_ppaths = list(object_ppaths) + library_ppaths
        target_ppaths = [program_ppath]
        if self.IsUpToDate(source_ppaths, target_ppaths):
            logging.info('Program %s is up to date', program_ppath)
            return

        for object_apath in object_apaths:
            assert os.path.exists(object_apath), ('Cannot find object %s' %
                                                  object_apath)
        for library_apath in library_apaths:
            assert os.path.exists(library_apath), ('Cannot find library %s' %
                                                   library_apath)
        command = ([self.vars.LINKER] + ['-o', program_apath] + link_flags +
                   library_apaths + object_apaths + library_apaths +
                   link_flags)
        logging.info('Linking binary: %s', program_ppath)
        self.Exec(command)

        self.RecordMetadata(source_ppaths, target_ppaths)