How to use add_text method in SeleniumBase

Best Python code snippet using SeleniumBase

fbuild_utils.py

Source:fbuild_utils.py Github

copy

Full Screen

...88 bff_path = os.path.join(self.intermediate_path, "fbuild.bff")89 # generate bff file90 self.bff_file = open(bff_path, "w")91 # description for bff file92 self.add_text(93 ";*************************************************************************\n"94 )95 self.add_text(96 ";* Autogenerated bff - see FASTBuild.cs for how this file was generated. *\n"97 )98 self.add_text(99 ";*************************************************************************\n\n"100 )101 # set global variables102 self.add_text(f".OutputPath = '{self.output_path}'\n")103 self.add_text(f".IntermediatePath = '{self.intermediate_path}'\n\n")104 # cache sdk_root105 self.cache_sdk_root()106 # setup by environment variables107 self.write_env_setup()108 return109 def add_sym_link_to_output(self, src_path: str, dst_folder_name: str):110 """add symbolic link which is useful e.g. adding Data folder link to Output Folder which contains .exe file"""111 if self.build_conf != None:112 dst_dir = self.get_output_path(self.build_conf)113 dst_path = os.path.join(dst_dir, dst_folder_name)114 # re-create sym link115 if not os.path.isdir(dst_path):116 subprocess.check_call(117 f'mklink /J "{dst_path}" "{src_path}"', shell=True118 )119 def add_module(self, module: FBModule):120 self.modules[module.name] = module121 return122 def add_module_info(self, info: ModuleInfo):123 self.module_infos[info.name] = info124 return125 def collect_modules(self):126 for root, dirs, files in os.walk(".\\LSGD"):127 for file in files:128 if "Module.py" in file:129 # get module name130 module_name = file.split(".")[0]131 # get module path132 module_path = os.path.join(root, file)133 # add module134 self.add_module_info(ModuleInfo(module_name, module_path))135 return136 def import_modules(self):137 for name, info in self.module_infos.items():138 info.import_as_py_module()139 return140 def cache_sdk_root(self):141 sdk_root_dir_ref = [142 "",143 ]144 try_read_registry_key(145 "Microsoft\\Windows Kits\\Installed Roots", "KitsRoot10", sdk_root_dir_ref146 )147 if sdk_root_dir_ref[0] == "":148 try_read_registry_key(149 "Microsoft\\Microsoft SDKs\\Windows\\v10.0",150 "InstallationFolder",151 sdk_root_dir_ref,152 )153 # cache sdk_root_dir154 self.sdk_root_dir = sdk_root_dir_ref[0]155 return156 def get_base_include_paths(self, tool_chain_dir: str) -> List[str]:157 # include tool_chain_dir158 base_include_paths: List[str] = [159 os.path.join(tool_chain_dir, "include"),160 ]161 # cache sdk_version162 self.sdk_version = None163 # enumerate all windows sdks164 sdk_include_dir = os.path.join(self.sdk_root_dir, "include")165 version_dirs = []166 for version_dir in os.listdir(sdk_include_dir):167 version_path = os.path.join(sdk_include_dir, version_dir)168 sdk_version = version_dir169 if self.sdk_version != None and self.sdk_version > sdk_version:170 continue171 # cache sdk_version172 self.sdk_version = sdk_version173 # reset the directories174 version_dirs.clear()175 shared_dir = os.path.join(version_path, "shared")176 um_dir = os.path.join(version_path, "um")177 ucrt_dir = os.path.join(version_path, "ucrt")178 if os.path.exists(shared_dir):179 version_dirs.append(shared_dir)180 if os.path.exists(um_dir):181 version_dirs.append(um_dir)182 if os.path.exists(ucrt_dir):183 version_dirs.append(ucrt_dir)184 for version_dir in version_dirs:185 base_include_paths.append(version_dir)186 # add LSGD187 lsgd_path = os.path.abspath(os.path.join(".", "LSGD"))188 base_include_paths.append(lsgd_path)189 return base_include_paths190 def setup_third_libraries_bin_folder(self, thrid_library_path):191 """copy third libraries' binary folder to Output folder"""192 # get src path193 src_path = os.path.join(thrid_library_path, "src")194 # get dest path195 dst_path = self.get_output_path(self.build_conf)196 # get configuration name197 conf_name = "Debug"198 if self.build_conf == BuildConf.RELEASE or self.build_conf == BuildConf.PROFILE:199 conf_name = "Release"200 for dir in self.third_library_paths:201 bin_path = os.path.join(dir, "bin")202 # add bin path203 if not os.path.isdir(bin_path):204 continue205 # get the bin path206 bin_path = os.path.join(bin_path, conf_name)207 if os.path.isdir(bin_path):208 for root, _, files in os.walk(bin_path):209 for file in files:210 ext = os.path.splitext(file)[1]211 if ext == ".dll" or ext == ".pdb":212 # get src_file_path213 src_file_path = os.path.join(root, file)214 src_file_path = os.path.normpath(src_file_path)215 # get dst_file_path216 dst_file_path = os.path.join(dst_path, file)217 dst_file_path = os.path.normpath(dst_file_path)218 # copy file219 shutil.copy2(src_file_path, dst_file_path)220 return221 def setup_third_libraries(self, third_library_path: str):222 # get src path223 src_path = os.path.join(third_library_path, "src")224 # list third libraries225 self.third_library_paths = []226 for dir in os.listdir(src_path):227 self.third_library_paths.append(os.path.join(src_path, dir))228 # extract include/lib paths229 self.third_library_include_paths: List[str] = []230 self.third_library_lib_paths: List[str] = []231 # extract .lib names232 self.debug_library_names = []233 self.release_library_names = []234 # search any deps.json235 deps_file_path = os.path.join(src_path, "deps.json")236 if os.path.exists(deps_file_path):237 deps = read_json_data(deps_file_path)238 deps_paths = deps.get("paths", None)239 if not deps_paths is None:240 for deps_path in deps_paths:241 self.third_library_lib_paths.append(deps_path)242 deps_libs = deps.get("libs", None)243 if not deps_libs is None:244 for deps_lib in deps_libs:245 self.debug_library_names.append(deps_lib)246 self.release_library_names.append(deps_lib)247 for dir in self.third_library_paths:248 include_path = os.path.join(dir, "include")249 library_path = os.path.join(dir, "lib")250 # add include path251 if os.path.isdir(include_path):252 self.third_library_include_paths.append(include_path)253 # Debug library254 debug_library_path = os.path.join(library_path, "Debug")255 if os.path.isdir(debug_library_path):256 self.third_library_lib_paths.append(debug_library_path)257 for root, _, files in os.walk(debug_library_path):258 for file in files:259 ext = os.path.splitext(file)[1]260 if ext == ".lib":261 self.debug_library_names.append(file)262 # Release library263 release_library_path = os.path.join(library_path, "Release")264 if os.path.isdir(release_library_path):265 self.third_library_lib_paths.append(release_library_path)266 for root, _, files in os.walk(release_library_path):267 for file in files:268 ext = os.path.splitext(file)[1]269 if ext == ".lib":270 self.release_library_names.append(file)271 return272 def write_env_setup(self) -> bool:273 """274 #import275 """276 if "CommonProgramFiles" in self.env_vars:277 self.add_text("#import CommonProgramFiles\n")278 if "DXSDK_DIR" in self.env_vars:279 self.add_text("#import DXSDK_DIR\n")280 """281 Compiler 282 """283 # get the vs version284 vs_version = get_visual_studio_version()285 if vs_version == None:286 Logger.instance().info(f"[ERROR] visual studio is NOT valid")287 return False288 # get the vs install path289 vs_default_path = get_visual_studio_path(vs_version)290 vs_install_path = os.path.join(vs_default_path, "VC", "Tools", "MSVC")291 if not os.path.isdir(vs_install_path):292 Logger.instance().info(f"[ERROR] visual studio is NOT valid")293 return False294 # get valid tool chain295 tool_chain_dirs = []296 for dir in os.listdir(vs_install_path):297 compiler_exe = os.path.join(298 vs_install_path, dir, "bin", "Hostx64", "x64", "cl.exe"299 )300 if os.path.exists(compiler_exe):301 tool_chain_dirs.append(dir)302 if len(tool_chain_dirs) == 0:303 Logger.instance().info(f"[ERROR] no appropriate tool chain dir")304 return False305 # get the tool chain directory306 vs_version = tool_chain_dirs[0]307 tool_chain_dir = os.path.join(vs_install_path, vs_version)308 tool_chain_dir_bin = os.path.join(tool_chain_dir, "bin", "Hostx64", "x64")309 # compiler310 self.add_text("Compiler('LSGDCompiler')\n{\n")311 self.add_text(f"\t.Root = '{tool_chain_dir_bin}'\n")312 self.add_text(f"\t.Executable = '$Root$/cl.exe'\n")313 # start ExtraFiles314 self.add_text("\t.ExtraFiles =\n\t{\n")315 self.add_text("\t\t'$Root$/c1.dll'\n")316 self.add_text("\t\t'$Root$/c2.dll'\n")317 self.add_text("\t\t'$Root$/c1xx.dll'\n")318 self.add_text("\t\t'$Root$/1033/clui.dll'\n")319 self.add_text("\t\t'$Root$/mspdbsrv.exe'\n")320 self.add_text("\t\t'$Root$/mspdbcore.dll'\n")321 self.add_text("\t\t'$Root$/mspft140.dll'\n")322 self.add_text("\t\t'$Root$/msobj140.dll'\n")323 self.add_text("\t\t'$Root$/mspdb140.dll'\n")324 self.add_text("\t\t'$Root$/msvcp140.dll'\n")325 self.add_text("\t\t'$Root$/tbbmalloc.dll'\n")326 # get redist directory to find additional dll327 vs_redist_path = os.path.join(vs_default_path, "VC", "Redist", "MSVC")328 vs_redist_dirs = []329 for dir in os.listdir(vs_redist_path):330 redist_dir = os.path.join(vs_redist_path, dir)331 vccorlib140_dll = os.path.join(332 redist_dir, "x64", "Microsoft.VC142.CRT", "vccorlib140.dll"333 )334 if os.path.exists(vccorlib140_dll):335 vs_redist_dirs.append(redist_dir)336 if len(vs_redist_dirs) == 0:337 Logger.instance().info(f"[ERROR] no appropriate vs redist dir")338 return False339 vs_redist_dir = vs_redist_dirs[0]340 vs_redist_dir = os.path.join(vs_redist_dir, "x64", "Microsoft.VC142.CRT")341 # vcruntime140.dll342 vcruntime140_path = os.path.join(vs_redist_dir, "vcruntime140.dll")343 self.add_text(f"\t\t'{vcruntime140_path}'\n")344 # vccorlib140.dll345 vccorlib140_path = os.path.join(vs_redist_dir, "vccorlib140.dll")346 self.add_text(f"\t\t'{vccorlib140_path}'\n")347 # end ExtraFiles348 self.add_text("\t}\n")349 # CompilerFamily350 self.add_text("\t.CompilerFamily = 'msvc'\n")351 self.add_text("}\n")352 """353 Settings354 """355 self.add_text("Settings\n{\n")356 self.add_text("\t.Environment =\n\t{\n")357 # add PATH for vs settings358 IDE_path = os.path.join(vs_default_path, "VC", "Common7", "IDE")359 self.add_text(f'\t\t"PATH={IDE_path};{tool_chain_dir}",\n')360 # add TMP361 TMP_path = self.env_vars.get("TMP", None)362 if TMP_path != None:363 self.add_text(f'\t\t"TMP={TMP_path}"\n')364 # add SystemRoot365 system_root_path = self.env_vars.get("SystemRoot", None)366 if system_root_path != None:367 self.add_text(f'\t\t"SystemRoot={system_root_path}"\n')368 self.add_text("\t}\n")369 # use fbuild cache370 if TMP_path != None:371 fbuild_cache_path = os.path.join(TMP_path, ".build.cache")372 if not os.path.isdir(fbuild_cache_path):373 os.mkdir(fbuild_cache_path)374 self.add_text(f'\t.CachePath = "{fbuild_cache_path}"\n')375 self.add_text("}\n")376 """377 MSVC settings378 """379 """ .MSVC16_BaseConfig """380 # visual studio 2019381 self.add_text(".MSVC16_BaseConfig = [\n")382 # .AdditionalWarning383 self.add_text("\t.AdditionalWarnings = ''\n")384 # .CompilerOptions385 self.add_text("\t.CompilerOptions = ''\n")386 self.add_text("\t\t + ' \"%1\" /Z7'\n") #387 self.add_text(388 "\t\t + ' /nologo'\n"389 ) # surpress the display of the copyright banner390 self.add_text("\t\t + ' /c'\n") # compiles without linking391 self.add_text("\t\t + ' /W4'\n") # warning level 4392 # self.add_text("\t\t + ' /Wall'\n") # display all warning393 # self.add_text("\t\t + ' /WX'\n") # treat warning as error394 # self.add_text("\t\t + ' /TP'\n") # compile as C++395 self.add_text(396 "\t\t + ' /EHsc'\n"397 ) # warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc398 self.add_text(399 "\t\t + ' /Zc:inline'\n"400 ) # remove unreferenced COMDATs at compile time (VS2013.2+)401 self.add_text(402 "\t\t + ' /Zc:strictStrings'\n"403 ) # require const only usage of string literals (VS2013+)404 self.add_text("\t\t + .AdditionalWarnings\n") # see above405 self.add_text("\t\t + ' /fp:fast'\n") # specifies floating-point behavior406 self.add_text(407 '\t\t + \' /D"WIN32_LEAN_AND_MEAN" /D"_WIN32" /D"__WINDOWS__"\'\n'408 )409 self.add_text(410 "\t\t + ' /D\"_CRT_SECURE_NO_WARNINGS\"'\n"411 ) # dont warn about unsafe functions412 self.add_text(413 "\t\t + ' /D\"_WINSOCK_DEPRECATED_NO_WARNINGS\"'\n"414 ) # dont warn about deprecated winsock functions415 # .PCHOptions416 self.add_text(417 "\t.PCHOptions = '' + .CompilerOptions + ' /Fp\"%2\" /Fo\"%3\"'\n"418 )419 self.add_text("\t.CompilerOptions + ' /Fo\"%2\"'\n")420 # .LibrarianOptions421 self.add_text("\t.LibrarianOptions = ''\n")422 self.add_text("\t\t + ' /NODEFAULTLIB'\n") # ignores all default libraries423 self.add_text(424 "\t\t + ' /NOLOGO'\n"425 ) # supresses the display of the copyright banner426 self.add_text('\t\t + \' /OUT:"%2" "%1"\'\n')427 # .LinkerOptions428 self.add_text("\t.LinkerOptions = ''\n")429 self.add_text("\t\t + ' /NODEFAULTLIB'\n") # ignores all default libraries430 self.add_text(431 "\t\t + ' /NOLOGO'\n"432 ) # supresses the display of the copyright banner433 self.add_text("\t\t + ' /INCREMENTAL:NO'\n") # turn off incremental linking434 self.add_text('\t\t + \' /OUT:"%2" "%1"\'\n')435 self.add_text("\t\t + ' /DEBUG'\n") # creates debugging information436 self.add_text(437 "\t\t + ' /IGNORE:4001 /IGNORE:4099'\n"438 ) # dont complain about linking libs only439 # .CompilerDebugOptimizations440 self.add_text("\t.CompilerDebugOptimizations = ''\n")441 self.add_text(442 "\t\t + ' /MTd'\n"443 ) # creates a debug multithreaded executable file using LIBCMTD.lib444 self.add_text("\t\t + ' /Od'\n") # disables optimizations445 self.add_text("\t\t + ' /RTC1'\n") # enables run-time error checks446 self.add_text("\t\t + ' /GS'\n") # buffers security check447 self.add_text("\t\t + ' /Oy-'\n") # disable omitting frame pointer (x86 only)448 self.add_text("\t\t + ' /Oi'\n") # generates intrinsic functions449 self.add_text("\t\t + ' /GR-'\n") # disables run-time type information (RTTI)450 self.add_text("\t\t + ' /EHa-'\n") # disables exceptions451 # .CompilerReleaseOptimizations452 self.add_text("\t.CompilerReleaseOptimizations = ''\n")453 self.add_text(454 "\t\t + ' /MT'\n"455 ) # creates a multithreaded executable file using LIBCMT.lib456 self.add_text("\t\t + ' /Ox'\n") # uses maximum optimization457 self.add_text("\t\t + ' /Oy'\n") # omits frame pointer (x86 only)458 self.add_text("\t\t + ' /Oi'\n") # generates intrinsic functions459 self.add_text("\t\t + ' /GS-'\n") # disables buffers security check460 self.add_text("\t\t + ' /GF'\n") # enables string pooling461 self.add_text("\t\t + ' /GL'\n") # enables while program optimization462 self.add_text("\t\t + ' /Gy'\n") # enables function-level linking463 self.add_text(464 "\t\t + ' /Gw'\n"465 ) # enables whole-program global data optimization466 self.add_text("\t\t + ' /GR-'\n") # disables run-time type information (RTTI)467 self.add_text("\t\t + ' /EHa-'\n") # disables exceptions468 # .LibrarianDebugOptimizations469 self.add_text("\t.LibrarianDebugOptimizations = ''\n")470 # .LibrarianReleaseOptimizations471 self.add_text(472 "\t.LibrarianReleaseOptimizations = ' /LTCG'\n"473 ) # specifies link-time code generation474 # .LinkerDebugOptimizations475 self.add_text("\t.LinkerDebugOptimizations = ''\n")476 # .LinkerReleaseOptimizations477 self.add_text(478 "\t.LinkerReleaseOptimizations = ' /LTCG'\n"479 ) # specifies link-time code generation480 self.add_text("\t\t + ' /OPT:REF,ICF'\n")481 # .BaseIncludePaths482 self.add_text("\t.BaseIncludePaths = ' /I\".\"'\n")483 include_paths = self.get_base_include_paths(tool_chain_dir)484 for include_path in include_paths:485 self.add_text(f"\t\t + ' /I\"{include_path}\"'\n")486 # add third library include path487 for third_library_include_path in self.third_library_include_paths:488 self.add_text(f"\t\t + ' /I\"{third_library_include_path}\"'\n")489 # .CompilerOptions490 self.add_text("\t.CompilerOptions + .BaseIncludePaths\n")491 # .PCHOptions492 self.add_text("\t.PCHOptions + .BaseIncludePaths\n")493 # .WindowsLibPath494 sdk_lib_dir = os.path.join(495 self.sdk_root_dir,496 "Lib",497 self.sdk_version, # drived by self.get_base_include_paths()498 )499 self.add_text(f"\t.WindowsLibPath = '{sdk_lib_dir}'\n")500 self.add_text("]\n")501 """ .MSVC16x64_BaseConfig """502 # x64 base config503 self.add_text(".MSVC16x64_BaseConfig = [\n")504 self.add_text("\tUsing(.MSVC16_BaseConfig)\n")505 self.add_text(f"\t.ToolsBasePath = '{tool_chain_dir_bin}'\n")506 self.add_text("\t.PlatformInfo = 'Windows'\n")507 self.add_text("\t.ArchInfo = 'x64'\n")508 self.add_text("\t.CompilerInfo = 'MSVC16'\n")509 self.add_text("\t.Compiler = 'LSGDCompiler'\n")510 self.add_text("\t.Librarian = '$ToolsBasePath$\lib.exe'\n")511 self.add_text("\t.Linker = '$ToolsBasePath$\link.exe'\n")512 self.add_text("\t.CompilerOptions + ' /DWIN64'\n")513 self.add_text("\t.PCHOptions + ' /DWIN64'\n")514 self.add_text("\t.LinkerOptions + ' /MACHINE:X64'\n")515 self.add_text("\t\t + ' /LIBPATH:\"$WindowsLibPath$\\ucrt\\x64\"'\n")516 self.add_text("\t\t + ' /LIBPATH:\"$WindowsLibPath$\\um\\x64\"'\n")517 # add tool_chain_dir_lib518 tool_chain_dir_lib = os.path.join(tool_chain_dir, "lib", "x64")519 self.add_text(f"\t\t + ' /LIBPATH:\"{tool_chain_dir_lib}\"'\n")520 # add third library lib paths521 for third_library_lib_path in self.third_library_lib_paths:522 self.add_text(f"\t\t + ' /LIBPATH:\"{third_library_lib_path}\"'\n")523 self.add_text("]\n")524 """ .MSVC16x64_DebugConfig """525 # x64 debug config526 self.add_text(".MSVC16x64_DebugConfig = [\n")527 self.add_text("\tUsing(.MSVC16x64_BaseConfig)\n")528 self.add_text("\t.Config = 'Debug'\n")529 self.add_text("\t.CompilerOptions + ' /DDEBUG /D_DEBUG /DPROFILING_ENABLED'\n")530 self.add_text("\t\t + .CompilerDebugOptimizations\n")531 self.add_text("\t.PCHOptions + ' /DDEBUG /D_DEBUG /DPROFILING_ENABLED'\n")532 self.add_text("\t\t + .CompilerDebugOptimizations\n")533 self.add_text("\t.LibrarianOptions + .LibrarianDebugOptimizations\n")534 self.add_text("\t.LinkerOptions + .LinkerDebugOptimizations\n")535 self.add_text(536 "\t\t + ' libcmtd.lib libucrtd.lib libvcruntimed.lib kernel32.lib'\n"537 )538 # std library <vector, map, ...>539 self.add_text("\t\t + ' msvcprtd.lib'\n")540 # join third_library's library name541 debug_lib_list = " ".join(self.debug_library_names)542 self.add_text(f"\t\t + ' {debug_lib_list}'\n")543 self.add_text("]\n")544 """ .MSVC16x64_ReleaseConfig """545 # x64 release config546 self.add_text(".MSVC16x64_ReleaseConfig = [\n")547 self.add_text("\tUsing(.MSVC16x64_BaseConfig)\n")548 self.add_text("\t.Config = 'Release'\n")549 self.add_text("\t.CompilerOptions + '/DRELEASE'\n")550 self.add_text("\t.PCHOptions + '/DRELEASE'\n\n")551 self.add_text(552 "\t// setup de-optimization options (FASTBUILD_DEOPTIMIZE_OBJECT)\n"553 )554 self.add_text("\t.DeoptimizeWritableFilesWithToken = true\n")555 self.add_text("\t.CompilerOptionsDeoptimized = '$CompilerOptions$ /Od'\n")556 self.add_text("\t.PCHOptionsDeoptimized = '$PCHOptions$ /Od'\n\n")557 self.add_text("\t.CompilerOptions + .CompilerReleaseOptimizations\n")558 self.add_text("\t.LibrarianOptions + .LibrarianReleaseOptimizations\n")559 self.add_text("\t.LinkerOptions + .LinkerReleaseOptimizations\n")560 self.add_text(561 "\t\t + ' libcmt.lib libucrt.lib libvcruntime.lib kernel32.lib'\n"562 )563 # std library <vector, map, ...>564 self.add_text("\t\t + ' msvcprt.lib'\n")565 # join third_library's library name566 release_lib_list = " ".join(self.release_library_names)567 self.add_text(f"\t\t + ' {release_lib_list}'\n")568 self.add_text("]\n")569 """ .MSVC16x64_ProfileConfig """570 # x64 profile config571 self.add_text(".MSVC16x64_ProfileConfig = [\n")572 self.add_text("\tUsing(.MSVC16x64_ReleaseConfig)\n")573 self.add_text("\t.Config = 'Profile'\n")574 self.add_text("\t.CompilerOptions + ' /DPROFILING_ENABLED'\n")575 self.add_text("\t.PCHOptions + ' /DPROFILING_ENABLED'\n")576 self.add_text("\t.DeoptimizeWritableFilesWithToken = false\n")577 self.add_text("]\n\n")578 """ .Configs_Windows_MSVC16 """579 self.add_text(".Configs_Windows_MSVC16 = {\n")580 self.add_text("\t.MSVC16x64_DebugConfig\n")581 self.add_text("\t,.MSVC16x64_ProfileConfig\n")582 self.add_text("\t,.MSVC16x64_ReleaseConfig\n")583 self.add_text("}\n\n")584 return True585 def add_lib_module_bff(self, module: FBModule):586 self.add_text("{\n")587 self.add_text(f"\t.ProjectName = '{module.name}'\n")588 self.add_text(f"\t.ProjectPath = '{module.dir}'\n")589 self.add_text("\t{\n")590 self.add_text("\t\t.UnityInputPath = {\n")591 # add default src path592 self.add_text(f"\t\t\t'{module.src_path}'\n")593 # add additional src paths594 for src_path in module.additional_src_paths:595 self.add_text(f"\t\t\t'{src_path}',\n")596 self.add_text("\t\t}\n")597 self.add_text("\t\t.UnityInputPattern = {'*.cpp', '*.c'}\n")598 self.add_text(599 "\t\t.UnityOutputPath = '$IntermediatePath$\\Unity\\$ProjectName$\\'\n"600 )601 self.add_text("\t\tUnity('$ProjectName$-Unity'){}\n")602 self.add_text("\t}\n\n")603 self.add_text("\tForEach(.Config in .Configs_Windows_MSVC16) {\n")604 self.add_text("\t\tUsing(.Config)\n")605 self.add_text(606 "\t\t.OutputPath + '\\$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$\\'\n"607 )608 self.add_text(609 "\t\t.IntermediatePath + '\\$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$\\'\n"610 )611 # additonal includes612 if len(module.additional_include_paths) > 0:613 self.add_text("\t\t.CompilerOptions \n")614 for include_path in module.additional_include_paths:615 self.add_text(f"\t\t + ' /I\"{include_path}\"'\n")616 """ Library() """617 self.add_text(618 "\t\tLibrary('$ProjectName$-Lib-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$') {\n"619 )620 # .PreBuildDependencies621 self.add_text("\t\t\t.PreBuildDependencies = {\n")622 for module_name in module.dependent_module_names:623 self.add_text(624 f"\t\t\t\t'{module_name}-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$'\n"625 )626 self.add_text("\t\t\t}\n")627 self.add_text("\t\t\t.CompilerInputUnity = '$ProjectName$-Unity'\n")628 self.add_text(629 "\t\t\t.CompilerOutputPath = '$IntermediatePath$\\$ProjectName$-Build\\'\n"630 )631 self.add_text("\t\t\t.LibrarianOutput = '$OutputPath$\\$ProjectName$.lib'\n")632 self.add_text("\t\t}\n")633 """ Alias() """634 self.add_text(635 "\t\tAlias('$ProjectName$-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$') {\n"636 )637 self.add_text(638 "\t\t\t.Targets = '$ProjectName$-Lib-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$'\n"639 )640 self.add_text("\t\t}\n")641 self.add_text("\t}\n")642 self.add_text("}\n\n")643 return644 def add_exe_module_bff(self, module: FBModule):645 self.add_text("{\n")646 self.add_text(f"\t.ProjectName = '{module.name}'\n")647 self.add_text(f"\t.ProjectPath = '{module.dir}'\n")648 self.add_text("\t{\n")649 self.add_text("\t\t.UnityInputPath = {\n")650 # add default src path651 self.add_text(f"\t\t\t'{module.src_path}'\n")652 # add additional src paths653 for src_path in module.additional_src_paths:654 self.add_text(f"\t\t\t'{src_path}',\n")655 self.add_text("\t\t}\n")656 self.add_text("\t\t.UnityInputPattern = {'*.cpp'}\n")657 self.add_text(658 "\t\t.UnityOutputPath = '$IntermediatePath$\\Unity\\$ProjectName$\\'\n"659 )660 self.add_text("\t\tUnity('$ProjectName$-Unity'){}\n")661 self.add_text("\t}\n\n")662 self.add_text("\tForEach(.Config in .Configs_Windows_MSVC16) {\n")663 self.add_text("\t\tUsing(.Config)\n")664 self.add_text("\t\t.CompilerOptions + ''\n")665 self.add_text("\t\t\t + ' /wd4710' // function not inlined \n")666 # add additional include folder for dependent modules667 for module_name in module.dependent_module_names:668 dependent_module = self.modules[module_name]669 for include_path in dependent_module.additional_include_paths:670 self.add_text(f"\t\t\t + ' /I\"{include_path}\"' \n")671 self.add_text(672 "\t\t.OutputPath + '\\$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$\\'\n"673 )674 self.add_text(675 "\t\t.IntermediatePath + '\\$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$\\'\n"676 )677 """ ObjectList """678 self.add_text(679 "\t\tObjectList('$ProjectName$-Lib-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$') {\n"680 )681 self.add_text("\t\t\t.CompilerInputUnity = '$ProjectName$-Unity'\n")682 self.add_text(683 "\t\t\t.CompilerOutputPath = '$IntermediatePath$\\$ProjectName$-Build\\'\n"684 )685 self.add_text("\t\t}\n")686 """ Executable """687 self.add_text(688 "\t\tExecutable('$ProjectName$-Exe-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$') {\n"689 )690 # .PreBuildDependencies691 self.add_text("\t\t\t.PreBuildDependencies = {\n")692 for module_name in module.dependent_module_names:693 self.add_text(694 f"\t\t\t\t'{module_name}-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$'\n"695 )696 self.add_text("\t\t\t}\n")697 # .Librarian698 self.add_text("\t\t\t.Libraries = {\n")699 self.add_text(700 "\t\t\t\t'$ProjectName$-Lib-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$'\n"701 )702 for module_name in module.dependent_module_names:703 self.add_text(704 f"\t\t\t\t'{module_name}-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$'\n"705 )706 self.add_text("\t\t\t}\n")707 self.add_text("\t\t\t.LinkerOutput = '$OutputPath$\\$ProjectName$.exe'\n")708 self.add_text("\t\t\t.LinkerOptions + ' /SUBSYSTEM:CONSOLE'\n")709 """ override linker options """710 # add .lib path ($OutputPath$)711 self.add_text(f"\t\t\t\t + ' /LIBPATH:\"$OutputPath$\"'\n")712 # add .lib file in $OutputPath$ for all dependent modules713 library_names: List[str] = []714 for module_name in module.dependent_module_names:715 library_names.append(f"{module_name}.lib")716 library_names = " ".join(library_names)717 if len(library_names) > 0:718 self.add_text(f"\t\t\t\t + ' {library_names}'\n")719 self.add_text("\t\t}\n")720 """ Alias """721 self.add_text(722 "\t\tAlias('$ProjectName$-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$') {\n"723 )724 self.add_text(725 "\t\t\t.Targets = '$ProjectName$-Exe-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$'\n"726 )727 self.add_text("\t\t}\n")728 self.add_text("\t}\n")729 self.add_text("}\n\n")730 return731 def finalize_alias(self, build_conf: BuildConf):732 """ForEach All Alias"""733 self.add_text("ForEach(.Config in .Configs_Windows_MSVC16) {\n")734 self.add_text("\tUsing(.Config)\n")735 self.add_text(736 "\tAlias('All-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$') {\n"737 )738 self.add_text("\t\t.Targets = {\n")739 module_contents = []740 for name, module in self.modules.items():741 module_contents.append(742 f"\t\t\t'{name}-$PlatformInfo$-$ArchInfo$-$CompilerInfo$-$Config$'"743 )744 self.add_text(",\n".join(module_contents))745 self.add_text("\n")746 self.add_text("\t\t}\n")747 self.add_text("\t}\n")748 self.add_text("}\n")749 # by default, BuildConf.DEBUG750 build_configuration = "\t\t'All-Windows-x64-MSVC16-Debug'\n"751 if build_conf == BuildConf.PROFILE:752 build_configuration = "\t\t'All-Windows-x64-MSVC16-Profile'\n"753 elif build_conf == BuildConf.RELEASE:754 build_configuration = "\t\t'All-Windows-x64-MSVC16-Release'\n"755 """ All Alias"""756 self.add_text("Alias('All') {\n")757 self.add_text("\t.Targets = {\n")758 self.add_text(build_configuration)759 self.add_text("\t}\n")760 self.add_text("}\n")761 return762 def construct_build_graph(self) -> List[str]:763 # find executable and construct list of module name764 module_names: List[str] = []765 executable_modules: List[str] = []766 for name, module in self.modules.items():767 if module.is_executable == True:768 executable_modules.append(name)769 else:770 module_names.append(name)771 if len(executable_modules) > 1:772 Logger.instance().info(f"[ERROR] more than one executable module!")773 raise RuntimeError()774 # calculate dependency costs775 module_dep_costs: Dict[str, int] = {}776 for module_name in module_names:777 module = self.modules.get(module_name, None)778 # calculate dep costs779 # @todo - need to calculate recursive dep costs780 cost = len(module.dependent_module_names)781 module_dep_costs[module_name] = cost782 # sort by dep costs783 ordered_modules_by_dep_cost = dict(784 sorted(module_dep_costs.items(), key=lambda item: item[1])785 )786 # construct build graph787 build_graph: List[str] = []788 for name, _ in ordered_modules_by_dep_cost.items():789 build_graph.append(name)790 # append last executable module791 build_graph.append(executable_modules[0])792 return build_graph793 def generate_bff_file(self, build_conf: BuildConf):794 # cache build conf.795 self.build_conf = build_conf796 # get build graph797 build_graph = self.construct_build_graph()798 # looping module generate799 for module_name in build_graph:800 module = self.modules[module_name]801 if not module.is_executable:802 self.add_lib_module_bff(module)803 if module.is_executable:804 self.add_exe_module_bff(module)805 # Alias('All')806 self.finalize_alias(build_conf)807 # dump the bff file (fbuild.bff)808 self.dump()809 return810 def get_output_path(self, build_conf: BuildConf):811 output_path_postfix = "Debug"812 if build_conf is BuildConf.PROFILE:813 output_path_postfix = "Profile"814 elif build_conf is BuildConf.RELEASE:815 output_path_postfix = "Release"816 output_path = os.path.join(817 self.output_path, f"Windows-x64-MSVC16-{output_path_postfix}"818 )819 return output_path820 def add_text(self, text: str):821 self.bff_file.write(text)822 return823 def dump(self):824 self.bff_file.close()...

Full Screen

Full Screen

euros.py

Source:euros.py Github

copy

Full Screen

...116 ("202", "Knockout"),117 ("203", "Results"),118 ("204", "Fixtures"),119 ]:120 self.add_text(n + " ", fg="YELLOW")121 self.add_text(name)122 self.add_newline()123class EuroGroups(Page):124 def __init__(self, data):125 super().__init__("201")126 self.data = data127 self.title = "Euro 2020 Groups"128 self.tagline = "It's coming home"129 def generate_content(self):130 self.add_title("Euro 2020 Groups", font="size4")131 for n, group in enumerate(self.data.points):132 if n % 3 == 0:133 self.move_cursor(y=5)134 if n >= 3:135 st = 40136 else:137 st = 0138 self.move_cursor(x=st)139 self.add_text(f"Group {group}", fg="YELLOW")140 self.move_cursor(x=st + 16)141 self.add_text("P", fg="BLUE")142 self.move_cursor(x=st + 18)143 self.add_text("W", fg="BLUE")144 self.move_cursor(x=st + 20)145 self.add_text("D", fg="BLUE")146 self.move_cursor(x=st + 22)147 self.add_text("L", fg="BLUE")148 self.move_cursor(x=st + 24)149 self.add_text("GD", fg="BLUE")150 self.move_cursor(x=st + 28)151 self.add_text("Pts", fg="BLUE")152 self.add_newline()153 for team in self.data.points[group]:154 self.move_cursor(x=st)155 if team["name"] in self.data.colours:156 self.add_text(team["name"], fg=self.data.colours[team["name"]])157 else:158 self.add_text(team["name"])159 self.move_cursor(x=st + 16)160 self.add_text(str(team["P"]))161 self.move_cursor(x=st + 18)162 self.add_text(str(team["W"]))163 self.move_cursor(x=st + 20)164 self.add_text(str(team["D"]))165 self.move_cursor(x=st + 22)166 self.add_text(str(team["L"]))167 self.move_cursor(x=st + 24)168 self.add_text(str(team["GD"]))169 self.move_cursor(x=st + 28)170 self.add_text(str(team["Pts"]))171 self.add_newline()172 self.add_newline()173 self.add_newline()174class EuroKnockout(Page):175 def __init__(self, data):176 super().__init__("202")177 self.data = data178 self.title = "Euro 2020 Knockout"179 self.tagline = "It's coming home"180 def add_team_name(self, name, align="left", bg=None):181 if name is None:182 name = "???"183 if align == "right":184 self.add_text(" " * (16 - len(name)), bg=bg)185 if align == "center":186 self.add_text(" " * (8 - len(name) // 2), bg=bg)187 if name in self.data.colours:188 self.add_text(name, fg=self.data.colours[name], bg=bg)189 else:190 self.add_text(name, bg=bg)191 if align == "left":192 self.add_text(" " * (16 - len(name)), bg=bg)193 if align == "center":194 self.add_text(" " * (8 - len(name) + len(name) // 2), bg=bg)195 def add_match_right(self, n, x=0, y=0, bg="PINK"):196 m = self.data.matches[n]197 self.move_cursor(x=x, y=y)198 self.add_team_name(m["home"], "right", bg=bg)199 if m["homegoals"] is None:200 self.add_text(" ", bg=bg)201 else:202 self.add_text(f" {m['homegoals']}", bg=bg)203 self.move_cursor(x=x, y=y + 1)204 self.add_text(f"{m['day']} {m['month']} {m['hour']}:{m['minute']}", fg=bg)205 self.add_text(" vs ", bg=bg)206 self.move_cursor(x=x, y=y + 2)207 self.add_team_name(m["away"], "right", bg=bg)208 if m["awaygoals"] is None:209 self.add_text(" ", bg=bg)210 else:211 self.add_text(f" {m['awaygoals']}", bg=bg)212 def add_match_left(self, n, x=0, y=0, bg="PINK"):213 m = self.data.matches[n]214 self.move_cursor(x=x, y=y)215 if m["homegoals"] is None:216 self.add_text(" ", bg=bg)217 else:218 self.add_text(f"{m['homegoals']} ", bg=bg)219 self.add_team_name(m["home"], "left", bg=bg)220 self.move_cursor(x=x, y=y + 1)221 self.add_text(" vs ", bg=bg)222 self.add_text(f"{m['day']} {m['month']} {m['hour']}:{m['minute']}", fg=bg)223 self.move_cursor(x=x, y=y + 2)224 if m["awaygoals"] is None:225 self.add_text(" ", bg=bg)226 else:227 self.add_text(f"{m['awaygoals']} ", bg=bg)228 self.add_team_name(m["away"], "left", bg=bg)229 def add_match_bottom(self, n, x=0, y=0, bg="PINK"):230 m = self.data.matches[n]231 self.move_cursor(x=x, y=y)232 self.add_team_name(m["home"], "right", bg=bg)233 if m["homegoals"] is None:234 self.add_text(" vs ", bg=bg)235 else:236 self.add_text(f" {m['homegoals']} {m['awaygoals']} ", bg=bg)237 self.add_team_name(m["away"], "left", bg=bg)238 self.move_cursor(x=x + 12, y=y + 1)239 self.add_text(f"{m['day']} {m['month']} {m['hour']}:{m['minute']}", fg=bg)240 def add_match_top(self, n, x=0, y=0, bg="PINK"):241 m = self.data.matches[n]242 self.move_cursor(x=x + 12, y=y)243 self.add_text(f"{m['day']} {m['month']} {m['hour']}:{m['minute']}", fg=bg)244 self.move_cursor(x=x, y=y + 1)245 self.add_team_name(m["home"], "right", bg=bg)246 if m["homegoals"] is None:247 self.add_text(" vs ", bg=bg)248 else:249 self.add_text(f" {m['homegoals']} {m['awaygoals']} ", bg=bg)250 self.add_team_name(m["away"], "left", bg=bg)251 def add_match_final(self, n, x=0, y=0, bg="PINK"):252 m = self.data.matches[n]253 self.move_cursor(x=x, y=y)254 self.add_team_name(m["home"], "center", bg=bg)255 self.move_cursor(x=x, y=y + 1)256 self.add_text(" " * 16, bg=bg)257 if m["homegoals"] is not None:258 self.move_cursor(x=x + 7, y=y + 1)259 self.add_text(m['homegoals'], bg=bg)260 self.move_cursor(x=x, y=y + 2)261 self.add_text(" ", bg=bg)262 self.move_cursor(x=x + 1, y=y + 2)263 self.add_text(f"{m['day']} {m['month']} {m['hour']}:{m['minute']}", fg=bg)264 self.move_cursor(x=x + 15, y=y + 2)265 self.add_text(" ", bg=bg)266 self.move_cursor(x=x, y=y + 3)267 self.add_text(" " * 16, bg=bg)268 if m["awaygoals"] is not None:269 self.move_cursor(x=x + 8, y=y + 1)270 self.add_text(m['awaygoals'], bg=bg)271 self.move_cursor(x=x, y=y + 4)272 self.add_team_name(m["away"], "center", bg=bg)273 def generate_content(self):274 self.add_title("Euro 2020 Knockout", font="size4")275 self.add_match_right(39, x=0, y=5)276 self.add_match_right(37, x=0, y=11)277 self.add_match_right(43, x=0, y=17)278 self.add_match_right(42, x=0, y=23)279 self.add_match_left(41, x=62, y=5)280 self.add_match_left(40, x=62, y=11)281 self.add_match_left(38, x=62, y=17)282 self.add_match_left(36, x=62, y=23)283 self.add_match_right(45, x=20, y=6, bg="CYAN")284 self.add_match_left(44, x=42, y=6, bg="CYAN")285 self.add_match_right(47, x=20, y=22, bg="CYAN")286 self.add_match_left(46, x=42, y=22, bg="CYAN")287 self.add_match_top(48, x=21, y=10, bg="ORANGE")288 self.add_match_bottom(49, x=21, y=19, bg="ORANGE")289 self.add_match_final(50, x=32, y=13, bg="GREY")290 ar = chr(8594)291 al = chr(8592)292 au = chr(8593)293 ad = chr(8595)294 self.move_cursor(x=18, y=6)295 self.add_text(f"{ar}{ar}")296 self.move_cursor(x=18, y=24)297 self.add_text(f"{ar}{ar}")298 self.move_cursor(x=60, y=6)299 self.add_text(f"{al}{al}")300 self.move_cursor(x=60, y=24)301 self.add_text(f"{al}{al}")302 self.move_cursor(x=17, y=10)303 self.add_text(f"{au}")304 self.move_cursor(x=17, y=9)305 self.add_text(f"{ar}{ar}{au}")306 self.move_cursor(x=19, y=8)307 self.add_text(f"{ar}")308 self.move_cursor(x=62, y=10)309 self.add_text(f"{au}")310 self.move_cursor(x=60, y=9)311 self.add_text(f"{au}{al}{al}")312 self.move_cursor(x=60, y=8)313 self.add_text(f"{al}")314 self.move_cursor(x=17, y=20)315 self.add_text(f"{ad}")316 self.move_cursor(x=17, y=21)317 self.add_text(f"{ar}{ar}{ad}")318 self.move_cursor(x=19, y=22)319 self.add_text(f"{ar}")320 self.move_cursor(x=62, y=20)321 self.add_text(f"{ad}")322 self.move_cursor(x=60, y=21)323 self.add_text(f"{ad}{al}{al}")324 self.move_cursor(x=60, y=22)325 self.add_text(f"{al}")326 self.move_cursor(x=26, y=9)327 self.add_text(f"{ad}")328 self.move_cursor(x=26, y=10)329 self.add_text(f"{ad}")330 self.move_cursor(x=53, y=9)331 self.add_text(f"{ad}")332 self.move_cursor(x=53, y=10)333 self.add_text(f"{ad}")334 self.move_cursor(x=26, y=21)335 self.add_text(f"{au}")336 self.move_cursor(x=26, y=20)337 self.add_text(f"{au}")338 self.move_cursor(x=53, y=21)339 self.add_text(f"{au}")340 self.move_cursor(x=53, y=20)341 self.add_text(f"{au}")342 self.move_cursor(x=38, y=18)343 self.add_text(f"{au}{au}{au}{au}")344 self.move_cursor(x=38, y=12)345 self.add_text(f"{ad}{ad}{ad}{ad}")346 return347 for m in self.data.matches:348 if m["group"] is None:349 if m["homegoals"] is None:350 self.add_text(f"{m['day']} {m['month']} {m['hour']}:{m['minute']} ")351 self.add_text(" " * (15 - len(m['home'])))352 if m["home"] in self.data.colours:353 self.add_text(m['home'], fg=self.data.colours[m["home"]])354 else:355 self.add_text(m['home'])356 self.add_text(" vs ")357 if m["away"] in self.data.colours:358 self.add_text(m['away'], fg=self.data.colours[m["away"]])359 else:360 self.add_text(m['away'])361 self.add_newline()362 else:363 self.add_text(f"{m['day']} {m['month']} {m['hour']}:{m['minute']} ")364 self.add_text(" " * (15 - len(m['home'])))365 if m["home"] in self.data.colours:366 self.add_text(m['home'], fg=self.data.colours[m["home"]])367 else:368 self.add_text(m['home'])369 self.add_text(" " + str(m['homegoals']))370 self.add_text(" - ")371 self.add_text(str(m['awaygoals']) + " ")372 if m["away"] in self.data.colours:373 self.add_text(m['away'], fg=self.data.colours[m["away"]])374 else:375 self.add_text(m['away'])376 self.add_newline()377class EuroResults(Page):378 def __init__(self, data):379 super().__init__("203")380 self.data = data381 self.title = "Euro 2020 Results"382 self.tagline = "It's coming home"383 def generate_content(self):384 self.add_title("Euro 2020 Results", font="size4")385 self.add_newline()386 for m in self.data.matches[::-1]:387 if m["homegoals"] is not None:388 self.add_text(f"{m['day']} {m['month']} {m['hour']}:{m['minute']} ")389 self.add_text(" " * (15 - len(m['home'])))390 if m["home"] in self.data.colours:391 self.add_text(m['home'], fg=self.data.colours[m["home"]])392 else:393 self.add_text(m['home'])394 self.add_text(f" {m['homegoals']} - {m['awaygoals']} ")395 if m["away"] in self.data.colours:396 self.add_text(m['away'], fg=self.data.colours[m["away"]])397 else:398 self.add_text(m['away'])399 self.add_newline()400class EuroFixtures(Page):401 def __init__(self, data):402 super().__init__("204")403 self.data = data404 self.title = "Euro 2020 Fixtures"405 self.tagline = "It's coming home"406 def generate_content(self):407 self.add_title("Euro 2020 Fixtures", font="size4")408 self.add_newline()409 for m in self.data.matches:410 if m["homegoals"] is None:411 self.add_text(f"{m['day']} {m['month']} {m['hour']}:{m['minute']} ")412 self.add_text(" " * (15 - len(m['home'])))413 if m["home"] in self.data.colours:414 self.add_text(m['home'], fg=self.data.colours[m["home"]])415 else:416 self.add_text(m['home'])417 self.add_text(" vs ")418 if m["away"] in self.data.colours:419 self.add_text(m['away'], fg=self.data.colours[m["away"]])420 else:421 self.add_text(m['away'])422 self.add_newline()423d = FootballData()424page0 = EuroPage(d)425page1 = EuroGroups(d)426page2 = EuroKnockout(d)427page3 = EuroResults(d)...

Full Screen

Full Screen

amalgamate.py

Source:amalgamate.py Github

copy

Full Screen

...9class AmalgamationFile:10 def __init__( self, top_dir ):11 self.top_dir = top_dir12 self.blocks = []13 def add_text( self, text ):14 if not text.endswith( "\n" ):15 text += "\n"16 self.blocks.append( text )17 def add_file( self, relative_input_path, wrap_in_comment=False ):18 def add_marker( prefix ):19 self.add_text( "" )20 self.add_text( "// " + "/"*70 )21 self.add_text( "// %s of content of file: %s" % (prefix, relative_input_path.replace("\\","/")) )22 self.add_text( "// " + "/"*70 )23 self.add_text( "" )24 add_marker( "Beginning" )25 f = open( os.path.join( self.top_dir, relative_input_path ), "rt" )26 content = f.read()27 if wrap_in_comment:28 content = "/*\n" + content + "\n*/"29 self.add_text( content )30 f.close()31 add_marker( "End" )32 self.add_text( "\n\n\n\n" )33 def get_value( self ):34 return "".join( self.blocks ).replace("\r\n","\n")35 def write_to( self, output_path ):36 output_dir = os.path.dirname( output_path )37 if output_dir and not os.path.isdir( output_dir ):38 os.makedirs( output_dir )39 f = open( output_path, "wb" )40 f.write( str.encode(self.get_value(), 'UTF-8') )41 f.close()42def amalgamate_source( source_top_dir=None,43 target_source_path=None,44 header_include_path=None ):45 """Produces amalgated source.46 Parameters:47 source_top_dir: top-directory48 target_source_path: output .cpp path49 header_include_path: generated header path relative to target_source_path.50 """51 print ("Amalgating header...")52 header = AmalgamationFile( source_top_dir )53 header.add_text( "/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/)." )54 header.add_text( "/// It is intented to be used with #include <%s>" % header_include_path )55 header.add_file( "LICENSE", wrap_in_comment=True )56 header.add_text( "#ifndef JSON_AMALGATED_H_INCLUDED" )57 header.add_text( "# define JSON_AMALGATED_H_INCLUDED" )58 header.add_text( "/// If defined, indicates that the source file is amalgated" )59 header.add_text( "/// to prevent private header inclusion." )60 header.add_text( "#define JSON_IS_AMALGAMATION" )61 header.add_file( "include/json/version.h" )62 header.add_file( "include/json/config.h" )63 header.add_file( "include/json/forwards.h" )64 header.add_file( "include/json/features.h" )65 header.add_file( "include/json/value.h" )66 header.add_file( "include/json/reader.h" )67 header.add_file( "include/json/writer.h" )68 header.add_file( "include/json/assertions.h" )69 header.add_text( "#endif //ifndef JSON_AMALGATED_H_INCLUDED" )70 target_header_path = os.path.join( os.path.dirname(target_source_path), header_include_path )71 print ("Writing amalgated header to %r" % target_header_path)72 header.write_to( target_header_path )73 base, ext = os.path.splitext( header_include_path )74 forward_header_include_path = base + "-forwards" + ext75 print ("Amalgating forward header...")76 header = AmalgamationFile( source_top_dir )77 header.add_text( "/// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/)." )78 header.add_text( "/// It is intented to be used with #include <%s>" % forward_header_include_path )79 header.add_text( "/// This header provides forward declaration for all JsonCpp types." )80 header.add_file( "LICENSE", wrap_in_comment=True )81 header.add_text( "#ifndef JSON_FORWARD_AMALGATED_H_INCLUDED" )82 header.add_text( "# define JSON_FORWARD_AMALGATED_H_INCLUDED" )83 header.add_text( "/// If defined, indicates that the source file is amalgated" )84 header.add_text( "/// to prevent private header inclusion." )85 header.add_text( "#define JSON_IS_AMALGAMATION" )86 header.add_file( "include/json/config.h" )87 header.add_file( "include/json/forwards.h" )88 header.add_text( "#endif //ifndef JSON_FORWARD_AMALGATED_H_INCLUDED" )89 target_forward_header_path = os.path.join( os.path.dirname(target_source_path),90 forward_header_include_path )91 print ("Writing amalgated forward header to %r" % target_forward_header_path)92 header.write_to( target_forward_header_path )93 print ("Amalgating source...")94 source = AmalgamationFile( source_top_dir )95 source.add_text( "/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/)." )96 source.add_text( "/// It is intented to be used with #include <%s>" % header_include_path )97 source.add_file( "LICENSE", wrap_in_comment=True )98 source.add_text( "" )99 source.add_text( "#include <%s>" % header_include_path )100 source.add_text( "" )101 lib_json = "src/lib_json"102 source.add_file( os.path.join(lib_json, "json_tool.h") )103 source.add_file( os.path.join(lib_json, "json_reader.cpp") )104 source.add_file( os.path.join(lib_json, "json_batchallocator.h") )105 source.add_file( os.path.join(lib_json, "json_valueiterator.inl") )106 source.add_file( os.path.join(lib_json, "json_value.cpp") )107 source.add_file( os.path.join(lib_json, "json_writer.cpp") )108 print ("Writing amalgated source to %r" % target_source_path)109 source.write_to( target_source_path )110def main():111 usage = """%prog [options]112Generate a single amalgated source and header file from the sources.113"""114 from optparse import OptionParser...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful