Example #1
0
def cmd_projgen(args, open_cmake=False):
    if not os.path.isfile(args.project_file):
        error_project_not_found(args.project_file)

    project = cryproject.load(args.project_file)
    if project is None:
        error_project_json_decode(args.project_file)

    project_path = os.path.abspath(os.path.dirname(args.project_file))
    engine_path = get_engine_path()

    cmakelists_dir = cryproject.cmakelists_dir(project)

    if not cmakelists_dir:
        error_code_folder_not_specified()

    code_directory = os.path.join(project_path, cmakelists_dir)

    # Generate solutions
    crysolutiongenerator.generate_solution(args.project_file, code_directory, engine_path)

    # Skip on Crytek build agents
    if args.buildmachine:
        return

    cmakelists_path = os.path.join(os.path.join(project_path, cmakelists_dir), 'CMakeLists.txt')

    # Generate the Solution
    if code_directory is not None and os.path.isfile(cmakelists_path):
        generate_project_solution(project_path, code_directory, open_cmake)
Example #2
0
def cmd_build(args):
    if not os.path.isfile (args.project_file):
        error_project_not_found (args.project_file)

    project= cryproject.load (args.project_file)
    if project is None:
        error_project_json_decode (args.project_file)

    cmake_path= get_cmake_path()
    if cmake_path is None:
        error_cmake_not_found()

    #--- cmake
    if cryproject.cmakelists_dir(project) is not None:
        project_path= os.path.dirname (os.path.abspath (args.project_file))
        solution_dir= get_solution_dir (args)

        subcmd= (
            cmake_path,
            '--build', solution_dir,
            '--config', args.config
        )

        print_subprocess (subcmd)
        errcode= subprocess.call(subcmd, cwd= project_path)
        if errcode != 0:
            sys.exit (errcode)
Example #3
0
def cmd_projgen(args):
    if not os.path.isfile(args.project_file):
        error_project_not_found(args.project_file)

    project = cryproject.load(args.project_file)
    if project is None:
        error_project_json_decode(args.project_file)

    cmake_path = get_cmake_path()
    if cmake_path is None:
        error_cmake_not_found()

    #---

    csharp = project.get("csharp")
    if csharp:
        csharp_copylinks(args)
        csharp_userfile(args, csharp)

    #---

    project_path = os.path.abspath(os.path.dirname(args.project_file))
    solution_path = os.path.join(project_path, get_solution_dir(args))
    engine_path = get_engine_path()

    subcmd = (
        cmake_path, '-Wno-dev', {
            'win_x86': '-AWin32',
            'win_x64': '-Ax64'
        }[args.platform],
        '-DPROJECT_FILE:FILEPATH=%s' % os.path.abspath(args.project_file),
        '-DCryEngine_DIR:PATH=%s' % engine_path,
        '-DCMAKE_PREFIX_PATH:PATH=%s' %
        os.path.join(engine_path, 'Tools', 'CMake', 'modules'),
        '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG:PATH=%s' %
        os.path.join(project_path,
                     cryproject.shared_dir(project, args.platform, 'Debug')),
        '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE:PATH=%s' %
        os.path.join(project_path,
                     cryproject.shared_dir(project, args.platform, 'Release')),
        '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL:PATH=%s' % os.path.join(
            project_path,
            cryproject.shared_dir(project, args.platform, 'MinSizeRel')),
        '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO:PATH=%s' %
        os.path.join(
            project_path,
            cryproject.shared_dir(project, args.platform, 'RelWithDebInfo')),
        os.path.join(project_path, cryproject.cmakelists_dir(project)))

    if not os.path.isdir(solution_path):
        os.makedirs(solution_path)

    os.chdir(solution_path)
    print_subprocess(subcmd)
    sys.exit(subprocess.call(subcmd))
Example #4
0
def copy_code(project, project_path, export_path, silent):
    """
    Copies the code and solutions to the backup folder.
    """
    code_dir = cryproject.cmakelists_dir(project)
    copy_directory(project_path, export_path, code_dir, silent=silent)

    # Also try copying the solutions folder if available
    solutions_dir = "solutions"
    copy_directory(project_path,
                   export_path,
                   solutions_dir,
                   warn_on_fail=False,
                   silent=silent)
Example #5
0
def cmd_devenv(args):
    if not os.path.isfile(args.project_file):
        error_project_not_found(args.project_file)

    project = cryproject.load(args.project_file)
    if project is None:
        error_project_json_decode(args.project_file)

    #---
    csharp = project.get("csharp", {})
    mono_solution = csharp.get('monodev', {}).get('solution')
    if mono_solution:
        # launch monodev
        dirname = os.path.dirname(args.project_file)
        mono_solution = os.path.abspath(os.path.join(dirname, mono_solution))
        if not os.path.isfile(mono_solution):
            error_mono_not_found(mono_solution)

        engine_path = get_engine_path()
        tool_path = os.path.join(engine_path, 'Tools', 'MonoDevelop', 'bin',
                                 'MonoDevelop.exe')
        if not os.path.isfile(tool_path):
            error_engine_tool_not_found(tool_path)

        subcmd = (tool_path, mono_solution)
        print_subprocess(subcmd)
        subprocess.Popen(subcmd,
                         env=dict(os.environ, CRYENGINEROOT=engine_path))
    else:
        # launch msdev
        cmakelists_dir = cryproject.cmakelists_dir(project)
        if cmakelists_dir is not None:
            project_path = os.path.abspath(os.path.dirname(args.project_file))
            solution_path = os.path.join(project_path, get_solution_dir(args))
            solutions = glob.glob(os.path.join(solution_path, '*.sln'))
            if not solutions:
                error_solution_not_found(solution_path)

            solutions.sort()
            subcmd = ('cmd', '/C', 'start', '', solutions[0])
            print_subprocess(subcmd)

            engine_path = get_engine_path()
            subprocess.Popen(subcmd,
                             env=dict(os.environ, CRYENGINEROOT=engine_path))
        else:
            error_mono_not_set(args.project_file)
Example #6
0
def cmd_build(args):
	if not os.path.isfile (args.project_file):
		error_project_not_found (args.project_file)
	
	project= cryproject.load (args.project_file)
	if project is None:
		error_project_json_decode (args.project_file)
	
	cmake_path= get_cmake_path()
	if cmake_path is None:
		error_cmake_not_found()
	
	#--- mono

	csharp= project.get ("csharp", {})
	mono_solution= csharp.get ("monodev", {}).get ("solution")
	if mono_solution is not None:
		engine_path= get_engine_path()
		tool_path= os.path.join (engine_path, 'Tools', 'MonoDevelop', 'bin', 'mdtool.exe')
		if not os.path.isfile (tool_path):
			error_engine_tool_not_found (tool_path)

		subcmd= (
			tool_path,
			'build', os.path.join (os.path.dirname (args.project_file), mono_solution)
		)
	
		print_subprocess (subcmd)
		errcode= subprocess.call(subcmd)
		if errcode != 0:
			sys.exit (errcode)		

	#--- cmake
	if cryproject.cmakelists_dir(project) is not None:
		project_path= os.path.dirname (os.path.abspath (args.project_file))
		solution_dir= get_solution_dir (args)
		
		subcmd= (
			cmake_path,
			'--build', solution_dir,
			'--config', args.config
		)
		
		print_subprocess (subcmd)
		errcode= subprocess.call(subcmd, cwd= project_path)
		if errcode != 0:
			sys.exit (errcode)
Example #7
0
def cmd_cmake_gui(args):
    if not os.path.isfile(args.project_file):
        error_project_not_found(args.project_file)

    project = cryproject.load(args.project_file)
    if project is None:
        error_project_json_decode(args.project_file)
    dirname = os.path.dirname(os.path.abspath(args.project_file))

    #--- cpp
    cmakelists_dir = cryproject.cmakelists_dir(project)
    if cmakelists_dir is not None:
        project_path = os.path.abspath(os.path.dirname(args.project_file))
        source_path = os.path.join(project_path, cmakelists_dir)
        solution_dir = get_project_solution_dir(project_path)
        if solution_dir == None:
            error_solution_not_found(project_path)
            return
        solution_path = os.path.join(project_path, solution_dir)
        open_cmake_gui(source_path, solution_path)
Example #8
0
def cmd_projgen(args):
    if not os.path.isfile (args.project_file):
        error_project_not_found (args.project_file)

    project= cryproject.load (args.project_file)
    if project is None:
        error_project_json_decode (args.project_file)

    project_path= os.path.abspath (os.path.dirname (args.project_file))
    engine_path= get_engine_path()

    cmakelists_dir= cryproject.cmakelists_dir(project)
    code_directory = os.path.join (project_path, cmakelists_dir)

    # Generate solutions
    crysolutiongenerator.generate_solution(args.project_file, code_directory, engine_path)

    cmakelists_path = os.path.join(os.path.join (project_path, cmakelists_dir), 'CMakeLists.txt')

    # Generate the Solution, skip on Crytek build agents
    if cmakelists_dir is not None and os.path.exists(cmakelists_path) and not args.buildmachine:
        cmake_path= get_cmake_path()
        if cmake_path is None:
            error_cmake_not_found()

        solution_path= os.path.join (project_path, get_solution_dir (args))

        subcmd= (
            cmake_path,
            {'win_x86': '-AWin32', 'win_x64': '-Ax64'}[args.platform],
            '-DCMAKE_TOOLCHAIN_FILE=%s' % os.path.join (engine_path, 'Tools', 'CMake', 'toolchain', 'windows', 'WindowsPC-MSVC.cmake'),
            os.path.join (project_path, cmakelists_dir)
        )

        if not os.path.isdir (solution_path):
            os.makedirs (solution_path)

        print_subprocess (subcmd)
        errcode= subprocess.call(subcmd, cwd= solution_path)
        if errcode != 0:
            sys.exit (errcode)
Example #9
0
def cmd_cmake_gui(args):
    if not os.path.isfile (args.project_file):
        error_project_not_found (args.project_file)

    project= cryproject.load (args.project_file)
    if project is None:
        error_project_json_decode (args.project_file)
    dirname= os.path.dirname (os.path.abspath (args.project_file))

    #--- cpp
    cmakelists_dir= cryproject.cmakelists_dir(project)
    if cmakelists_dir is not None:
        cmake_path= get_cmake_path()
        if cmake_path is None:
            error_cmake_not_found()

        project_path= os.path.abspath (os.path.dirname (args.project_file))
        solution_path= os.path.join (project_path, get_solution_dir (args))

        cmake_gui_path = cmake_path.replace('cmake.exe','cmake-gui.exe')

        subcmd= (cmake_gui_path)
        pid = subprocess.Popen([cmake_gui_path],cwd= solution_path)
Example #10
0
def cmd_projgen(args):
    if not os.path.isfile(args.project_file):
        error_project_not_found(args.project_file)

    project = cryproject.load(args.project_file)
    if project is None:
        error_project_json_decode(args.project_file)

    project_path = os.path.abspath(os.path.dirname(args.project_file))
    engine_path = get_engine_path()

    cmakelists_dir = cryproject.cmakelists_dir(project)
    code_directory = os.path.join(project_path, cmakelists_dir)

    # Generate solutions
    crysolutiongenerator.generate_solution(args.project_file, code_directory,
                                           engine_path)

    cmakelists_path = os.path.join(os.path.join(project_path, cmakelists_dir),
                                   'CMakeLists.txt')

    # Generate the Solution, skip on Crytek build agents
    if cmakelists_dir is not None and os.path.exists(
            cmakelists_path) and not args.buildmachine:

        cmake_dir = get_cmake_dir()
        cmake_path = get_cmake_exe_path()

        if cmake_path is None:
            error_cmake_not_found()

        # Run the GUI to select a config for CMake.
        config = cryrun_gui.select_config()

        #No config means the user canceled while selecting the config, so we can safely exit.
        if not config:
            sys.exit(0)

        # By default the CMake output is hidden. This is printed to make sure the user knows it's not stuck.
        print("Generating solution...")

        toolchain = config['cmake_toolchain']
        solution_path = os.path.join(project_path, config['cmake_builddir'])
        generator = config['cmake_generator']

        if not os.path.isdir(solution_path):
            os.makedirs(solution_path)

        if toolchain:
            toolchain = toolchain.replace('\\', '/')
            toolchain = os.path.join(cmake_dir, toolchain)

        prepare_cmake_cache(solution_path, generator)

        cmake_command = ['"{}"'.format(cmake_path)]
        cmake_command.append('-Wno-dev')
        if toolchain:
            cmake_command.append(
                '-DCMAKE_TOOLCHAIN_FILE="{}"'.format(toolchain))
        cmake_command.append('"{}"'.format(cmakelists_dir))
        cmake_command.append('-B"{}"'.format(solution_path))
        cmake_command.append('-G"{}"'.format(generator))

        # Filter empty commands, and convert the list to a string.
        cmake_command = list(filter(bool, cmake_command))
        command_str = ("".join("{} ".format(e) for e in cmake_command)).strip()

        try:
            subprocess.check_output(command_str, universal_newlines=True)
        except subprocess.CalledProcessError as e:
            if not e.returncode == 0:
                print(
                    "Encountered and error while running command '{}'!".format(
                        command_str))
                print(e.output)
                print("Generating solution has failed!")
                print("Press Enter to exit")
                input()
Example #11
0
def cmd_projgen(args):
    if not os.path.isfile(args.project_file):
        error_project_not_found(args.project_file)

    project = cryproject.load(args.project_file)
    if project is None:
        error_project_json_decode(args.project_file)

    #--- remove old files

    dirname = os.path.dirname(os.path.abspath(args.project_file))
    prevcwd = os.getcwd()
    os.chdir(dirname)

    if not os.path.isdir('Backup'):
        os.mkdir('Backup')
    (fd, zfilename) = tempfile.mkstemp(
        '.zip',
        datetime.date.today().strftime('projgen_%y%m%d_'),
        os.path.join(dirname, 'Backup'))
    file = os.fdopen(fd, 'wb')
    backup = zipfile.ZipFile(file, 'w', zipfile.ZIP_DEFLATED)

    #Solution
    for (dirpath, dirnames, filenames) in os.walk(get_solution_dir(args)):
        for filename in filenames:
            backup.write(os.path.join(dirpath, filename))

    #CryManaged
    for (dirpath, dirnames,
         filenames) in os.walk(os.path.join('Code', 'CryManaged', 'CESharp')):
        for filename in filenames:
            backup.write(os.path.join(dirpath, filename))

    #bin
    for (dirpath, dirnames, filenames) in os.walk('bin'):
        for filename in filter(
                lambda a: os.path.splitext(a)[1] in ('.exe', '.dll'),
                filenames):
            backup.write(os.path.join(dirpath, filename))

    backup.close()
    file.close()

    backup_deletefiles(zfilename)
    os.chdir(prevcwd)

    #--- csharp

    csharp = project.get("csharp")
    if csharp:
        csharp_copylinks(args, update=False)
        csharp_userfile(args, csharp)

    #--- cpp
    cmakelists_dir = cryproject.cmakelists_dir(project)
    if cmakelists_dir is not None:
        cmake_path = get_cmake_path()
        if cmake_path is None:
            error_cmake_not_found()

        project_path = os.path.abspath(os.path.dirname(args.project_file))
        solution_path = os.path.join(project_path, get_solution_dir(args))
        engine_path = get_engine_path()

        subcmd = (
            cmake_path, '-Wno-dev', {
                'win_x86': '-AWin32',
                'win_x64': '-Ax64'
            }[args.platform],
            '-DPROJECT_FILE:FILEPATH=%s' % os.path.abspath(args.project_file),
            '-DCryEngine_DIR:PATH=%s' % engine_path,
            '-DCMAKE_PREFIX_PATH:PATH=%s' %
            os.path.join(engine_path, 'Tools', 'CMake', 'modules'),
            '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG:PATH=%s' % os.path.join(
                project_path,
                cryproject.shared_dir(project, args.platform, 'Debug')),
            '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE:PATH=%s' % os.path.join(
                project_path,
                cryproject.shared_dir(project, args.platform, 'Release')),
            '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL:PATH=%s' %
            os.path.join(
                project_path,
                cryproject.shared_dir(project, args.platform, 'MinSizeRel')),
            '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO:PATH=%s' %
            os.path.join(
                project_path,
                cryproject.shared_dir(project, args.platform,
                                      'RelWithDebInfo')),
            os.path.join(project_path, cmakelists_dir))

        if not os.path.isdir(solution_path):
            os.makedirs(solution_path)

        print_subprocess(subcmd)
        errcode = subprocess.call(subcmd, cwd=solution_path)
        if errcode != 0:
            sys.exit(errcode)

    cmd_build(args)