Example #1
0
    def get_builder(self, install_dir: str, input_prefixes: Iterable[str],
                    build_type: BuildType) -> Optional[Builder]:
        remote = self.get_remote()
        source_dir = remote.get_source_dir()
        buildsystem = self.get_buildsystem(source_dir)
        factory = None

        if buildsystem is BuildSystem.MAKEFILE:
            factory = MakefileBuilder
        elif buildsystem is BuildSystem.CMAKE:
            factory = CMakeBuilder
        elif buildsystem is BuildSystem.XCODE:
            factory = XcodeBuilder

        if not factory:
            self.view.error('Unknown build system')
            raise BuildError()

        caller = SubprocessCaller(self.view)

        return factory(buildfile_dir=source_dir,
                       build_dir=self.storage.get_build_dir(
                           self.get_label(), build_type),
                       install_dir=install_dir,
                       additional_prefix_paths=input_prefixes,
                       build_type=build_type,
                       properties=self.properties,
                       caller=caller,
                       view=self.view,
                       additional_cmake_defines=self.dependency.cmake_defines)
Example #2
0
    def update_final_prefix(self, labels: Iterable[str], build_type: BuildType):
        success = True
        dst_prefix = self.storage.get_install_dir(build_type)
        installed_files: Dict[str, str] = {}

        for label in labels:
            src_prefix = self.get_isolated_prefix(label, build_type)

            for dirpath, dirnames, filenames in os.walk(src_prefix):
                relpath = os.path.relpath(dirpath, src_prefix)
                dst_dir = os.path.join(dst_prefix, relpath)

                for dirname in dirnames:
                    os.makedirs(os.path.join(dst_dir, dirname), exist_ok=True)

                for filename in filenames:
                    src_path = os.path.join(dirpath, filename)
                    dst_path = os.path.join(dst_dir, filename)

                    prefix_neutral_path = os.path.join(relpath, filename)

                    shutil.copy2(src_path, dst_path)

                    if prefix_neutral_path in installed_files:
                        self.view.error(f'Conflicting prefix files found! file: {prefix_neutral_path}, first occurance: {installed_files[prefix_neutral_path]}, current occurance: {label}')
                        success = False
                    else:
                        # Only copy files if we are currently succeding.
                        if success:
                            shutil.copy2(src_path, dst_path)
                        installed_files[prefix_neutral_path] = label

        if not success:
            raise BuildError(f'Failed while installing files')
Example #3
0
    def build(self) -> None:
        build_dir = self.build_dir
        os.makedirs(build_dir, exist_ok=True)

        # Figure out which xcodeproj path we are using
        xcodeproj_path = ''
        for path in os.listdir(os.path.join(self.buildfile_dir)):
            if path.endswith('.xcodeproj'):
                xcodeproj_path = os.path.join(self.buildfile_dir, path)
                break

        if not xcodeproj_path:
            self.view.error('Cannot determine the xcodeproj to build with.')
            raise BuildError()

        self.caller.call([
            'xcodebuild', '-project', xcodeproj_path,
            'OBJROOT=' + os.path.join(build_dir, 'Intermediates'),
            'BUILD_DIR=' + os.path.join(build_dir, 'Products'),
            'SYMROOT=' + os.path.join(build_dir, 'Products'), 'build'
        ],
                         cwd=self.build_dir)
Example #4
0
    def build(self) -> None:
        install_dir = self.install_dir
        os.makedirs(self.build_dir, exist_ok=True)

        cmake_executable = self.get_cmake_executable()

        module_paths = [
            os.path.join(prefix, 'share', 'cmake', 'Modules')
            for prefix in self.prefix_paths
        ]

        generator = self.properties.cmake_generator
        if not generator:
            generator = guess_generator()
            if not generator:
                raise BuildError(
                    'Cannot guess CMake generator to use. '
                    'Please specify a generator using the --guess-generator flag.'
                )

        args = [
            cmake_executable,
            '-G',
            generator,
            self.buildfile_dir,
            '-DCMAKE_INSTALL_PREFIX={0}'.format(install_dir),
            '-DCMAKE_PREFIX_PATH={0}'.format(';'.join(self.prefix_paths)),
            '-DCMAKE_MODULE_PATH={0}'.format(';'.join(module_paths)),
            '-DCMAKE_BUILD_TYPE=Debug',  # TODO: Support building dependencies in release mode.

            # Lots of projects default to build shared libs instead of static. Let's add some consistency.
            # TODO: Need a system to choose the types of libraries desired.
            '-DBUILD_SHARED_LIBS=OFF'
        ]

        # Setup environment
        env = {
            'PATH': os.environ.get('PATH'),
            'CC': self.properties.c_compiler_path,
            'CXX': self.properties.cxx_compiler_path,
            'INVOKED_BY_DEW':
            'true'  # Set this environment variable to alert the dew CMake modules to no-op.
        }

        # Configure
        self.caller.call(args,
                         cwd=self.build_dir,
                         error_exception=BuildError,
                         env=env)

        build_args = [cmake_executable, '--build', '.']
        if generator in ('Unix Makefiles', 'MinGW Makefiles'):
            build_args.extend(('--', '-j', str(multiprocessing.cpu_count())))

        # Build
        self.caller.call(build_args,
                         cwd=self.build_dir,
                         error_exception=BuildError)

        # Install
        self.caller.call(
            [cmake_executable, '--build', '.', '--target', 'install'],
            cwd=self.build_dir,
            error_exception=BuildError)
Example #5
0
    def build(self) -> None:
        install_dir = self.install_dir
        os.makedirs(self.build_dir, exist_ok=True)

        cmake_executable = self.get_cmake_executable()

        prefix_paths = self.properties.prefixes.copy()
        prefix_paths.extend(self.additional_prefix_paths)
        prefix_paths = [pathlib.PurePath(prefix).as_posix() for prefix in prefix_paths]

        module_paths = [posixpath.join(prefix, 'share', 'cmake', 'Modules') for prefix in prefix_paths]

        generator = self.properties.cmake_generator
        if not generator:
            generator = guess_generator()
            if not generator:
                raise BuildError('Cannot guess CMake generator to use. ' 
                                 'Please specify a generator using the --cmake-generator flag.')

        args = [
            cmake_executable,
            '-G', generator,
            self.buildfile_dir,
            '-DCMAKE_PREFIX_PATH={0}'.format(';'.join(prefix_paths)),
            '-DCMAKE_MODULE_PATH={0}'.format(';'.join(module_paths)),
            '-DCMAKE_BUILD_TYPE={0}'.format(CMAKE_BUILD_TYPES[self.build_type]),

            # Lots of projects default to build shared libs instead of static. Let's add some consistency.
            # TODO: Need a system to choose the types of libraries desired.
            '-DBUILD_SHARED_LIBS=OFF'
        ]

        if install_dir:
            args.append('-DCMAKE_INSTALL_PREFIX={0}'.format(install_dir),)

        if self.additional_cmake_defines:
            args.extend([f'-D{k}={v}' for k, v in self.additional_cmake_defines.items()])

        # Setup environment
        env = {
            'CC': self.properties.c_compiler_path,
            'CXX': self.properties.cxx_compiler_path,
            'INVOKED_BY_DEW': 'true'  # Set this environment variable to alert the dew CMake modules to no-op.
        }

        # Configure
        self.caller.call(args, cwd=self.build_dir, error_exception=BuildError, env=env)

        build_args = [cmake_executable, '--build', '.']
        if generator in ('Unix Makefiles', 'MinGW Makefiles'):
            build_args.extend(('--', '-j', str(multiprocessing.cpu_count())))

        # Build
        self.caller.call(
            build_args,
            cwd=self.build_dir,
            error_exception=BuildError
        )

        # Install
        if install_dir:
            self.caller.call(
                [cmake_executable, '--build', '.', '--target', 'install'],
                cwd=self.build_dir,
                error_exception=BuildError
            )