📄 __init__.py
字号:
# case 2: Try all the already verified packages with the new # compiler. If everything is ok, use the new compiler, and mark # the new package as verified else: flag = True for vpack in verifiedPackages: try: vdep_packgen = pkgconfig.get_packgen(vpack) except PkgconfigGeneratorMissing: log2("No pkg-config generator for package '%s'. Assuming Ok." % vpack) continue try: vdep_packcfg = packcfgObjs[vpack] vdep_packgen.pkgTests(forceCompiler=dep.compiler, sconsEnv=sconsEnv, cflags=vdep_packcfg.cflags(), libs=vdep_packcfg.ldflags()) except Exception, msg: log2("Some tests failed for package '%s'. Discarding package." % pack) log2(msg) flag = False break if flag: compiler = dep.compiler verifiedPackages[pack] = dep # if dep.compiler and compiler is the same, we just mark the package # as verified: else: verifiedPackages[pack] = dep # If compiler is set and dep.compiler is not, we have to check that the new # package works with the set compiler elif compiler and not dep.compiler: try: dep_packgen = pkgconfig.get_packgen(pack) try: dep_packcfg = packcfgObjs[pack] dep_packgen.pkgTests(forceCompiler=compiler, sconsEnv=sconsEnv, cflags=dep_packcfg.cflags(), libs=dep_packcfg.ldflags()) verifiedPackages[pack] = dep except Exception, msg: # Cannot compile, link, or run package. Discard it. log2("Some tests failed for package '%s'. Discarding package." % pack) log2(msg) continue except PkgconfigGeneratorMissing: # This dep does not have its own pkg-config generator. Treat as verified? log2("No pkg-config generator for package '%s'. Assuming Ok." % pack) verifiedPackages[pack] = dep # If dep.compiler is set and compiler is not, we have to check that the new # compiler can be used with all the verified packages. If so, use the new # one as default and mark the package is verified, if not ditch the new # package (and the compiler) elif dep.compiler and not compiler: flag = True for vpack in verifiedPackages: try: vdep_packgen = pkgconfig.get_packgen(vpack) except PkgconfigGeneratorMissing: # consider this dependency as verified log2("No pkg-config generator for package '%s'. Assuming Ok." % pack) continue try: vdep_packcfg = packcfgObjs[vpack] vdep_packgen.pkgTests(forceCompiler=dep.compiler, sconsEnv=sconsEnv, cflags=vdep_packcfg.cflags(), libs=vdep_packcfg.ldflags()) except Exception, msg: log2("Some tests failed for package '%s'. Discarding package." % pack) log2(msg) flag = False break if flag: compiler = dep.compiler verifiedPackages[pack] = dep print "done" # Store the compiler in the SCons environment and return the verifiedPackages # hash as the new configuredPackages if sconsEnv["CXX"] != compiler: print " Some tests failed using %s" % sconsEnv["CXX"] print " Switching to use %s instead." % compiler sconsEnv['CXX'] = compiler return verifiedPackagesdef circularCheck(modlist, checkModName, allmodules): # mod.dependencies is either a dict (if versions are specified), else # it is just a list. # # For our purpose, though, we only care about the names of # the dependencies. # # When we traverse thorugh, we may stumble upon circular dependencies further # down in the tree - not only for the checkModName, but actually for # any node (module). Hence, we need to aggregate the nodes as we go down in the # tree. So, checkModName should be a list. # # We're doing a depth-first search. # First see if any of the modules in modlist match any of entries in # the checkModName: if len([m for m in checkModName if m in modlist]) > 0: return True else: # only care about the modules in the allmodules (internal) list. nextlevel_modlist = [m for m in modlist if m in allmodules] # dig out the dependencies from each of the modules and the # nextlevel_modlist, and check those: for modName in nextlevel_modlist: mod = allmodules[modName] # need to append modName to the checkModName, but only for this call - # if we get back from this subtree in False state (no circularity # detected), we should not keep modName on the list. if circularCheck(mod.dependencies, checkModName + [modName], allmodules): return True return Falsedef resolveModuleDependencies(modules, configuredPackages, packcfgObjs, internalmodules=None, sconsEnv=_defaultEnv): """Check whether dependencies can be fullfilled For each module, check whether external dependency requirements, given in the 'deps' part, can be fullfilled in the packages configured. If some dependency is given with an explicit version requirement, check that the configured package agree with this requirement. Arguments: modules; a dict with detected modules, which should be resolved configuredPackages; a dict of known external packages internalmodules; if not None, a dict with known internal modules that 'modules' should be resolved against. Use case: when building tests, we need to resolve against the library source modules, not the test modules. Hence we can pass in internalmodules as detected in the library sources. By default, modules is used as internalmodules. sconsEnv; SCons environment that may be modified with a new 'CXX' compiler. A new modules dict and the modified SCons environment are returned. """ # Find a common compiler for this package and it's external dependencies if not sconsEnv.has_key("enableResolveCompiler") or \ sconsEnv["enableResolveCompiler"]: configuredPackages = resolveCompiler(configuredPackages, packcfgObjs, sconsEnv) if not internalmodules: internalmodules = modules # First, we like to take care of circular internal dependencies, which we # do not allow, of any order: # If module A, have deps d = [d1,d2,d3,..], A could not be among the deps # for any of the modules in d. Further on, none of the deps in d must # themself have deps wich in turn include the module A. And so on... deleteModules = [] for modName, mod in internalmodules.items(): if circularCheck(mod.dependencies, [modName], internalmodules): # have to remove 'modName' from the modules that should be # compiled, as a True return from circularCheck indicate that # modName is found among the mod.dependencies, or their dependencies, # recursively. But we are not allowed to do that during interation: # # TODO: check logic here, is it flawed. If we have circular dependencies, # all modules that are involved in the circle must be removed? Or # will that be taken care of below? deleteModules.append(modName) for m in deleteModules: del internalmodules[m] # also remove this modName from the modules, as those are what we # try to resolve: if modules.has_key(m): del modules[m] new_modules = {} check_modules = modules.keys() # should ensure that check_modules is not an empty list, else the pop # will raise an exception. But, if check_modules is empty, we probably # have more important problems already? (at this stage, anyway) modName = check_modules.pop(0) mod = internalmodules[modName] # grab the actual module. check_more = True while check_more: module_ok = True # TODO: Do we have to consider whether dependencies are list or dict # here? for d in mod.dependencies: if d in internalmodules: if d in check_modules: # d not checked yet, postpone check of mod check_modules.append(modName) module_ok = False # Can not say that module is ok yet # but that will be tested later on if len(check_modules) > 0: modName = check_modules.pop(0) mod = internalmodules[modName] else: check_more = False break # exit for-loop, no need to test other deps. elif new_modules.has_key(d): # d is checked and ok, we can just move to next in for-loop continue else: # d is checked and not verified -> throw away mod: module_ok = False print "Warning: Dependency %s will not be compiled" % (d) print " -> Ignoring module %s" % (modName) if len(check_modules) > 0: modName = check_modules.pop(0) mod = internalmodules[modName] else: check_more = False break # exit for-loop, no need to test other deps. elif configuredPackages.has_key(d): # d is an external module # Need to handle both the situation with deps. a dict (with # versions) and deps as a list... (see below) if isinstance(mod.dependencies, dict): # dependencies given with version, have to check against # version in configuredPackages, unless the version requested for this # particular dependency was just given as None - meaning we don't care. request_version = mod.dependencies[d] if request_version: if not checkVersion(configuredPackages[d].version, request_version): # We can not compile module - module_ok = False print "Warning: Requested version %s for package %s is not fullfilled" % (request_version,d) print " -> Ignoring module %s" % (modName) if len(check_modules) > 0: modName = check_modules.pop(0) mod = internalmodules[modName] else: check_more = False break # exit for-loop, no need to test other deps. else: # The dependency that was asked for is neither among the internal modules # nor the configured external packages. Hence we don't know anything about # it and have to throw this module away. module_ok = False print "Warning: Unknown dependency package: %s" % (d) if len(check_modules) > 0: modName = check_modules.pop(0) mod = internalmodules[modName] else: check_more = False break # exit for-loop, no need to test other deps. # we're done with the for-loop. If we get here with module_ok True, # the module can be compiled and should go on into verified_modules # dict. if module_ok: new_modules[modName] = mod if len (check_modules) > 0: modName = check_modules.pop(0) mod = internalmodules[modName] else: check_more = False# for modName, mod in modules.items():## #print "*** Check deps for %s ***" % (modName)# if isinstance(mod.dependencies, dict):# # # for each dependency, we need to check whether the dep. is between # # the configuredPackages.# # If it is, we need to check the version## compileModule = True# for package, request_version in mod.dependencies.items():# if configuredPackages.has_key(package):# #print "package %s is configured" % (package)# #print "request version: ",request_version# #print "found current configured and using version: ",configuredPackages[package].version# if request_version: # requested version is not None# if not checkVersion(configuredPackages[package].version, request_version):# compileModule = False# print "Warning: Requested version %s for package %s is not fullfilled" % (request_version,package)# elif not internalmodules.has_key(package):# compileModule = False# print "Warning: Unknown dependency package: %s" % (package)# else:# pass # Internal dependency; no need to check version.## if not compileModule:# print " -> Ignoring module %s" % (modName)# else:# mod.dependencies = mod.dependencies.keys()# new_modules[modName] = mod# else:# compileModule = True# for package in mod.dependencies:# if not configuredPackages.has_key(package) \# and not internalmodules.has_key(package):# compileModule = False# print "Warning: Unknown dependency package: %s" % (package)## if not compileModule:# print " -> Ignoring module %s" % (modName)# else:# new_modules[modName] = mod # for the remaining modules we need to check whether optional dependencies # was specified, and if so se if we can resolve these. If we can resolve # them, we have to add '-DHAS_<module>' to cxx-flags. found_packages = [] not_found_packages = [] for modName,mod in new_modules.items(): if isinstance(mod.optDependencies, dict): for package,request_version in mod.optDependencies.items(): found = False if configuredPackages.has_key(package): if request_version: # requested version is not None if checkVersion(configuredPackages[package].version, request_version): # Add cxxflags, and add package as a regular dependency. mod.cxxFlags += " -DHAS_%s=1" % (package.upper()) mod.swigFlags.append("-DHAS_%s=1" % (package.upper())) addToDependencies(mod.dependencies,package) found = True else: # Add cxxflags, and add package as a regular dependency. mod.cxxFlags += " -DHAS_%s=1" % (package.upper()) mod.swigFlags.append("-DHAS_%s=1" % (package.upper())) addToDependencies(mod.dependencies,package) found = True elif internalmodules.has_key(package): # Add cxxflags, and add package as a regular dependency. mod.cxxFlags += " -DHAS_%s=1" % (package.upper()) mod.swigFlags.append("-DHAS_%s=1" % (package.upper())) addToDependencies(mod.dependencies,package) found = True else: found = False if not found: not_found_packages.append("%s (version %s)" % (package,request_version)) else: found.append("%s (version %s)" % (package,request_version)) else: for package in mod.optDependencies: found = False if configuredPackages.has_key(package): # Add cxxflags, and add package as a regular dependency. mod.cxxFlags += " -DHAS_%s=1" % (package.upper()) mod.swigFlags.append("-DHAS_%s=1" % (package.upper())) addToDependencies(mod.dependencies,package) found = True elif internalmodules.has_key(package): # Add cxxflags, and add package as a regular dependency. mod.cxxFlags += " -DHAS_%s=1" % (package.upper()) mod.swigFlags.append("-DHAS_%s=1" % (package.upper())) addToDependencies(mod.dependencies,package) found = True else: found = False if not found: not_found_packages.append(package) else: found_packages.append(package) for package in found_packages: print "Found optional package: %s" % package for package in not_found_packages: print "Unable to find optional package: %s" % package return new_modules, sconsEnv# vim:ft=python sw=2 ts=2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -