Beispiel #1
0
def cmd_export(ctx: ProjectContext, args: argparse.Namespace) -> int:
    """Exports the currently built shared libraries and headers."""
    top_level_dir_name: str = 'calendon-0.0.1'
    if args.output_dir:
        export_dir = os.path.join(args.output_dir, top_level_dir_name)
    else:
        export_dir = os.path.join(ctx.export_dir(), top_level_dir_name)

    header_dir: str = os.path.join(export_dir, 'include', 'calendon')
    base_dir: str = ctx.source_dir()
    print(f'Exporting from {ctx.build_dir()} to {export_dir}')

    if os.path.isdir(export_dir):
        print(f'Removing export directory: {export_dir}')
        shutil.rmtree(export_dir)

    shutil.copytree(base_dir, header_dir, ignore=shutil.ignore_patterns('*.c', 'CMakeLists.txt'))
    print('Exported Headers:')
    print(f' - {header_dir}')

    # TODO: Allow export as other architectures other than x64.
    lib_dir = os.path.join(export_dir, 'lib', 'x64')
    os.makedirs(lib_dir, exist_ok=True)

    libraries = glob.glob(os.path.join(ctx.build_dir(), mp.shared_lib_glob()))
    libraries.extend(glob.glob(os.path.join(ctx.build_dir(), mp.static_lib_glob())))
    print('Exporting Libraries:')
    for lib in libraries:
        exported_lib: str = os.path.basename(lib)
        shutil.copyfile(lib, os.path.join(lib_dir, exported_lib))
        print(f'- {exported_lib}')

    print(f'Exported Calendon to: {export_dir}')
    return 0
Beispiel #2
0
def cmd_build(ctx: ProjectContext, args: argparse.Namespace) -> int:
    """Build using the current project configuration."""
    if not _verify_executable_exists(ctx, 'cmake'):
        return 1

    if not _verify_build_dir_exists(ctx.build_dir()):
        return 1

    cmake_args = [ctx.path_for_program('cmake'), '--build', '.',
                  '--parallel', str(multiprocessing.cpu_count()),
                  '--config', ctx.build_config()]

    if args.dry_run:
        print(f'Would have run {cmake_args} in {ctx.build_dir()}')
        return 0

    return run_program(cmake_args, cwd=(ctx.build_dir()))
Beispiel #3
0
def cmd_check(ctx: ProjectContext, args: argparse.Namespace) -> int:
    """Runs tests."""
    if not _verify_executable_exists(ctx, 'cmake'):
        return 1

    if not _verify_build_dir_exists(ctx.build_dir()):
        return 1

    check_target: str = 'check'
    if args.iterate:
        check_target += '-iterate'

    cmake_args = [ctx.path_for_program('cmake'), '--build', '.',
                  '--target', check_target,
                  '--config', ctx.build_config()]
    if args.dry_run:
        print(f'Would have run {cmake_args} in {ctx.build_dir()}')
        return 0
    else:
        return run_program(cmake_args, cwd=(ctx.build_dir()))
Beispiel #4
0
def cmd_gen(ctx: ProjectContext, args: argparse.Namespace) -> int:
    """Runs the generator to make build files like Visual Studio solutions."""
    if not _verify_executable_exists(ctx, 'cmake'):
        return 1

    if ctx.compiler() is not None and not _verify_executable_exists(ctx, ctx.compiler()):
        return 1

    build_dir = ctx.build_dir()
    if os.path.isfile(build_dir):
        print(f'Build directory {build_dir} exists as something other than a directory')
        return 1
    if os.path.isdir(build_dir):
        if args.force:
            if args.dry_run:
                print(f'Would have removed previously existing directory {build_dir}')
            else:
                shutil.rmtree(build_dir)
        else:
            print(f'{build_dir} exists.  Use --force to wipe and recreate the build dir.')
            return 1

    if args.dry_run:
        print(f'Would have created {build_dir}')
    else:
        print(f'Creating build directory {build_dir}')
        os.mkdir(build_dir)

    cmake_path: str = ctx.path_for_program('cmake')
    cmake_args = [cmake_path, '..']
    if args.enable_ccache:
        cmake_args.append('-DCN_ENABLE_CCACHE=1')

    compiler = ctx.compiler()
    if compiler is not None:
        compiler = ctx.path_for_program(compiler)
    cmake_args.extend(generator_settings_for_compiler(cmake_path, compiler))

    if args.dry_run:
        print(f'Would have run {cmake_args} in {build_dir}')
        return 0

    return run_program(cmake_args, cwd=build_dir)
Beispiel #5
0
def cmd_clean(ctx: ProjectContext, args: argparse.Namespace) -> int:
    """Clean up the build directory and build files."""
    build_dir: str = ctx.build_dir()
    if not os.path.exists(build_dir):
        return 0

    if not os.path.isdir(build_dir):
        print(f'Build directory {build_dir} is not a directory')
        return 1

    if args.dry_run:
        print('Dry run')
        print(f'Would have removed: {build_dir}')
    else:
        print(f'Removing: {build_dir}')
        try:
            shutil.rmtree(build_dir)
        except OSError as err:
            print(f'Error removing {build_dir} {str(err)}')
    return 0