def gen_qtcreator(all_files, defines, includedirs, prj_name, buildfox_name, cmd_env, ninja_gen_mode): gen_make(buildfox_name, cmd_env, ninja_gen_mode) all_files = ["Makefile", buildfox_name] + cxx_findfiles(all_files) includedirs = ["."] + includedirs with open("%s.creator" % prj_name, "w") as f: f.write("[General]\n") with open("%s.config" % prj_name, "w") as f: f.write("%s\n" % "\n".join(["#define %s" % define for define in defines])) with open("%s.includes" % prj_name, "w") as f: f.write("%s\n" % "\n".join(includedirs)) with open("%s.files" % prj_name, "w") as f: f.write("%s\n" % "\n".join(all_files))
def gen_xcode(all_files, includedirs, prj_name, buildfox_name, cmd_env, ninja_gen_mode): gen_make(buildfox_name, cmd_env, ninja_gen_mode) all_files = cxx_findfiles(all_files) includedirs = [".", "build/bin_debug"] + includedirs prj_location = prj_name + ".xcodeproj" if not os.path.exists(prj_location): os.makedirs(prj_location) ref = json.loads(xcode_reference_prj) import mod_pbxproj # TODO would be nice to remove external dependency before release, because mod_pbxproj doesn't work with python3 prj = mod_pbxproj.XcodeProject(ref, prj_location + "/project.pbxproj") target = prj.get_build_phases('PBXLegacyTarget') target[0]["buildWorkingDirectory"] = os.path.abspath(prj_location + "/..") for file in all_files: prj.add_file_if_doesnt_exist(os.path.relpath(file, prj_location + "/..")) prj.save()
def gen_xcode(all_files, includedirs, prj_name, buildfox_name, cmd_env, ninja_gen_mode): gen_make(buildfox_name, cmd_env, ninja_gen_mode) all_files = cxx_findfiles(all_files) includedirs = [".", "build/bin_debug"] + includedirs prj_location = prj_name + ".xcodeproj" if not os.path.exists(prj_location): os.makedirs(prj_location) ref = json.loads(xcode_reference_prj) import mod_pbxproj # TODO would be nice to remove external dependency before release, because mod_pbxproj doesn't work with python3 prj = mod_pbxproj.XcodeProject(ref, prj_location + "/project.pbxproj") target = prj.get_build_phases('PBXLegacyTarget') target[0]["buildWorkingDirectory"] = os.path.abspath(prj_location + "/..") for file in all_files: prj.add_file_if_doesnt_exist( os.path.relpath(file, prj_location + "/..")) prj.save()
def main(*argv, **kwargs): # find out if user wants help about flags or something and slice all arguments after help arg_help = [sys.argv.index(v) for v in ["-h", "--help"] if v in sys.argv] arg_help = sys.argv[min(arg_help) + 1:] if arg_help else None if arg_help: lines = fox_core.split("\n") for arg in arg_help: # find stuff results = [ index for index in range(0, len(lines)) if arg in lines[index] ] # look behind/ahead results = [ set([ item for item in range(index - 1, index + 2) if item >= 0 and item < len(lines) ]) for index in results ] # merge context groups # so if we have [(0,1,2), (1,2,3)] we will have [(0,1,2,3)] merged_results = [] while results: head = results[0] tail = results[1:] last_len = -1 while len(head) > last_len: last_len = len(head) new_tail = [] for rest in tail: if head.intersection(rest): head |= rest else: new_tail.append(rest) tail = new_tail merged_results.append(head) results = tail results = merged_results # merge strings results = "\n...\n".join([ "\n".join([lines[item] for item in sorted(group)]) for group in results ]) # print results if results: print("results for %s:" % arg) print("...") print(results) print("...") else: print("no results for %s" % arg) exit(0) # parse arguments normally title = "buildfox ninja generator %s" % VERSION argsparser = argparse.ArgumentParser(description=title, add_help=False) argsparser.add_argument("-i", "--in", help="input file", default="build.fox") argsparser.add_argument("-o", "--out", help="output file", default="build.ninja") argsparser.add_argument("-w", "--workdir", help="working directory") argsparser.add_argument("variables", metavar="name=value", type=str, nargs="*", help="variables with values to setup", default=[]) #argsparser.add_argument("-v", "--verbose", action = "store_true", help = "verbose output") # TODO argsparser.add_argument( "--ide", help= "generate ide solution (vs, vs2012, vs2013, vs2015, xcode, make, qtcreator, cmake)", default=None, dest="ide") argsparser.add_argument("--ide-prj", help="ide project prefix", default="build") argsparser.add_argument( "--ide-env", help= "run provided command to set required environment before calling ninja from the ide, " + "use set NAME=VALUE form if you need to modify environment so it will work with all IDE's", default=None) argsparser.add_argument("--no-core", action="store_false", help="disable parsing fox core definitions", default=True, dest="core") argsparser.add_argument("--no-env", action="store_false", help="disable environment discovery", default=True, dest="env") argsparser.add_argument( "-n", "--ninja-ide-gen", action="store_true", help="enables ninja ide generator mode (equal to --no-core --no-env)", default=False, dest="ninja_ide_gen") # It won't be checked for real. Ninja will be run only if no arguments were passed. argsparser.add_argument("--just-generate", action="store_true", help="skips automatic ninja run", default=False, dest="just_generate") argsparser.add_argument("--selftest", action="store_true", help="run self test", default=False, dest="selftest") argsparser.add_argument("-v", "--ver", "--version", action="version", version=title) argsparser.add_argument( "-h", "--help", metavar="REQUEST", type=str, nargs="*", default=argparse.SUPPRESS, help="look for request or show this help message and exit") args = vars(argsparser.parse_args()) if "help" in args: argsparser.print_help() exit(0) if args.get("ninja_ide_gen"): args["core"] = False args["env"] = False args["in"] = "build.ninja" if args.get( "in") == "build.fox" else args.get("in") args["out"] = "" if args.get("workdir"): os.chdir(args.get("workdir")) engine = Engine() if args.get("env"): env = discover() for name in sorted(env.keys()): engine.on_assign((name, env.get(name), "=")) for var in args.get("variables"): parts = var.split("=") if len(parts) == 2: name, value = parts[0], parts[1] engine.on_assign((name, value, "=")) else: raise SyntaxError( "unknown argument '%s'. you should use name=value syntax to setup a variable" % var) if args.get("core"): engine.load_core(fox_core) if args.get("selftest"): fox_filename, ninja_filename, app_filename = selftest_setup() engine.load(fox_filename) engine.save(ninja_filename) result = not subprocess.call(["ninja", "-f", ninja_filename]) if result: result = not subprocess.call(["./" + app_filename]) if result: print("Selftest - ok") selftest_wipe() else: print("Selftest - failed") sys.exit(1) else: engine.load(args.get("in")) if len(args.get("out")): engine.save(args.get("out")) ide = args.get("ide") if ide in ["vs", "vs2012", "vs2013", "vs2015"]: if ide == "vs": ide = "vs" + engine.variables.get("toolset_msc_ver", "") gen_vs(engine.context.all_files, cxx_defines(engine.variables.get("defines", "")), cxx_includedirs(engine.variables.get("includedirs", "")), args.get("ide_prj"), ide, args.get("ide_env")) elif ide in ["xcode"]: gen_xcode(engine.context.all_files, cxx_includedirs(engine.variables.get("includedirs", "")), args.get("ide_prj"), args.get("in"), args.get("ide_env"), args.get("ninja_ide_gen")) elif ide in ["make"]: gen_make(args.get("in"), args.get("ide_env"), args.get("ninja_ide_gen")) elif ide in ["qtcreator"]: gen_qtcreator( engine.context.all_files, cxx_defines(engine.variables.get("defines", "")), cxx_includedirs(engine.variables.get("includedirs", "")), args.get("ide_prj"), args.get("in"), args.get("ide_env"), args.get("ninja_ide_gen")) elif ide in ["cmake"]: gen_cmake(engine.context.all_files, cxx_includedirs(engine.variables.get("includedirs", "")), args.get("ide_prj"), args.get("in"), args.get("ide_env")) elif ide is not None: raise ValueError( "unknown ide '%s', available ide's : vs, vs2012, vs2013, vs2015, xcode, make, qtcreator, cmake" % ide) if len(sys.argv) == 1: sys.exit( subprocess.call("ninja" + (" -f " + args["out"] if len(args["out"]) else "")))