예제 #1
0
    def install_cpp_prebuilt_atom(self, atom, check_arch=True):
        '''Installs a prebuilt atom from the "cpp" domain.'''
        if check_arch and atom.tags['arch'] != 'target':
            print('Only libraries compiled for a target are supported, '
                  'skipping %s.' % atom.id)
            return

        name = sanitize(atom.id.name)
        library = model.CppPrebuiltLibrary(name, self.metadata.target_arch)
        base = self.dest('pkg', name)

        for file in atom.files:
            destination = file.destination
            extension = os.path.splitext(destination)[1][1:]
            if extension == 'so' or extension == 'a' or extension == 'o':
                relative_dest = os.path.join('arch', self.metadata.target_arch,
                                             destination)
                dest = os.path.join(base, relative_dest)
                if os.path.isfile(dest):
                    raise Exception('File already exists: %s.' % dest)
                self.make_dir(dest)
                shutil.copy2(file.source, dest)
                if ((extension == 'so' or extension == 'a')
                        and destination.startswith('lib')):
                    if library.prebuilt:
                        raise Exception('Multiple prebuilts for %s.' % dest)
                    library.prebuilt = relative_dest
                    library.is_static = extension == 'a'
                if file.is_packaged:
                    package_path = 'lib/%s' % os.path.basename(relative_dest)
                    library.packaged_files[package_path] = relative_dest
            elif self.is_overlay:
                # Only binaries get installed in overlay mode.
                continue
            elif (extension == 'h' or extension == 'modulemap'
                  or extension == 'inc' or extension == 'rs'):
                dest = self.make_dir(os.path.join(base, destination))
                shutil.copy2(file.source, dest)
                if extension == 'h':
                    library.hdrs.append(destination)
            else:
                raise Exception('Error: unknow file extension "%s" for %s.' %
                                (extension, atom.id))

        for dep_id in atom.deps:
            library.deps.append('//pkg/' + sanitize(dep_id.name))
        library.includes.append('include')

        # Only write the prebuilt library BUILD top when not in overlay mode.
        if not self.is_overlay:
            self.write_file(os.path.join(base, 'BUILD'),
                            'cc_prebuilt_library_top', library)

        # Write the arch-specific target.
        self.write_file(os.path.join(base, 'BUILD'),
                        'cc_prebuilt_library_srcs',
                        library,
                        append=True)
    def install_cc_prebuilt_library_atom(self, atom):
        name = atom['name']
        # Add atom to test targets
        self.cc_prebuilt_targets.append(name)
        base = self.dest('pkg', name)
        library = model.CppPrebuiltLibrary(name)
        library.relative_path_to_root = os.path.relpath(self.output,
                                                        start=base)
        library.is_static = atom['format'] == 'static'

        self.copy_files(atom['headers'], atom['root'], base, library.hdrs)

        for arch in self.target_arches:

            def _copy_prebuilt(path, category):
                relative_dest = os.path.join(
                    'arch',
                    arch,  # pylint: disable=cell-var-from-loop
                    category,
                    os.path.basename(path))
                dest = self.dest(relative_dest)
                shutil.copy2(self.source(path), dest)
                return relative_dest

            binaries = atom['binaries'][arch]
            prebuilt_set = model.CppPrebuiltSet(
                _copy_prebuilt(binaries['link'], 'lib'))
            if 'dist' in binaries:
                dist = binaries['dist']
                prebuilt_set.dist_lib = _copy_prebuilt(dist, 'dist')
                prebuilt_set.dist_path = binaries['dist_path']

            if 'debug' in binaries:
                self.copy_file(binaries['debug'])

            library.prebuilts[arch] = prebuilt_set

        for dep in atom['deps']:
            library.deps.append('../' + dep)

        library.includes = os.path.relpath(atom['include_dir'], atom['root'])

        if not os.path.exists(base):
            os.makedirs(base)
        self.write_file(os.path.join(base, 'BUILD.gn'), 'cc_prebuilt_library',
                        library)
        self.write_atom_metadata(os.path.join(base, 'meta.json'), atom)
        self.build_files.append(
            os.path.relpath(os.path.join(base, 'BUILD.gn'), self.output))
예제 #3
0
파일: generate.py 프로젝트: lmlg/fuchsia
    def install_cc_prebuilt_library_atom(self, atom):
        name = sanitize(atom['name'])
        include_paths = [
            os.path.relpath(h, atom['include_dir']) for h in atom['headers']
        ]
        self.workspace_info.headers['//pkg/' + name] = include_paths

        if not self.install:
            return

        library = model.CppPrebuiltLibrary(name)
        library.is_static = atom['format'] == 'static'
        base = self.dest('pkg', name)
        self.copy_files(atom['headers'], atom['root'], base, library.hdrs)

        for arch in self.target_arches:

            def _copy_prebuilt(path, category):
                relative_dest = os.path.join('arch', arch, category,
                                             os.path.basename(path))
                dest = self.dest(base, relative_dest)
                shutil.copy2(self.source(path), dest)
                return relative_dest

            binaries = atom['binaries'][arch]
            prebuilt_set = model.CppPrebuiltSet(
                _copy_prebuilt(binaries['link'], 'lib'))
            if 'dist' in binaries:
                dist = binaries['dist']
                prebuilt_set.dist_lib = _copy_prebuilt(dist, 'dist')
                prebuilt_set.dist_path = 'lib/' + os.path.basename(dist)

            if 'debug' in binaries:
                self.copy_file(binaries['debug'])

            library.prebuilts[arch] = prebuilt_set

        for dep in atom['deps']:
            library.deps.append('//pkg/' + sanitize(dep))

        library.includes = os.path.relpath(atom['include_dir'], atom['root'])

        self.write_file(os.path.join(base, 'BUILD'), 'cc_prebuilt_library',
                        library)
예제 #4
0
    def install_cc_prebuilt_library_atom(self, atom):
        name = atom['name']
        # Add atom to test targets
        self.cc_prebuilt_targets.append(name)
        base = self.dest('pkg', name)
        library = model.CppPrebuiltLibrary(name)
        library.relative_path_to_root = os.path.relpath(self.output,
                                                        start=base)
        library.is_static = atom['format'] == 'static'

        self.copy_files(atom['headers'], atom['root'], base, library.hdrs)

        for arch in self.target_arches:
            binaries = atom['binaries'][arch]
            prebuilt_set = model.CppPrebuiltSet(binaries['link'])
            self.copy_file(binaries['link'])

            if 'dist' in binaries:
                prebuilt_set.dist_lib = binaries['dist']
                prebuilt_set.dist_path = binaries['dist_path']
                self.copy_file(binaries['dist'])

            if 'debug' in binaries:
                self.copy_file(binaries['debug'])

            library.prebuilts[arch] = prebuilt_set

        for dep in atom['deps']:
            library.deps.append('../' + dep)

        library.includes = os.path.relpath(atom['include_dir'], atom['root'])

        if not os.path.exists(base):
            os.makedirs(base)
        self.write_file(os.path.join(base, 'BUILD.gn'), 'cc_prebuilt_library',
                        library)
        self.write_atom_metadata(os.path.join(base, 'meta.json'), atom)
        self.build_files.append(
            os.path.relpath(os.path.join(base, 'BUILD.gn'), self.output))