def addPackageToWasmModule(packageName, currModule, addSourceFiles): for dirpath, dirnames, filenames in os.walk( os.path.join("/occt/occt-628c021/src/", packageName)): for item in filenames: if filterIncludeFile(item): currModule.addHeaderFile(str(os.path.join(dirpath, item))) if filterSourceFile(item) and addSourceFiles: currModule.addSourceFile(str(os.path.join(dirpath, item)))
def addPackageLibrary(libraryName, packageNames): thisLibrary = {} thisLibrary["name"] = libraryName thisLibrary["files"] = [] librariesToBuild.append(thisLibrary) for packageName in packageNames: for dirpath, dirnames, filenames in os.walk(os.path.join("/occt/occt-" + os.environ['OCCT_COMMIT_HASH'] + "/src/", packageName)): for item in filenames: if filterSourceFile(item): thisLibrary["files"].append({ "name": os.path.splitext(item)[0], "packageName": packageName, })
def addObjectFiles(packageName): thisPackage = {} thisPackage["name"] = packageName thisPackage["files"] = [] objectFilesToBuild.append(thisPackage) for dirpath, dirnames, filenames in os.walk(os.path.join("/occt/occt-" + os.environ['OCCT_COMMIT_HASH'] + "/src/", packageName)): for item in filenames: if filterSourceFile(item): thisPackage["files"].append({ "name": os.path.splitext(item)[0], "file": item, "dirpath": dirpath })
def generateWasmModule(moduleName, buildConfig, outputFolder=None): try: os.makedirs('/opencascade.js/build') except: pass try: os.makedirs('/opencascade.js/build/modules') except: pass if outputFolder is None: outputFolder = "/opencascade.js/dist" includeFiles = set() additionalIncludePaths = { "/rapidjson/include", "/freetype/include/freetype", "/freetype/include", } additionalSystemIncludePaths = { "/usr/lib/gcc/x86_64-linux-gnu/10/include", } thisModule = WasmModule( moduleName, "/opencascade.js/build/modules/" + moduleName + ".cpp", outputFolder + "/" + moduleName) if "inputs" in buildConfig and not buildConfig["inputs"] is None: for input in buildConfig["inputs"]: if "package" in input: if not "preBuilt" in input or not input["preBuilt"]: for dirpath, dirnames, filenames in os.walk( os.path.join( "/occt/occt-" + os.environ['OCCT_COMMIT_HASH'] + "/src/", input["package"])): for item in filenames: if filterSourceFile(item): thisModule.addLibraryFile( dirpath + "/" + item, None) else: if "preBuilt" in input and input["preBuilt"]: thisModule.addLibraryFile( input["package"], "/opencascade.js/build/fullLibrary/") else: print("could not process preBuilt setting") if "module" in input: if not "preBuilt" in input or not input["preBuilt"]: with open( "/occt/occt-" + os.environ['OCCT_COMMIT_HASH'] + "/src/" + input["module"] + "/PACKAGES", "r") as a_file: packageNames = list( map(lambda x: x.strip(), filter(lambda x: not x.strip() == "", a_file))) for packageName in packageNames: for dirpath, dirnames, filenames in os.walk( os.path.join( "/occt/occt-" + os.environ['OCCT_COMMIT_HASH'] + "/src/", packageName)): for item in filenames: if filterSourceFile(item): thisModule.addLibraryFile( dirpath + "/" + item, None) else: if "preBuilt" in input and input["preBuilt"]: thisModule.addLibraryFile( input["module"], "/opencascade.js/build/fullLibrary/") else: print("could not process preBuilt setting") if "sourceFile" in input: libFile = input["sourceFile"] libPath = None thisModule.addLibraryFile(libFile, libPath) if type(input) == str and input.startswith("allModules"): if input == "allModules.debug": addAllOcctModulesToWasmModule(thisModule, ".debug") else: if input == "allModules": addAllOcctModulesToWasmModule(thisModule) else: print("unknown input: " + input) else: addAllOcctModulesToWasmModule(thisModule) includes = getGlobalIncludes() includeFiles = includes[0] additionalIncludePaths.update(includes[1]) thisModule.setBindingsFilterFunction( getBindingsFilterFunction(buildConfig["bindings"])) emccFlags = [] if "emccFlags" in buildConfig and not buildConfig["emccFlags"] is None: emccFlags.extend(buildConfig["emccFlags"]) thisModule.headerFiles = list(includeFiles) thisModule.additionalIncludePaths = additionalIncludePaths thisModule.additionalSystemIncludePaths = additionalSystemIncludePaths thisModule.buildFlags = emccFlags return thisModule
allModules[os.path.basename(dirpath)].append(packageName) def getModuleNameByPackageName(inputPackageName): for moduleName in allModules: for package in allModules[moduleName]: packageName = package.strip() if packageName == inputPackageName: return moduleName return "" filesToBuild = [] for dirpath, dirnames, filenames in os.walk(sourceBasePath): packageOrModuleName = os.path.basename(dirpath.replace(sourceBasePath, "")) for item in filenames: if not filterPackages(packageOrModuleName) or not filterPackages(getModuleNameByPackageName(packageOrModuleName)): continue if filterSourceFile(dirpath + "/" + item): filesToBuild.append(dirpath + "/" + item) if __name__ == "__main__": parser = ArgumentParser() parser.add_argument(dest="threading", choices=["single-threaded", "multi-threaded"], help="Build in single vs. multi-threaded mode") args = parser.parse_args() try: os.makedirs(libraryBasePath) except Exception: pass def myBuildFunction(x): buildObjectFiles(x, args)