Пример #1
0
def update_framework_release_module_cmake(directory, project_module, contents):
    # Detect if needs update
    needs_update = False
    # Check for project definition relocation for v0.4
    if not 'dist_shared_crossplatform.cmake' in contents:
        needs_update = True
    if not _get_current_cmake_version_setter() in contents:
        needs_update = True
    if not needs_update:
        print("Module at %s doesn't need CMake update" % directory)
        return

    cmake = get_cmake_path()
    nap_root = get_nap_root()

    # Create module from template
    cmake_template_dir = os.path.abspath(
        os.path.join(nap_root, 'cmake', 'module_creator'))
    if not os.path.exists(cmake_template_dir):
        cmake_template_dir = os.path.abspath(
            os.path.join(nap_root, 'dist', 'cmake', 'native',
                         'module_creator'))

    print("Upgrading module CMake at %s" % directory)
    cmd = [
        cmake,
        '-DMODULE_CMAKE_OUTPATH=%s' %
        os.path.join(directory, 'CMakeLists.txt'),
        '%s' % '-DPROJECT_MODULE=1' if project_module else '',
        '-DCMAKE_ONLY=1', '-P',
        os.path.join(cmake_template_dir, 'module_creator.cmake')
    ]
    if call(cmd) != 0:
        print("CMake upgrade at %s failed" % directory)
Пример #2
0
def cmake_reconfigure_project(project_name, build_type, show_solution):
    # Find the project
    project_path = find_project(project_name)
    if project_path is None:
        return ERROR_MISSING_MODULE

    cmake = get_cmake_path()
    if sys.platform.startswith('linux'):
        exit_code = call([
            cmake, '-H.',
            '-B%s' % BUILD_DIR,
            '-DCMAKE_BUILD_TYPE=%s' % build_type
        ],
                         cwd=project_path)

        # Show in Nautilus?
        # Seems a bit pointless if we're not opening it in an IDE from the file browser
        # if show_solution:
        #     call(["nautilus -s %s > /dev/null 2>&1 &" % BUILD_DIR], shell=True)

    elif sys.platform == 'darwin':
        exit_code = call(
            [cmake, '-H.', '-B%s' % BUILD_DIR, '-G', 'Xcode'],
            cwd=project_path)

        # Show in Finder
        if exit_code == 0 and show_solution:
            xcode_solution_path = os.path.join(project_path, BUILD_DIR,
                                               '%s.xcodeproj' % project_name)
            call(["open", "-R", xcode_solution_path])
    else:
        # Create dir if it doesn't exist
        full_build_dir = os.path.join(project_path, BUILD_DIR)
        if not os.path.exists(full_build_dir):
            os.makedirs(full_build_dir)

        # Generate project
        exit_code = call([
            cmake, '-H.',
            '-B%s' % BUILD_DIR, '-G', 'Visual Studio 14 2015 Win64',
            '-DPYBIND11_PYTHON_VERSION=3.5'
        ],
                         cwd=project_path)

        # Show in Explorer
        if exit_code == 0 and show_solution:
            msvc_solution_path = os.path.join(project_path, BUILD_DIR,
                                              '%s.sln' % project_name)
            call(r'explorer /select,"%s"' % msvc_solution_path)

    if exit_code == 0:
        print("Solution generated in %s" %
              os.path.relpath(os.path.join(project_path, BUILD_DIR)))
        return 0
    else:
        return (ERROR_CONFIGURE_FAILURE)
Пример #3
0
def create_module(module_name, generate_solution):
    print("Creating module %s in user_modules/mod_%s" %
          (module_name, module_name.lower()))

    # Set our paths
    script_path = os.path.dirname(os.path.realpath(__file__))
    nap_root = os.path.abspath(os.path.join(script_path, os.pardir, os.pardir))
    cmake_template_dir = os.path.abspath(
        os.path.join(nap_root, 'cmake', 'module_creator'))
    module_path = os.path.abspath(
        os.path.join(nap_root, 'user_modules', 'mod_%s' % module_name.lower()))
    duplicate_module_path = os.path.abspath(
        os.path.join(nap_root, 'modules', 'mod_%s' % module_name.lower()))

    # Check for existing module with same name
    if os.path.exists(module_path):
        print("Error: Module with name %s already exists" % module_name)
        sys.exit(ERROR_EXISTING_MODULE)

    # Check for existing NAP module with same name
    if os.path.exists(duplicate_module_path):
        print("Error: NAP module exists with same name '%s'" % module_name)
        sys.exit(ERROR_EXISTING_MODULE)

    # Create module from template
    cmake = get_cmake_path()
    cmd = [
        cmake,
        '-DMODULE_NAME_PASCALCASE=%s' % module_name, '-P',
        'module_creator.cmake'
    ]
    if call(cmd, cwd=cmake_template_dir) != 0:
        print("Module creation failed")
        sys.exit(ERROR_CMAKE_CREATION_FAILURE)

    # Solution generation
    if generate_solution:
        print("Module created")
        print("Generating solution")

        # Determine our Python interpreter location
        python = get_python_path()

        cmd = [
            python, './tools/platform/regenerate_module_by_name.py',
            module_name.lower()
        ]
        if call(cmd, cwd=nap_root) != 0:
            print("Solution generation failed")
            sys.exit(ERROR_SOLUTION_GENERATION_FAILURE)
    else:
        print("Module created in %s" % os.path.relpath(module_path))
Пример #4
0
def update_project_cmake(directory):
    # Ensure it's a Framework Release context by verifying CMakeLists.txt contains nap_project.cmake
    file_path = os.path.join(directory, 'CMakeLists.txt')
    try:
        with open(file_path) as f:
            contents = f.read()
    except FileNotFoundError:
        return
    if not 'nap_project.cmake' in contents:
        return

    # Detect if needs update
    needs_update = False
    # Check for project definition relocation for v0.4
    if not 'dist_shared_crossplatform.cmake' in contents:
        needs_update = True
    if not _get_current_cmake_version_setter() in contents:
        needs_update = True
    if not needs_update:
        print("Project at %s doesn't need CMake update" % directory)
        return

    cmake = get_cmake_path()
    nap_root = get_nap_root()

    # Create module from template
    cmake_template_dir = os.path.abspath(
        os.path.join(nap_root, 'cmake', 'project_creator'))
    if not os.path.exists(cmake_template_dir):
        cmake_template_dir = os.path.abspath(
            os.path.join(nap_root, 'dist', 'cmake', 'native',
                         'project_creator'))

    print("Upgrading project CMake at %s" % directory)
    cmd = [
        cmake,
        '-DPROJECT_DIR=%s' % directory, '-DCMAKE_ONLY=1', '-P',
        os.path.join(cmake_template_dir, 'project_creator.cmake')
    ]
    if call(cmd) != 0:
        print("CMake upgrade at %s failed" % directory)
Пример #5
0
def update_module(module_name, build_type):
    # If module name is prefixed with mod_ remove it
    if module_name.startswith('mod_'):
        module_name = module_name[4:]

    # Find the module
    module_path = find_module(module_name)
    if module_path is None:
        return ERROR_MISSING_PROJECT

    cmake = get_cmake_path()
    if sys.platform.startswith('linux'):
        exit_code = call([
            cmake, '-H.',
            '-B%s' % BUILD_DIR,
            '-DCMAKE_BUILD_TYPE=%s' % build_type
        ],
                         cwd=module_path)
    elif sys.platform == 'darwin':
        exit_code = call(
            [cmake, '-H.', '-B%s' % BUILD_DIR, '-G', 'Xcode'], cwd=module_path)
    else:
        # Create dir if it doesn't exist
        full_build_dir = os.path.join(module_path, BUILD_DIR)
        if not os.path.exists(full_build_dir):
            os.makedirs(full_build_dir)

        exit_code = call([
            cmake, '-H.',
            '-B%s' % BUILD_DIR, '-G', 'Visual Studio 14 2015 Win64',
            '-DPYBIND11_PYTHON_VERSION=3.5'
        ],
                         cwd=module_path)

    if exit_code == 0:
        print("Solution generated in %s" %
              os.path.relpath(os.path.join(module_path, BUILD_DIR)))
        return 0
    else:
        return ERROR_CONFIGURE_FAILURE
Пример #6
0
def package_project(project_name, show_created_package, include_napkin, zip_package):
    # Find the project
    project_path = find_project(project_name)
    if project_path is None:
        return ERROR_MISSING_PROJECT

    # Process the project info to get project full name and version
    (project_version, project_full_name) = process_project_info(project_path)
    if project_version is None:
        return ERROR_INVALID_PROJECT_JSON

    print("Packaging %s v%s" % (project_full_name, project_version))

    project_name_lower = project_name.lower()

    # Build directory names
    script_path = os.path.realpath(__file__)
    nap_root = os.path.abspath(os.path.join(os.path.dirname(script_path), os.pardir))
    timestamp = datetime.datetime.now().strftime('%Y.%m.%dT%H.%M')
    local_bin_dir_name = 'bin_package'
    bin_dir = os.path.join(project_path, local_bin_dir_name)
    build_dir_name = os.path.join(project_path, 'build_package')
    cmake = get_cmake_path()        

    # Remove old packaging path if it exists
    if os.path.exists(bin_dir):
        shutil.rmtree(bin_dir, True)
    if os.path.exists(build_dir_name):
        shutil.rmtree(build_dir_name, True)
        
    if platform.startswith('linux'):
        # Generate makefiles
        call_except_on_failure(WORKING_DIR, [cmake, 
                              '-H%s' % project_path, 
                              '-B%s' % build_dir_name, 
                              '-DNAP_PACKAGED_APP_BUILD=1',
                              '-DCMAKE_BUILD_TYPE=%s' % PACKAGED_BUILD_TYPE, 
                              '-DPACKAGE_NAPKIN=%s' % int(include_napkin)])

        # Build & install to packaging dir
        call_except_on_failure(build_dir_name, ['make', 'all', 'install', '-j%s' % cpu_count()])

        # Create archive
        if zip_package:
            packaged_to = archive_to_linux_tar_bz2(timestamp, bin_dir, project_full_name, project_version)
        else:
            packaged_to = archive_to_timestamped_dir(timestamp, bin_dir, project_full_name, project_version, 'Linux')

        # Running from X/Wayland session
        gui_session = ('DISPLAY' or 'WAYLAND_DISPLAY') in os.environ

        # Show in Nautilus
        if show_created_package and gui_session:
            # Configurable command to show resulting file
            show_command = os.getenv('NAP_SHOW_FILE_COMMAND', 'nautilus -s %PACKAGE_PATH%')
            show_command = '%s > /dev/null 2>&1 &' % show_command.replace('%PACKAGE_PATH%', packaged_to)

            call([show_command], shell=True)
            # call(["nautilus -s %s > /dev/null 2>&1 &" % packaged_to], shell=True)

    elif platform == 'darwin':
        # Generate project
        call_except_on_failure(WORKING_DIR, [cmake, 
                               '-H%s' % project_path, 
                               '-B%s' % build_dir_name, 
                               '-G', 'Xcode',
                               '-DNAP_PACKAGED_APP_BUILD=1',
                               '-DPACKAGE_NAPKIN=%s' % int(include_napkin)])

        # Build & install to packaging dir
        call_except_on_failure(build_dir_name, ['xcodebuild', '-configuration', PACKAGED_BUILD_TYPE, '-target', 'install'])

        # Create archive
        if zip_package:
            packaged_to = archive_to_macos_zip(timestamp, bin_dir, project_full_name, project_version)
        else:
            packaged_to = archive_to_timestamped_dir(timestamp, bin_dir, project_full_name, project_version, 'macOS')

        # Show in Finder
        if show_created_package:
            call(["open", "-R", packaged_to])
    else:
        # Generate project
        call_except_on_failure(WORKING_DIR, [cmake, 
                           '-H%s' % project_path, 
                           '-B%s' % build_dir_name, 
                           '-G', 'Visual Studio 14 2015 Win64', 
                           '-DNAP_PACKAGED_APP_BUILD=1',
                           '-DPYBIND11_PYTHON_VERSION=3.5', 
                           '-DPROJECT_PACKAGE_BIN_DIR=%s' % local_bin_dir_name,
                           '-DPACKAGE_NAPKIN=%s' % int(include_napkin)])

        # Build & install to packaging dir
        call_except_on_failure(build_dir_name, [cmake, '--build', '.', '--target', 'install', '--config', PACKAGED_BUILD_TYPE])

        # Create archive
        if zip_package:
            packaged_to = archive_to_win64_zip(timestamp, bin_dir, project_full_name, project_version)
        else:
            packaged_to = archive_to_timestamped_dir(timestamp, bin_dir, project_full_name, project_version, 'Win64')

        # Show in Explorer
        if show_created_package:
            call(r'explorer /select,"%s"' % packaged_to)

    # Cleanup
    shutil.rmtree(build_dir_name, True)

    # Clean exit code
    return 0
Пример #7
0
def create_project_module(project_name, update_project_json, generate_solution,
                          show_solution):
    # Ensure project exists
    project_path = find_project(project_name, True)
    if project_path is None:
        print("Error: can't find project with name '%s'" % project_name)
        sys.exit(ERROR_MISSING_PROJECT)

    # Load camelcase project name from project.json
    module_name = get_camelcase_project_name(project_name)

    # Set our paths
    module_path = os.path.join(project_path, 'module')
    script_path = os.path.dirname(os.path.realpath(__file__))
    nap_root = os.path.abspath(os.path.join(script_path, os.pardir, os.pardir))
    cmake_template_dir = os.path.abspath(
        os.path.join(nap_root, 'cmake', 'module_creator'))
    user_module_path = os.path.abspath(
        os.path.join(nap_root, 'user_modules', 'mod_%s' % module_name.lower()))
    duplicate_module_path = os.path.abspath(
        os.path.join(nap_root, 'modules', 'mod_%s' % module_name.lower()))

    # Ensure project doesn't already have module
    if os.path.exists(module_path):
        print("Error: '%s' already has a module" % project_name)
        sys.exit(ERROR_EXISTING_MODULE)

    # Check for existing module with same name
    if os.path.exists(user_module_path):
        print("Error: User module with name %s already exists" % module_name)
        sys.exit(ERROR_EXISTING_MODULE)

    # Check for existing NAP module with same name
    if os.path.exists(duplicate_module_path):
        print("Error: NAP module exists with same name '%s'" % module_name)
        sys.exit(ERROR_EXISTING_MODULE)

    print("Creating project module mod_%s for project %s in %s" %
          (module_name.lower(), module_name, module_path))

    # Create module from template
    cmake = get_cmake_path()
    cmd = [
        cmake,
        '-DMODULE_NAME_PASCALCASE=%s' % module_name, '-DPROJECT_MODULE=1',
        '-DPROJECT_MODULE_PROJECT_PATH=%s' % project_path, '-P',
        'module_creator.cmake'
    ]
    if call(cmd, cwd=cmake_template_dir) != 0:
        print("Module creation failed")
        sys.exit(ERROR_CMAKE_CREATION_FAILURE)

    if update_project_json:
        # Update project.json
        add_module_to_project_json(project_name,
                                   'mod_%s' % module_name.lower())

        # Solution regeneration
        if generate_solution:
            print("Module created")
            print("Regenerating solution")

            # Determine our Python interpreter location
            python = get_python_path()

            cmd = [
                python, './tools/platform/regenerate_project_by_name.py',
                project_name
            ]
            if not show_solution and not sys.platform.startswith('linux'):
                cmd.append('--no-show')
            if call(cmd, cwd=nap_root) != 0:
                print("Solution generation failed")
                sys.exit(ERROR_SOLUTION_GENERATION_FAILURE)

    print("Project module created in %s" % os.path.relpath(module_path))
Пример #8
0
def create_project(project_name, module_list, with_module, generate_solution,
                   show_solution):
    print("Creating project %s" % project_name)

    # Set our paths
    script_path = os.path.dirname(os.path.realpath(__file__))
    nap_root = os.path.join(script_path, os.pardir, os.pardir)

    cmake_template_dir = os.path.abspath(
        os.path.join(nap_root, 'cmake', 'project_creator'))
    project_path = os.path.abspath(
        os.path.join(nap_root, 'projects', '%s' % project_name.lower()))

    # Check for duplicate project
    if not find_project(project_name, True) is None:
        print("Error: demo, example or project exists with same name '%s'" %
              project_name)
        return ERROR_EXISTING_PROJECT

    # Create project from template
    input_module_list = module_list.lower().replace(',', ';')
    cmake = get_cmake_path()
    cmd = [
        cmake,
        '-DPROJECT_NAME_PASCALCASE=%s' % project_name,
        '-DMODULE_LIST=%s' % input_module_list, '-P', 'project_creator.cmake'
    ]
    if call(cmd, cwd=cmake_template_dir) != 0:
        print("Project creation failed")
        return ERROR_CMAKE_CREATION_FAILURE

    # Add project module on request
    if with_module:
        # Create module from template
        cmake_template_dir = os.path.abspath(
            os.path.join(nap_root, 'cmake', 'module_creator'))
        input_module_list = PROJECT_MODULE_MODULE_LIST.lower().replace(
            ',', ';')
        cmd = [
            cmake,
            '-DMODULE_NAME_PASCALCASE=%s' % project_name, '-DPROJECT_MODULE=1',
            '-DPROJECT_MODULE_PROJECT_PATH=%s' % project_path,
            '-DPROJECT_MODULE_MODULE_LIST=%s' % input_module_list, '-P',
            'module_creator.cmake'
        ]
        if call(cmd, cwd=cmake_template_dir) != 0:
            print("Project module creation failed")
            sys.exit(ERROR_CMAKE_MODULE_CREATION_FAILURE)

        # Update project.json
        add_module_to_project_json(project_name,
                                   'mod_%s' % project_name.lower())

    # Solution generation
    if generate_solution:
        print("Project created")
        print("Generating solution")

        # Determine our Python interpreter location
        python = get_python_path()

        cmd = [
            python, './tools/platform/regenerate_project_by_name.py',
            project_name
        ]
        if not show_solution and not sys.platform.startswith('linux'):
            cmd.append('--no-show')
        if call(cmd, cwd=nap_root) != 0:
            print("Solution generation failed")
            return ERROR_SOLUTION_GENERATION_FAILURE
    else:
        print("Project created in %s" % os.path.relpath(project_path))

    return 0