def writeOutputFiles(self, sourceRoot, outputRoot=None): import util hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') actionsDir = os.path.join(hardcoreDir, 'actions') if outputRoot is None: targetDir = actionsDir else: targetDir = os.path.join(outputRoot, 'modules', 'hardcore', 'actions') util.makedirs(targetDir) changed = util.readTemplate(os.path.join(actionsDir, 'actions_template.h'), os.path.join(targetDir, 'generated_actions.h'), HandleTemplateAction(self)) changed = util.readTemplate(os.path.join(actionsDir, 'actions_enum_template.h'), os.path.join(targetDir, 'generated_actions_enum.h'), HandleTemplateAction(self)) or changed changed = util.readTemplate(os.path.join(actionsDir, 'actions_strings_template.h'), os.path.join(targetDir, 'generated_actions_strings.h'), HandleTemplateAction(self)) or changed # Ignore changes in this; this is just a template for a # platforms' actions.h and not used when building Opera: util.readTemplate(os.path.join(actionsDir, 'actions_template_template.h'), os.path.join(targetDir, 'generated_actions_template.h'), HandleTemplateAction(self)) if targetDir == actionsDir: util.updateModuleGenerated( hardcoreDir, ['actions/generated_actions.h', 'actions/generated_actions_enum.h', 'actions/generated_actions_strings.h', 'actions/generated_actions_template.h']) return changed
def __call__(self, sourceRoot, outputRoot=None, quiet=True): """ Determine a build-identifier (either use the one specified in __init__, or call 'git describe --dirty' to get a build identifier) and use the value on handling the template file. """ self.startTiming() if outputRoot is None: outputRoot = sourceRoot result = 0 build_identifier = self.getBuildIdentifier(sourceRoot, quiet) if build_identifier is None: result = 1 # error on getting the build-identifier error( "Cannot determine build-identifier, please specify a --buildid argument or --fallbackid argument" ) elif util.readTemplate(os.path.join(sourceRoot, self.__template), os.path.join(outputRoot, self.__output), HandleTemplateAction(build_identifier)): result = 2 # output file was changed self.endTiming(result, quiet=quiet) # don't let operasetup regenerate operasetup.h if this file was changed: if result == 2: return 0 else: return result
def writeOutputFiles(self, sourceRoot, outputRoot): hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') mhDir = os.path.join(hardcoreDir, 'mh') if outputRoot is None: targetDir = mhDir else: targetDir = os.path.join(outputRoot, 'modules', 'hardcore', 'mh') util.makedirs(targetDir) changed = util.readTemplate(os.path.join(mhDir, 'messages_template.h'), os.path.join(targetDir, 'generated_messages.h'), HandleTemplateAction(self)) changed = util.readTemplate(os.path.join(mhDir, 'message_strings_template.inc'), os.path.join(targetDir, 'generated_message_strings.inc'), HandleTemplateAction(self)) or changed if targetDir == mhDir: util.updateModuleGenerated(hardcoreDir, ['mh/generated_messages.h', 'mh/generated_message_strings.inc']) return changed
def __call__(self, sourceRoot, outputRoot=None, quiet=True): current_version, milestone = opera_coreversion.getCoreVersion(sourceRoot, "current") next_version, milestone = opera_coreversion.getCoreVersion(sourceRoot, "next") hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') documentationDir = os.path.join(hardcoreDir, 'documentation') version_js_template = os.path.join(documentationDir, 'version_template.js') changes = util.readTemplate( version_js_template, os.path.join(documentationDir, 'version.js'), GenerateVersionJs.TemplateAction(current_version, next_version), hardcoreDir, "documentation/version.js") if changes: return 2 else: return 0
def __call__(self, sourceRoot, feature_def, outputRoot=None, quiet=True): """ Calling this instance will generate the file modules/hardcore/documentation/defines.{version}.xml. It is expected that the specified util.FeatureDefinition instance has already loaded the corresponding features.{version}.txt file. If necessary this method loads and parses also all message, tweaks and apis to obtain a complete list of all defines. @param sourceRoot is the root directory of the source tree that was parsed. Some of the output files are always generated relative to the sourceRoot. @param feature_def is a loaded instance of the class util.FeatureDefinition. That instance collects all defines from features.{version}.txt and all module.tweaks and module.exports. @param outputRoot is the root directory relative to which to generate the output files that depend on the mainline configuration that is given in the specified FeatureDefinition instance. This class ignores the outputRoot as all output files are generated in modules/hardcore/documentation/ relative to the sourceRoot. @param quiet is ignored. @return The convention of the "system-functions" are that the return value should be - 0 to indicate success - 1 to indicate an error - 2 to indicate that output files have changed. """ if not feature_def.messagesLoaded(): messages_parser = messages.MessagesParser(feature_def) messages_parser.loadMessages(sourceRoot) messages_parser.printWarningsAndErrors() if messages_parser.hasErrors(): return 1 if not feature_def.tweaksAndApisLoaded(): tweaks_parser = tweaks_and_apis.TweaksParser( feature_def, sourceRoot) tweaks_parser.parseModuleTweaksAndApis() tweaks_parser.resolveDependencies() tweaks_parser.printWarningsAndErrors() if tweaks_parser.hasErrors(): return 1 hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') if feature_def.coreVersion() is None: defines_xml = 'defines.xml' else: defines_xml = 'defines.%s.xml' % feature_def.coreVersion() changes = util.readTemplate( os.path.join(hardcoreDir, 'base', 'defines_template.xml'), os.path.join(hardcoreDir, 'documentation', defines_xml), GenerateDefinesXml.DefinesTemplateAction(feature_def), hardcoreDir, 'documentation/%s' % defines_xml) if changes: return 2 else: return 0
def generateSourceFile(self, sourceRoot, outputRoot): """ Generates the source file for the jumbo compile unit. @param sourceRoot is the path to the Opera source tree @param outputRoot is the path for output files @return True if the generated source file has changed and False if it has not changed. """ return util.readTemplate(os.path.join(sourceRoot, 'modules', 'hardcore', 'base', 'jumbo_compile_template.cpp'), os.path.join(outputRoot, self.getFilepath()), JumboCompileUnit.TemplateAction(self), os.path.join(outputRoot, self.getModuleDir()), self.name())
def __call__(self, sourceRoot, feature_def, outputRoot=None, quiet=True): """ Calling this instance will generate the file modules/hardcore/documentation/defines.{version}.xml. It is expected that the specified util.FeatureDefinition instance has already loaded the corresponding features.{version}.txt file. If necessary this method loads and parses also all message, tweaks and apis to obtain a complete list of all defines. @param sourceRoot is the root directory of the source tree that was parsed. Some of the output files are always generated relative to the sourceRoot. @param feature_def is a loaded instance of the class util.FeatureDefinition. That instance collects all defines from features.{version}.txt and all module.tweaks and module.exports. @param outputRoot is the root directory relative to which to generate the output files that depend on the mainline configuration that is given in the specified FeatureDefinition instance. This class ignores the outputRoot as all output files are generated in modules/hardcore/documentation/ relative to the sourceRoot. @param quiet is ignored. @return The convention of the "system-functions" are that the return value should be - 0 to indicate success - 1 to indicate an error - 2 to indicate that output files have changed. """ if not feature_def.messagesLoaded(): messages_parser = messages.MessagesParser(feature_def) messages_parser.loadMessages(sourceRoot) messages_parser.printWarningsAndErrors() if messages_parser.hasErrors(): return 1 if not feature_def.tweaksAndApisLoaded(): tweaks_parser = tweaks_and_apis.TweaksParser(feature_def, sourceRoot) tweaks_parser.parseModuleTweaksAndApis() tweaks_parser.resolveDependencies() tweaks_parser.printWarningsAndErrors() if tweaks_parser.hasErrors(): return 1 hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') if feature_def.coreVersion() is None: defines_xml = 'defines.xml' else: defines_xml = 'defines.%s.xml' % feature_def.coreVersion() changes = util.readTemplate( os.path.join(hardcoreDir, 'base', 'defines_template.xml'), os.path.join(hardcoreDir, 'documentation', defines_xml), GenerateDefinesXml.DefinesTemplateAction(feature_def), hardcoreDir, 'documentation/%s' % defines_xml) if changes: return 2 else: return 0
def generateSourceFile(self, sourceRoot, outputRoot): """ Generates the source file for the jumbo compile unit. @param sourceRoot is the path to the Opera source tree @param outputRoot is the path for output files @return True if the generated source file has changed and False if it has not changed. """ return util.readTemplate( os.path.join(sourceRoot, 'modules', 'hardcore', 'base', 'jumbo_compile_template.cpp'), os.path.join(outputRoot, self.getFilepath()), JumboCompileUnit.TemplateAction(self), os.path.join(outputRoot, self.getModuleDir()), self.name())
def __call__(self, sourceRoot, outputRoot=None, quiet=True): self.startTiming() if self.loadKeys(sourceRoot): hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') keysDir = os.path.join(hardcoreDir, 'keys') domModuleDir = os.path.join(sourceRoot, 'modules', 'dom') domDir = os.path.join(domModuleDir, 'src', 'domevents') if not outputRoot or outputRoot == sourceRoot: keysOutputDir = keysDir domOutputDir = domDir else: keysOutputDir = os.path.join(outputRoot, 'modules', 'hardcore', 'keys') domOutputDir = os.path.join(outputRoot, 'modules', 'dom', 'src', 'domevents') handleTemplateAction = GenerateOpKeys.OpKeysTemplateAction( self.__keys, self.__keysBySymbol, self.__keysByName) changed = util.readTemplate( os.path.join(keysDir, 'opkeys_template.h'), os.path.join(keysOutputDir, 'opkeys.h'), handleTemplateAction, hardcoreDir if keysOutputDir == keysDir else None, 'keys/opkeys.h') changed = util.readTemplate( os.path.join(keysDir, 'opkeys_mappings_template.inc'), os.path.join(keysOutputDir, 'opkeys_mappings.inc'), handleTemplateAction, hardcoreDir if keysOutputDir == keysDir else None, 'keys/opkeys_mappings.inc') or changed changed = util.readTemplate( os.path.join(domDir, 'domevent_keys_template.cpp'), os.path.join(domOutputDir, 'domevent_keys.cpp'), handleTemplateAction, domModuleDir if domOutputDir == domDir else None, 'domevent_keys.cpp') or changed if changed: result = 2 # files have changed else: result = 0 # no changes else: result = 1 # error return self.endTiming(result, quiet=quiet)
def __call__(self, sourceRoot, outputRoot = None, quiet = "yes"): self.startTiming() if outputRoot is None: outputRoot = sourceRoot template_file = os.path.join(sourceRoot, "modules", "hardcore", "base", "stashed_defines_template.h") header_file = os.path.join(outputRoot, "core", "stashed_defines.h") # Bind function to this instance. handler = self.HandleTemplateAction.__get__(self, StashDefines) changed = util.readTemplate(template_file, header_file, handler) return self.endTiming(2 if changed else 0)
def __call__(self, sourceRoot, outputRoot=None, quiet=True): self.startTiming() outputRoot = outputRoot or sourceRoot if loadSystem(sourceRoot): hardcoreDir = os.path.join('modules', 'hardcore') baseDir = os.path.join(hardcoreDir, 'base') changed = util.readTemplate(os.path.join(sourceRoot, baseDir, 'system_template.h'), os.path.join(outputRoot, baseDir, 'system.h'), handleTemplateAction, os.path.join(outputRoot, hardcoreDir) if outputRoot == sourceRoot else None, 'base/system.h') if changed: result = 2 else: result = 0 else: result = 1 # errors return self.endTiming(result, sourceRoot=sourceRoot, outputRoot=outputRoot, quiet=quiet)
def writeOutputFiles(self, sourceRoot, outputRoot=None): import util hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') actionsDir = os.path.join(hardcoreDir, 'actions') if outputRoot is None: targetDir = actionsDir else: targetDir = os.path.join(outputRoot, 'modules', 'hardcore', 'actions') util.makedirs(targetDir) changed = util.readTemplate( os.path.join(actionsDir, 'actions_template.h'), os.path.join(targetDir, 'generated_actions.h'), HandleTemplateAction(self)) changed = util.readTemplate( os.path.join(actionsDir, 'actions_enum_template.h'), os.path.join(targetDir, 'generated_actions_enum.h'), HandleTemplateAction(self)) or changed changed = util.readTemplate( os.path.join(actionsDir, 'actions_strings_template.h'), os.path.join(targetDir, 'generated_actions_strings.h'), HandleTemplateAction(self)) or changed # Ignore changes in this; this is just a template for a # platforms' actions.h and not used when building Opera: util.readTemplate( os.path.join(actionsDir, 'actions_template_template.h'), os.path.join(targetDir, 'generated_actions_template.h'), HandleTemplateAction(self)) if targetDir == actionsDir: util.updateModuleGenerated(hardcoreDir, [ 'actions/generated_actions.h', 'actions/generated_actions_enum.h', 'actions/generated_actions_strings.h', 'actions/generated_actions_template.h' ]) return changed
def __call__(self, sourceRoot, outputRoot=None, quiet=True): current_version, milestone = opera_coreversion.getCoreVersion( sourceRoot, "current") next_version, milestone = opera_coreversion.getCoreVersion( sourceRoot, "next") hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') documentationDir = os.path.join(hardcoreDir, 'documentation') version_js_template = os.path.join(documentationDir, 'version_template.js') changes = util.readTemplate( version_js_template, os.path.join(documentationDir, 'version.js'), GenerateVersionJs.TemplateAction(current_version, next_version), hardcoreDir, "documentation/version.js") if changes: return 2 else: return 0
def __call__(self, sourceRoot, outputRoot=None, quiet=True): self.startTiming() libcryptoTestDir = os.path.join(sourceRoot, "modules", "libcrypto", "selftest") filelist = os.listdir(os.path.join(libcryptoTestDir, "data", "widget-digsig-ocsp")) regexp = re.compile(r'.*\.wgt$') for k,v in enumerate(filelist): if not regexp.match(v): del filelist[k] filelist.sort() changed = util.readTemplate(os.path.join(libcryptoTestDir, "gadget_signing_ocsp.ot.template"), os.path.join(libcryptoTestDir, "gadget_signing_ocsp.ot"), HandleTemplateAction(filelist)) if changed: result = 2 else: result = 0 return self.endTiming(result, quiet=quiet)
def create_opera_h(self, sourceRoot, outputRoot=None): """ Creates modules/hardcore/opera/opera.h from the corresponding template file modules/hardcore/opera/opera_template.h. The file is generate relative to the specified outputRoot. If the outputRoot is not specified, sourceRoot is used. If outputRoot == sourceRoot then hardcore's module.generated is updated with the line "opera/opera.h". Returns true if the generated file was changed. """ if outputRoot is None: outputRoot = sourceRoot hardcoreDir = os.path.join(sourceRoot, "modules", "hardcore") template = os.path.join(hardcoreDir, "opera", "opera_template.h") opera_h = os.path.join(outputRoot, "modules", "hardcore", "opera", "opera.h") changed = util.readTemplate(template, opera_h, self.getTemplateActionHandler(sourceRoot)) if sourceRoot == outputRoot: util.updateModuleGenerated(hardcoreDir, ["opera/opera.h"]) return changed
def create_components_h(self, sourceRoot, outputRoot=None): """ Creates modules/hardcore/opera/components.h from the template file modules/hardcore/opera/components_template.h and the module.components file from all modules. The file is generated relative to the specified outputRoot. If the outputRoot is not specified, sourceRoot is used. If outputRoot == sourceRoot then hardcore's module.generated is updated with the line 'opera/components.h'. Returns true if the generated file was changed. """ if outputRoot is None: outputRoot = sourceRoot hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') operaDir = os.path.join(hardcoreDir, 'opera') changed = util.readTemplate(os.path.join(operaDir, 'components_template.h'), os.path.join(outputRoot, 'modules', 'hardcore', 'opera', 'components.h'), ComponentTemplateActionHandler(self.components())) if sourceRoot == outputRoot: util.updateModuleGenerated(hardcoreDir, ["opera/components.h"]) return changed
def create_components_h(self, sourceRoot, outputRoot=None): """ Creates modules/hardcore/opera/components.h from the template file modules/hardcore/opera/components_template.h and the module.components file from all modules. The file is generated relative to the specified outputRoot. If the outputRoot is not specified, sourceRoot is used. If outputRoot == sourceRoot then hardcore's module.generated is updated with the line 'opera/components.h'. Returns true if the generated file was changed. """ if outputRoot is None: outputRoot = sourceRoot hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') operaDir = os.path.join(hardcoreDir, 'opera') changed = util.readTemplate( os.path.join(operaDir, 'components_template.h'), os.path.join(outputRoot, 'modules', 'hardcore', 'opera', 'components.h'), ComponentTemplateActionHandler(self.components())) if sourceRoot == outputRoot: util.updateModuleGenerated(hardcoreDir, ["opera/components.h"]) return changed
def __call__(self, sourceRoot, outputRoot=None, quiet=True): self.startTiming() libcryptoTestDir = os.path.join(sourceRoot, "modules", "libcrypto", "selftest") filelist = os.listdir( os.path.join(libcryptoTestDir, "data", "widget-digsig-ocsp")) regexp = re.compile(r'.*\.wgt$') for k, v in enumerate(filelist): if not regexp.match(v): del filelist[k] filelist.sort() changed = util.readTemplate( os.path.join(libcryptoTestDir, "gadget_signing_ocsp.ot.template"), os.path.join(libcryptoTestDir, "gadget_signing_ocsp.ot"), HandleTemplateAction(filelist)) if changed: result = 2 else: result = 0 return self.endTiming(result, quiet=quiet)
def __call__(self, sourceRoot, outputRoot=None, quiet="yes"): self.startTiming() if outputRoot is None: outputRoot = sourceRoot css_values_txt = os.path.join(sourceRoot, "modules", "style", "src", "css_values.txt") css_values_template_h = os.path.join(sourceRoot, "modules", "style", "src", "css_values_template.h") css_values_h = os.path.join(outputRoot, "modules", "style", "src", "css_values.h") css_value_strings_template_h = os.path.join( sourceRoot, "modules", "style", "src", "css_value_strings_template.h" ) css_value_strings_h = os.path.join(outputRoot, "modules", "style", "src", "css_value_strings.h") longest_value = None values = [] macros = [] lengths = {} re_macro = re.compile("^\#define|^\#ifdef|^\#endif|^\#else") re_comment = re.compile("^\/\/") re_internal = re.compile("^#internal (.*)") util.fileTracker.addInput(css_values_txt) f = open(css_values_txt) for lineidx, line in enumerate(f): if re_macro.match(line): macros.append(line) elif re_comment.match(line) or line == "\n": pass else: internal = False m = re_internal.match(line) if m: line = m.group(1) internal = True try: kv = line try: [kv, comment] = re.split("//", kv) except: pass [k, v] = re.split("\s+", kv.strip()) except ValueError: self.warning("%s:%d: ignoring unknown line '%s'" % (css_values_txt, lineidx + 1, line.strip())) continue v = CSSValue(k, v, internal) values.append(v) if not internal: if longest_value == None or v.length() > longest_value.length(): longest_value = v lengths.setdefault(v.length(), 0) lengths[v.length()] += 1 changed = util.readTemplate( css_values_template_h, css_values_h, CSSValuesTemplateActionHandler(values, macros, longest_value) ) changed = util.readTemplate( css_value_strings_template_h, css_value_strings_h, CSSValueStringsTemplateActionHandler(values, lengths, longest_value), ) if changed: result = 2 else: result = 0 return self.endTiming(result, quiet=quiet)
module_sources.write("# Note: The generated source files needs to include several\n") module_sources.write("# system header files. Thus it defines COMPILING_SQLITE before\n") module_sources.write("# including core/pch_system_includes.h so the platform's system.h is\n") module_sources.write("# able to prepare for that. So all files need options\n") module_sources.write("# [no-jumbo;system_includes;no-pch]\n") verbose("Scanning for .c files...") # find the .c files for filename in glob.glob(os.path.join(sqliteDir, "src", "*.c")): verbose(" Found %s" % relative_filename(filename), 1) basename = os.path.basename(filename) if basename not in exclude_files: wrapper_filename = os.path.join(sqliteDir, "generated", "sqlite_" + basename) verbose(" Wrapping %s into %s" % (relative_filename(filename), relative_filename(wrapper_filename)), 2) if util.readTemplate(wrapper_template, wrapper_filename, HandleTemplateAction(basename)): verbose(" Updated %s" % relative_filename(wrapper_filename)) else: verbose(" File %s not changed" % relative_filename(wrapper_filename), 2) module_sources.write("%s # [winnopch]\n" % '/'.join(["generated", "sqlite_" + basename])) else: verbose(" Excluded %s" % filename, 2) verbose("Finished wrapping .c files."); if (util.updateFile(module_sources, os.path.join(sqliteDir, "module.sources"))): verbose("Updated module.sources") else: verbose("module.sources not changed")
def __call__(self, sourceRoot, feature_def, outputRoot=None, quiet=True): """ Generates the following files in the specified output root: - modules/hardcore/features/features.h - modules/hardcore/features/features-thirdparty_attributions.inl - modules/hardcore/features/profile_{profile}.h for all profiles Generates the following files in the specified source root: - modules/hardcore/opera/setupinfo_features.cpp - modules/hardcore/documentation/features.{core_version}.xml for the core_version as given by the specified feature_def. @param sourceRoot is the path to the Opera source tree @param feature_def specifies a loaded instance of the class util.FeatureDefinition @param outputRoot is the path in which to generate the output files modules/hardcore/features/features.h modules/hardcore/features/profile_{profile}.h If this argument is None, then {sourceRoot}/modules/hardcore/features/ is used. """ self.startTiming() if feature_def is None or not feature_def.isLoaded(): error("the argument feature_def must be a loaded util.FeatureDefinition instance") result = 1 else: hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') featuresDir = os.path.join(hardcoreDir, 'features') if outputRoot is None: targetDir = featuresDir else: targetDir = os.path.join(outputRoot, 'modules', 'hardcore', 'features') changed = util.makedirs(targetDir) # TODO: instead of creating a copy of "features.h" for each # profile in # opera/profiles/{profile}.[next]/include/modules/hardcore/features/ # with the same content, try to find a place for that include file # which only depends on "current" or "next" mainline-configuration: changed = util.readTemplate( os.path.join(featuresDir, 'features_template.h'), os.path.join(targetDir, 'features.h'), HandleTemplateAction(feature_def)) or changed changed = util.readTemplate(os.path.join(featuresDir, 'features-thirdparty_attributions_template.inl'), os.path.join(targetDir, 'features-thirdparty_attributions.inl'), LegalTemplateActionHandler(feature_def)) or changed # TODO: instead of creating profile_XXX.h for all profiles XXX in # opera/profile/{profile}.[next]/include/modules/hardcore/features/, # only create profile_{profile}.h for the one profile that is # needed: for profile in util.PROFILES: changed = util.readTemplate( os.path.join(featuresDir, 'profile_template.h'), os.path.join(targetDir, 'profile_%s.h' % profile), ProfileTemplateActionHandler(profile, feature_def.featuresWithDefault())) or changed if targetDir == featuresDir: util.updateModuleGenerated(hardcoreDir, ['features/features.h', 'features/features-thirdparty_attributions.inl'] + ['features/profile_%s.h' % profile for profile in util.PROFILES]) # Ignore changes in setupinfo_features.cpp and documentation files: setupinfoDir = os.path.join(hardcoreDir, 'opera') documentationDir = os.path.join(hardcoreDir, 'documentation') if outputRoot is None: setupinfoOutputDir = setupInfoDir documentationOutputDir = documentationDir else: setupinfoOutputDir = os.path.join(outputRoot, 'modules', 'hardcore', 'opera') documentationOutputDir = os.path.join(outputRoot, 'modules', 'hardcore', 'documentation') # TODO: create a different output file # setupinfo_features.{core_version}.cpp for different # core-versions - note: this is only required if new features are # added or the documentation of a feature is changed. util.readTemplate( os.path.join(setupinfoDir, 'setupinfo_features_template.cpp'), os.path.join(setupinfoOutputDir, 'setupinfo_features_generated.inl'), HandleTemplateAction(feature_def), hardcoreDir if setupinfoDir == setupinfoOutputDir else None, 'opera/setupinfo_features.cpp') if feature_def.coreVersion() is None: features_xml = 'features.xml' else: features_xml = 'features.%s.xml' % feature_def.coreVersion() util.readTemplate( os.path.join(featuresDir, 'features_template.xml'), os.path.join(documentationOutputDir, features_xml), HandleTemplateAction(feature_def), hardcoreDir if documentationDir == documentationOutputDir else None, 'documentation/%s' % features_xml) if changed: result = 2 else: result = 0 return self.endTiming(result, sourceRoot=sourceRoot, outputRoot=outputRoot, quiet=quiet)
def generateTables(self): max_name_len = 0 name_map = {} normals = None specials = None type_filename = "" name_filename = "" file_name_suffix = "" has_changed = False if markup_debug: file_name_suffix = ".debug" # # Generate element tables # normals = self.elements specials = self.special_elements type_filename = self.type_file_pattern % ("element", "%s") name_filename = self.name_file_pattern % ("element", "%s") normals.sort() # Scan through the list to find duplicate names and # the length of the longest name for [name, ns, prefix] in normals: if not name in name_map: name_map[name] = [ns, prefix] if len(name) > max_name_len: max_name_len = len(name) type_template_file = os.path.join(self.template_file_path, type_filename % "_template") name_template_file = os.path.join(self.template_file_path, name_filename % "_template") type_out_file = os.path.join(self.out_file_path, type_filename % file_name_suffix) name_out_file = os.path.join(self.out_file_path, name_filename % file_name_suffix) logmessage( "\nGenerating element type file:\n %s\nfrom template:\n %s\n" % (type_out_file, type_template_file)) if util.readTemplate( type_template_file, type_out_file, self.MarkupTypeTemplateAction(False, normals, specials, name_map, max_name_len)): has_changed = True logmessage( "\nGenerating element name file:\n %s\nfrom template:\n %s\n" % (name_out_file, name_template_file)) if util.readTemplate( name_template_file, name_out_file, self.MarkupNameTemplateAction(False, normals, name_map, self.bigendian)): has_changed = True # # Generate attribute tables # name_map = {} normals = self.attributes specials = self.special_attributes type_filename = self.type_file_pattern % ("attr", "%s") name_filename = self.name_file_pattern % ("attr", "%s") normals.sort() # Scan through the list to find duplicate names and # the length of the longest name for [name, ns, prefix] in normals: if not name in name_map: name_map[name] = [ns, prefix] if len(name) > max_name_len: max_name_len = len(name) type_template_file = os.path.join(self.template_file_path, type_filename % "_template") name_template_file = os.path.join(self.template_file_path, name_filename % "_template") type_out_file = os.path.join(self.out_file_path, type_filename % file_name_suffix) name_out_file = os.path.join(self.out_file_path, name_filename % file_name_suffix) logmessage( "\nGenerating attribute type file:\n %s\nfrom template:\n %s\n" % (type_out_file, type_template_file)) if util.readTemplate( type_template_file, type_out_file, self.MarkupTypeTemplateAction(True, normals, specials, name_map, max_name_len)): has_changed = True logmessage( "\nGenerating attribute name file:\n %s\nfrom template:\n %s\n" % (name_out_file, name_template_file)) if util.readTemplate( name_template_file, name_out_file, self.MarkupNameTemplateAction(True, normals, name_map, self.bigendian)): has_changed = True return has_changed
def __call__(self, sourceRoot, outputRoot=None, quiet=True, show_all=False): """ Calling this instance will generate the source files from all prefs .txt files. @param sourceRoot is the root directory of the source tree that was parsed. Some of the output files are always generated relative to the sourceRoot. @param outputRoot root of the tree for generated files, defaults to sourceRoot @param quiet if False, print some log messages about executing the perl script. @param show_all controls whether to show only modified files or all files which are inspected. Default is False. @return The convention of the "system-functions" are that the return value should be - 0 to indicate success - 1 to indicate an error - 2 to indicate that output files have changed. """ self.startTiming() if outputRoot == None: outputRoot = sourceRoot perl = self.findPerl(quiet) if perl is None: return self.endTiming(1, quiet=quiet) # Now perl should be the path to a perl executable # Scan for modules and prefs files and build the structure allfiles = [] changed = False for module, files in find_prefs_files(sourceRoot): modfiles = [] for filename in files: self.logmessage(quiet, "Creating prefs enum for %s" % (filename)) parser = PrefsCollectionParser() parser.parse("%s.txt" % filename) if not quiet: parser.printParserWarnings() if parser.printParserErrors(): return self.endTiming(1, quiet=quiet) handler = PrefsCollectionTemplateActionHandler( parser.header(), parser.items()) stem = os.path.relpath(filename, sourceRoot) outdir = os.path.dirname(os.path.join(outputRoot, stem)) basename = os.path.basename(filename) prefs_collection_dir = os.path.join("modules", "prefs", "prefsmanager", "collections") pc_template_h = os.path.join(sourceRoot, prefs_collection_dir, "pc_template.h") output_h = os.path.join(outdir, "%s_h.inl" % basename) changed = util.readTemplate(pc_template_h, output_h, handler) or changed pc_template_c = os.path.join(sourceRoot, prefs_collection_dir, "pc_template.cpp") output_c = os.path.join(outdir, "%s_c.inl" % basename) changed = util.readTemplate(pc_template_c, output_c, handler) or changed modfiles += [output_c, output_h] allfiles.append(stem) util.fileTracker.addInput(stem + ".cpp") # Will be used by extract-documentation.pl # List the generated files in module.generated if outputRoot == sourceRoot: util.updateModuleGenerated(module.fullPath(), modfiles) # Update documentation for f in ('modules/prefs/prefsmanager/opprefscollection.cpp', 'modules/prefs/prefsmanager/opprefscollection.h', 'modules/prefs/module.tweaks', 'modules/prefs/prefsmanager/collections/erasettings.h', 'modules/pi/OpSystemInfo.h'): util.fileTracker.addInput(f) # Will be used by extract-documentation.pl if changed: documentation_dir = os.path.join(sourceRoot, "modules", "prefs") documentation_output_dir = os.path.join(outputRoot, "modules", "prefs") documentation_path = os.path.join(documentation_dir, "extract-documentation.pl") util.makedirs(os.path.join(documentation_output_dir, "documentation")) self.logmessage(quiet, "calling script %s" % (documentation_path)) subprocess.call([perl, documentation_path, "-o", outputRoot] + allfiles, cwd=sourceRoot) if outputRoot == sourceRoot: util.updateModuleGenerated(documentation_output_dir, ["documentation/settings.html"]) if changed: result = 2 else: result = 0 return self.endTiming(result, quiet=quiet)
if module_sources.cpp(source_file): extension = "cpp" original_filename = sourcename[6:] + "." + extension else: extension = "c" filename = "opera_" + sourcename + ".cpp" file_path[-1] = filename options = module_sources.getSourceOptionString(source_file) if len(options) == 0: module_sources_out.write("%s\n" % '/'.join(file_path)) else: module_sources_out.write("%s # [%s]\n" % ('/'.join(file_path).ljust(34), options)) if util.readTemplate( wrapper_template, os.path.join(libopeayDir, *file_path), HandleTemplateAction( extension == "cpp", module_sources, source_file, "/".join(file_path[0:-1] + [original_filename]))): changed_files.append(os.path.join(*file_path)) if util.updateFile(module_sources_out, os.path.join(libopeayDir, "module.sources")): print "module.sources updated" else: print "module.sources not changed" if len(changed_files): print "%d wrapper files updated:" % len(changed_files), changed_files else: print "No wrapper file changed"
def __call__(self, sourceRoot, outputRoot=None, quiet="yes"): self.startTiming() if outputRoot is None: outputRoot = sourceRoot # File names css_properties_txt = os.path.join(sourceRoot, "modules", "style", "src", "css_properties.txt") css_aliases_template_h = os.path.join(sourceRoot, "modules", "style", "src", "css_aliases_template.h") css_aliases_h = os.path.join(outputRoot, "modules", "style", "src", "css_aliases.h") css_property_strings_template_h = os.path.join( sourceRoot, "modules", "style", "src", "css_property_strings_template.h") css_property_strings_h = os.path.join(outputRoot, "modules", "style", "src", "css_property_strings.h") css_properties_template_h = os.path.join(sourceRoot, "modules", "style", "src", "css_properties_template.h") css_properties_h = os.path.join(outputRoot, "modules", "style", "src", "css_properties.h") css_properties_internal_txt = os.path.join( sourceRoot, "modules", "style", "src", "css_properties_internal.txt") atoms_txt = os.path.join(sourceRoot, "modules", "dom", "src", "atoms.txt") # Read the property names from css_properties.txt into a set, with # their aliases in a dictionary, and the properties which are not # aliases into another set properties = set([]) non_alias_properties = set([]) aliases = dict({}) try: f = None util.fileTracker.addInput(css_properties_txt) f = open(css_properties_txt) for line in f.read().split("\n"): if line: props = line.split(",") for p in props: p = p.strip() if p not in properties: properties.add(p) else: self.error( "Error: css property '%s' declared multiple times." % p) return self.endTiming(1, quiet=quiet) name = props[0].strip() non_alias_properties.add(name) if len(props) >= 2: for a in props[1:]: a = a.strip() aliases.setdefault(name, []).append(a) finally: if f: f.close() sorted_properties = sorted(properties, cmp=sort_properties) # Read internal property names from css_propertiesi_internal.txt into a # set internal_properties = set([]) try: f = None util.fileTracker.addInput(css_properties_internal_txt) f = open(css_properties_internal_txt) for line in f.read().split("\n"): p = line.strip() if p: if p not in internal_properties and p not in properties: internal_properties.add(p) else: self.error( "Error: css property '%s' declared multiple times." % p) return self.endTiming(1, quiet=quiet) finally: if f: f.close() sorted_internal_properties = sorted(internal_properties, cmp=sort_properties) # Regenerate css_properties.txt, with sorted non-alias properties each # followed by their alias to css_properties.txt,: output = StringIO.StringIO() for p in sorted(non_alias_properties, cmp=sort_properties): if p in aliases: output.write("%s, %s\n" % (p, ", ".join(sorted(aliases[p])))) else: output.write("%s\n" % p) changed = util.updateFile(output, css_properties_txt) # Create css_aliases.h from its template: changed = util.readTemplate( css_aliases_template_h, css_aliases_h, CssAliasesTemplateActionHandler(aliases)) or changed # Create css_property_strings.h from its template: changed = util.readTemplate( css_property_strings_template_h, css_property_strings_h, PropertyStringsTemplateActionHandler(sorted_properties)) or changed # Create css_properties.h from its template: changed = util.readTemplate( css_properties_template_h, css_properties_h, PropertiesTemplateActionHandler( sorted_properties, sorted_internal_properties)) or changed # Check that all properties are mCheck that all properties are in used # the atoms.txt file in dom as well. try: f = None util.fileTracker.addInput(atoms_txt) f = open(atoms_txt, "r") atoms = f.read().lower() for p in properties: if re.sub("-", "", p.lower()) not in atoms: self.error( "Warning: %s is missing from modules/dom/src/atoms.txt" % p) finally: if f: f.close() if changed: result = 2 else: result = 0 return self.endTiming(result, quiet=quiet)
def __call__(self, sourceRoot, outputRoot=None, quiet="yes"): self.startTiming() if outputRoot is None: outputRoot = sourceRoot css_values_txt = os.path.join(sourceRoot, "modules", "style", "src", "css_values.txt") css_values_template_h = os.path.join(sourceRoot, "modules", "style", "src", "css_values_template.h") css_values_h = os.path.join(outputRoot, "modules", "style", "src", "css_values.h") css_value_strings_template_h = os.path.join( sourceRoot, "modules", "style", "src", "css_value_strings_template.h") css_value_strings_h = os.path.join(outputRoot, "modules", "style", "src", "css_value_strings.h") longest_value = None values = [] macros = [] lengths = {} re_macro = re.compile("^\#define|^\#ifdef|^\#endif|^\#else") re_comment = re.compile("^\/\/") re_internal = re.compile("^#internal (.*)") util.fileTracker.addInput(css_values_txt) f = open(css_values_txt) for lineidx, line in enumerate(f): if (re_macro.match(line)): macros.append(line) elif re_comment.match(line) or line == "\n": pass else: internal = False m = re_internal.match(line) if (m): line = m.group(1) internal = True try: kv = line try: [kv, comment] = re.split("//", kv) except: pass [k, v] = re.split('\s+', kv.strip()) except ValueError: self.warning("%s:%d: ignoring unknown line '%s'" % (css_values_txt, lineidx + 1, line.strip())) continue v = CSSValue(k, v, internal) values.append(v) if not internal: if (longest_value == None or v.length() > longest_value.length()): longest_value = v lengths.setdefault(v.length(), 0) lengths[v.length()] += 1 changed = util.readTemplate( css_values_template_h, css_values_h, CSSValuesTemplateActionHandler(values, macros, longest_value)) changed = util.readTemplate( css_value_strings_template_h, css_value_strings_h, CSSValueStringsTemplateActionHandler(values, lengths, longest_value)) if changed: result = 2 else: result = 0 return self.endTiming(result, quiet=quiet)
def generatePchFiles(sourceRoot, outputRoot, platform_product_config=None, pch_template=None): """ Generates from modules/hardcore/base/pch_template.h the header files core/pch.h, core/pch_jumbo.h, core/pch_system_includes.h @param sourceRoot is the path to the Opera source tree. @param outputRoot is the output directory in which to generate the header files. If outputRoot is None, the header files are generated relative to the specified sourceRoot. @param platform_product_config is the platform's config file that #defines the PRODUCT_* macros. That file is included by the generated pch header files. If no config file is specified, an #error statement is generated to indicate that these macros are needed on compiling the sources. @param pch_template is the template file that should be used when generating pch files @return True if any of the generated files was updated and False if none of the files were changed. """ class CreatePchFromTemplate: """ Creates a core/pch...h file frome the template file modules/hardcore/base/pch_template.h. """ def __init__(self, filename, platform_product_config=None): """ @param filename is the name of the header file to create. This name is used to generate the #ifndef...#define...#endif statements. @param platform_product_config is the path to the platform's config file which #defines the PRODUCT_* macros. If no config file is specified, an #error statement is generated to indicate that these macros are needed on compiling the sources. """ self.__define = "_CORE_%s_" % filename.replace('.', '_').upper() self.__platform_product_config = platform_product_config if filename == "pch_system_includes.h": # only core/pch_system_includes.h should add a # #define ALLOW_SYSTEM_INCLUDES self.__allow_system_includes = True else: self.__allow_system_includes = False def __call__(self, action, output): if action == "ifndef file_h": output.write("#ifndef %s\n" % self.__define) return True elif action == "define file_h": output.write("#define %s\n" % self.__define) return True elif action == "define ALLOW_SYSTEM_INCLUDES": if self.__allow_system_includes: # enclose in ifndef, because sometimes it's defined globally # (in Opera.vcxproj generated by vcxproj_update.py) # and in this case redefinition gives a lot of compilation warnings output.write("#ifndef ALLOW_SYSTEM_INCLUDES\n") output.write("#define ALLOW_SYSTEM_INCLUDES\n") output.write("#endif // ALLOW_SYSTEM_INCLUDES\n\n") return True elif action == "endif file_h": output.write("#endif // %s\n" % self.__define) return True elif action == "include platform config": if self.__platform_product_config: output.write("#include \"%s\"\n" % self.__platform_product_config) else: output.write("#ifdef PRODUCT_CONFIG_FILE\n") output.write("// The platform may define a command line define PRODUCT_CONFIG_FILE:\n") output.write("// 'PRODUCT_CONFIG_FILE=\"platforms/my_platform/product_config.h\"' which\n") output.write("// defines a header file that is included here. The header file has the\n") output.write("// possibility to define the PRODUCT_*_FILE macros e.g. like\n") output.write("// #define PRODUCT_FEATURE_FILE \"platforms/my_platform/features.h\"\n") output.write("// #define PRODUCT_SYSTEM_FILE \"platforms/my_platform/system.h\"\n") output.write("// #define PRODUCT_OPKEY_FILE \"platforms/my_platform/opkey.h\"\n") output.write("// #define PRODUCT_ACTIONS_FILE \"platforms/my_platform/actions.h\"\n") output.write("// #define PRODUCT_TWEAKS_FILE \"platforms/my_platform/tweaks.h\"\n") output.write("# include PRODUCT_CONFIG_FILE\n") output.write("#endif // PRODUCT_CONFIG_FILE\n") return True changed = False hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') if not pch_template: baseDir = os.path.join(hardcoreDir, 'base') pch_template = os.path.join(baseDir, 'pch_template.h') elif not os.path.isabs(pch_template): pch_template = os.path.join(sourceRoot, pch_template) if not os.path.exists(pch_template): raise IOError(errno.ENOENT, "Template file '%s' (passed with --pch_template) not found" % pch_template) for pch in ('pch.h', 'pch_jumbo.h', 'pch_system_includes.h'): changed = util.readTemplate( pch_template, os.path.join(outputRoot, 'core', pch), CreatePchFromTemplate(pch, platform_product_config)) or changed # if the pch files are generated relative to the modules/hardcore # dir, update hardcore's module.generated: match = re.match("^%s(.*)$" % re.escape(hardcoreDir+os.sep), outputRoot) if match: base = match.group(1).replace(os.sep, '/') util.updateModuleGenerated(os.path.join(sourceRoot, 'modules', 'hardcore'), map(lambda h: '/'.join([base, 'core', h]), ['pch.h', 'pch_jumbo.h', 'pch_system_includes.h'])) return changed
class SVGPresentationAttrGenerator(util.WarningsAndErrors): """ Parses presentation_attributes.txt and generates the presentation attributes table. """ def __init__(self): util.WarningsAndErrors.__init__(self, sys.stderr) self.debug_mode = False def __call__(self, sourceRoot, outputRoot, quiet, debug=False, standalone=False): global is_standalone self.standalone = standalone or is_standalone self.debug_mode = debug presentation_attrs = {} attributes = [] num_attributes = 0 if outputRoot is None: outputRoot = sourceRoot attr_file_name = os.path.join(outputRoot, "modules", "logdoc", "src", "html5", "attrtypes.inl") if debug: attr_file_name = os.path.join(sourceRoot, "modules", "logdoc", "scripts", "attrtypes.debug.inl") pres_attr_file_name = os.path.join(sourceRoot, "modules", "svg", "scripts", "presentation_attributes.txt") template_file_name = os.path.join(sourceRoot, "modules", "svg", "scripts", "pres_attrs_template.h") out_file_name = os.path.join(outputRoot, "modules", "svg", "presentation_attrs.h") if debug: out_file_name = os.path.join(sourceRoot, "modules", "svg", "scripts", "presentation_attrs.debug.h") # read the list of presentation attributes self.logmessage("Reading: %s" % pres_attr_file_name) pres_attr_file = open(pres_attr_file_name, "r") for line in pres_attr_file: new_attr_name = line.strip()[8:] presentation_attrs[new_attr_name] = True pres_attr_file.close() # read the list of all attributes self.logmessage("Reading: %s" % attr_file_name) skip_next = False current_placeholder = "" attr_file = open(attr_file_name, "r") for line in attr_file: found = re.match("[\s,]+(\w+)(\s=\s(\w+))*", line) if found: if skip_next: skip_next = False else: attr_name = found.group(1) attr_value = found.group(3) if attr_value: if attr_value == current_placeholder: attributes.append(attr_name) # put the real attribute name in the list current_placeholder = "" elif attr_name[0:5] == "SVGA_": attributes.pop() # remove the already inserted non-svg entry... attributes.append(attr_name) # ...and replace it with the svg one else: if attr_name[-13:] == "__PLACEHOLDER": current_placeholder = attr_name # store the placeholder to check later else: attributes.append(attr_name) current_placeholder = "" self.logmessage("Generating: %s" % out_file_name) if util.readTemplate(template_file_name, out_file_name, self.BitsetAction(attributes, presentation_attrs)): self.logmessage("Success") return 2 self.logmessage("No change") return 0
def __call__(self, sourceRoot, feature_def, outputRoot=None, quiet=True): """ Generates the following files in the specified output root: - modules/hardcore/features/features.h - modules/hardcore/features/features-thirdparty_attributions.inl - modules/hardcore/features/profile_{profile}.h for all profiles Generates the following files in the specified source root: - modules/hardcore/opera/setupinfo_features.cpp - modules/hardcore/documentation/features.{core_version}.xml for the core_version as given by the specified feature_def. @param sourceRoot is the path to the Opera source tree @param feature_def specifies a loaded instance of the class util.FeatureDefinition @param outputRoot is the path in which to generate the output files modules/hardcore/features/features.h modules/hardcore/features/profile_{profile}.h If this argument is None, then {sourceRoot}/modules/hardcore/features/ is used. """ self.startTiming() if feature_def is None or not feature_def.isLoaded(): error( "the argument feature_def must be a loaded util.FeatureDefinition instance" ) result = 1 else: hardcoreDir = os.path.join(sourceRoot, 'modules', 'hardcore') featuresDir = os.path.join(hardcoreDir, 'features') if outputRoot is None: targetDir = featuresDir else: targetDir = os.path.join(outputRoot, 'modules', 'hardcore', 'features') changed = util.makedirs(targetDir) # TODO: instead of creating a copy of "features.h" for each # profile in # opera/profiles/{profile}.[next]/include/modules/hardcore/features/ # with the same content, try to find a place for that include file # which only depends on "current" or "next" mainline-configuration: changed = util.readTemplate( os.path.join(featuresDir, 'features_template.h'), os.path.join(targetDir, 'features.h'), HandleTemplateAction(feature_def)) or changed changed = util.readTemplate( os.path.join(featuresDir, 'features-thirdparty_attributions_template.inl'), os.path.join(targetDir, 'features-thirdparty_attributions.inl'), LegalTemplateActionHandler(feature_def)) or changed # TODO: instead of creating profile_XXX.h for all profiles XXX in # opera/profile/{profile}.[next]/include/modules/hardcore/features/, # only create profile_{profile}.h for the one profile that is # needed: for profile in util.PROFILES: changed = util.readTemplate( os.path.join(featuresDir, 'profile_template.h'), os.path.join(targetDir, 'profile_%s.h' % profile), ProfileTemplateActionHandler( profile, feature_def.featuresWithDefault())) or changed if targetDir == featuresDir: util.updateModuleGenerated(hardcoreDir, [ 'features/features.h', 'features/features-thirdparty_attributions.inl' ] + [ 'features/profile_%s.h' % profile for profile in util.PROFILES ]) # Ignore changes in setupinfo_features.cpp and documentation files: setupinfoDir = os.path.join(hardcoreDir, 'opera') documentationDir = os.path.join(hardcoreDir, 'documentation') if outputRoot is None: setupinfoOutputDir = setupInfoDir documentationOutputDir = documentationDir else: setupinfoOutputDir = os.path.join(outputRoot, 'modules', 'hardcore', 'opera') documentationOutputDir = os.path.join(outputRoot, 'modules', 'hardcore', 'documentation') # TODO: create a different output file # setupinfo_features.{core_version}.cpp for different # core-versions - note: this is only required if new features are # added or the documentation of a feature is changed. util.readTemplate( os.path.join(setupinfoDir, 'setupinfo_features_template.cpp'), os.path.join(setupinfoOutputDir, 'setupinfo_features_generated.inl'), HandleTemplateAction(feature_def), hardcoreDir if setupinfoDir == setupinfoOutputDir else None, 'opera/setupinfo_features.cpp') if feature_def.coreVersion() is None: features_xml = 'features.xml' else: features_xml = 'features.%s.xml' % feature_def.coreVersion() util.readTemplate( os.path.join(featuresDir, 'features_template.xml'), os.path.join(documentationOutputDir, features_xml), HandleTemplateAction(feature_def), hardcoreDir if documentationDir == documentationOutputDir else None, 'documentation/%s' % features_xml) if changed: result = 2 else: result = 0 return self.endTiming(result, sourceRoot=sourceRoot, outputRoot=outputRoot, quiet=quiet)
def __call__(self, sourceRoot, outputRoot=None, quiet=True, show_all=False): """ Calling this instance will generate the source files from all prefs .txt files. @param sourceRoot is the root directory of the source tree that was parsed. Some of the output files are always generated relative to the sourceRoot. @param outputRoot root of the tree for generated files, defaults to sourceRoot @param quiet if False, print some log messages about executing the perl script. @param show_all controls whether to show only modified files or all files which are inspected. Default is False. @return The convention of the "system-functions" are that the return value should be - 0 to indicate success - 1 to indicate an error - 2 to indicate that output files have changed. """ self.startTiming() if outputRoot == None: outputRoot = sourceRoot perl = self.findPerl(quiet) if perl is None: return self.endTiming(1, quiet=quiet) # Now perl should be the path to a perl executable # Scan for modules and prefs files and build the structure allfiles = [] changed = False for module, files in find_prefs_files(sourceRoot): modfiles = [] for filename in files: self.logmessage(quiet, "Creating prefs enum for %s" % (filename)) parser = PrefsCollectionParser() parser.parse("%s.txt" % filename) if not quiet: parser.printParserWarnings() if parser.printParserErrors(): return self.endTiming(1, quiet=quiet) handler = PrefsCollectionTemplateActionHandler( parser.header(), parser.items()) stem = os.path.relpath(filename, sourceRoot) outdir = os.path.dirname(os.path.join(outputRoot, stem)) basename = os.path.basename(filename) prefs_collection_dir = os.path.join("modules", "prefs", "prefsmanager", "collections") pc_template_h = os.path.join(sourceRoot, prefs_collection_dir, "pc_template.h") output_h = os.path.join(outdir, "%s_h.inl" % basename) changed = util.readTemplate(pc_template_h, output_h, handler) or changed pc_template_c = os.path.join(sourceRoot, prefs_collection_dir, "pc_template.cpp") output_c = os.path.join(outdir, "%s_c.inl" % basename) changed = util.readTemplate(pc_template_c, output_c, handler) or changed modfiles += [output_c, output_h] allfiles.append(stem) util.fileTracker.addInput( stem + ".cpp") # Will be used by extract-documentation.pl # List the generated files in module.generated if outputRoot == sourceRoot: util.updateModuleGenerated(module.fullPath(), modfiles) # Update documentation for f in ('modules/prefs/prefsmanager/opprefscollection.cpp', 'modules/prefs/prefsmanager/opprefscollection.h', 'modules/prefs/module.tweaks', 'modules/prefs/prefsmanager/collections/erasettings.h', 'modules/pi/OpSystemInfo.h'): util.fileTracker.addInput( f) # Will be used by extract-documentation.pl if changed: documentation_dir = os.path.join(sourceRoot, "modules", "prefs") documentation_output_dir = os.path.join(outputRoot, "modules", "prefs") documentation_path = os.path.join(documentation_dir, "extract-documentation.pl") util.makedirs( os.path.join(documentation_output_dir, "documentation")) self.logmessage(quiet, "calling script %s" % (documentation_path)) subprocess.call([perl, documentation_path, "-o", outputRoot] + allfiles, cwd=sourceRoot) if outputRoot == sourceRoot: util.updateModuleGenerated(documentation_output_dir, ["documentation/settings.html"]) if changed: result = 2 else: result = 0 return self.endTiming(result, quiet=quiet)
def generateTables(self): max_name_len = 0 name_map = {} normals = None specials = None type_filename = "" name_filename = "" file_name_suffix = "" has_changed = False if markup_debug: file_name_suffix = ".debug" # # Generate element tables # normals = self.elements specials = self.special_elements type_filename = self.type_file_pattern % ("element", "%s") name_filename = self.name_file_pattern % ("element", "%s") normals.sort() # Scan through the list to find duplicate names and # the length of the longest name for [name, ns, prefix] in normals: if not name in name_map: name_map[name] = [ns, prefix] if len(name) > max_name_len: max_name_len = len(name) type_template_file = os.path.join(self.template_file_path, type_filename % "_template") name_template_file = os.path.join(self.template_file_path, name_filename % "_template") type_out_file = os.path.join(self.out_file_path, type_filename % file_name_suffix) name_out_file = os.path.join(self.out_file_path, name_filename % file_name_suffix) logmessage("\nGenerating element type file:\n %s\nfrom template:\n %s\n" % (type_out_file, type_template_file)) if util.readTemplate(type_template_file, type_out_file, self.MarkupTypeTemplateAction(False, normals, specials, name_map, max_name_len)): has_changed = True logmessage("\nGenerating element name file:\n %s\nfrom template:\n %s\n" % (name_out_file, name_template_file)) if util.readTemplate(name_template_file, name_out_file, self.MarkupNameTemplateAction(False, normals, name_map, self.bigendian)): has_changed = True # # Generate attribute tables # name_map = {} normals = self.attributes specials = self.special_attributes type_filename = self.type_file_pattern % ("attr", "%s") name_filename = self.name_file_pattern % ("attr", "%s") normals.sort() # Scan through the list to find duplicate names and # the length of the longest name for [name, ns, prefix] in normals: if not name in name_map: name_map[name] = [ns, prefix] if len(name) > max_name_len: max_name_len = len(name) type_template_file = os.path.join(self.template_file_path, type_filename % "_template") name_template_file = os.path.join(self.template_file_path, name_filename % "_template") type_out_file = os.path.join(self.out_file_path, type_filename % file_name_suffix) name_out_file = os.path.join(self.out_file_path, name_filename % file_name_suffix) logmessage("\nGenerating attribute type file:\n %s\nfrom template:\n %s\n" % (type_out_file, type_template_file)) if util.readTemplate(type_template_file, type_out_file, self.MarkupTypeTemplateAction(True, normals, specials, name_map, max_name_len)): has_changed = True logmessage("\nGenerating attribute name file:\n %s\nfrom template:\n %s\n" % (name_out_file, name_template_file)) if util.readTemplate(name_template_file, name_out_file, self.MarkupNameTemplateAction(True, normals, name_map, self.bigendian)): has_changed = True return has_changed
def __call__(self, sourceRoot, outputRoot=None, quiet="yes"): self.startTiming() if outputRoot is None: outputRoot = sourceRoot # File names css_properties_txt = os.path.join(sourceRoot, "modules", "style", "src", "css_properties.txt") css_aliases_template_h = os.path.join(sourceRoot, "modules", "style", "src", "css_aliases_template.h") css_aliases_h = os.path.join(outputRoot, "modules", "style", "src", "css_aliases.h") css_property_strings_template_h = os.path.join(sourceRoot, "modules", "style", "src", "css_property_strings_template.h") css_property_strings_h = os.path.join(outputRoot, "modules", "style", "src", "css_property_strings.h") css_properties_template_h = os.path.join(sourceRoot, "modules", "style", "src", "css_properties_template.h") css_properties_h = os.path.join(outputRoot, "modules", "style", "src", "css_properties.h") css_properties_internal_txt = os.path.join(sourceRoot, "modules", "style", "src", "css_properties_internal.txt") atoms_txt = os.path.join(sourceRoot, "modules", "dom", "src", "atoms.txt") # Read the property names from css_properties.txt into a set, with # their aliases in a dictionary, and the properties which are not # aliases into another set properties = set([]) non_alias_properties = set([]) aliases = dict({}) try: f = None util.fileTracker.addInput(css_properties_txt) f = open(css_properties_txt) for line in f.read().split("\n"): if line: props = line.split(",") for p in props: p = p.strip() if p not in properties: properties.add(p) else: self.error("Error: css property '%s' declared multiple times." % p) return self.endTiming(1, quiet=quiet) name = props[0].strip() non_alias_properties.add(name) if len(props) >= 2: for a in props[1:]: a = a.strip() aliases.setdefault(name, []).append(a) finally: if f: f.close() sorted_properties = sorted(properties, cmp=sort_properties) # Read internal property names from css_propertiesi_internal.txt into a # set internal_properties = set([]) try: f = None util.fileTracker.addInput(css_properties_internal_txt) f = open(css_properties_internal_txt) for line in f.read().split("\n"): p = line.strip() if p: if p not in internal_properties and p not in properties: internal_properties.add(p) else: self.error("Error: css property '%s' declared multiple times." % p) return self.endTiming(1, quiet=quiet) finally: if f: f.close() sorted_internal_properties = sorted(internal_properties, cmp=sort_properties) # Regenerate css_properties.txt, with sorted non-alias properties each # followed by their alias to css_properties.txt,: output = StringIO.StringIO() for p in sorted(non_alias_properties, cmp=sort_properties): if p in aliases: output.write("%s, %s\n" % (p, ", ".join(sorted(aliases[p]))) ) else: output.write("%s\n" % p) changed = util.updateFile(output, css_properties_txt) # Create css_aliases.h from its template: changed = util.readTemplate(css_aliases_template_h, css_aliases_h, CssAliasesTemplateActionHandler(aliases)) or changed # Create css_property_strings.h from its template: changed = util.readTemplate(css_property_strings_template_h, css_property_strings_h, PropertyStringsTemplateActionHandler(sorted_properties)) or changed # Create css_properties.h from its template: changed = util.readTemplate(css_properties_template_h, css_properties_h, PropertiesTemplateActionHandler(sorted_properties, sorted_internal_properties)) or changed # Check that all properties are mCheck that all properties are in used # the atoms.txt file in dom as well. try: f = None util.fileTracker.addInput(atoms_txt) f = open(atoms_txt, "r") atoms = f.read().lower() for p in properties: if re.sub("-", "", p.lower()) not in atoms: self.error("Warning: %s is missing from modules/dom/src/atoms.txt" % p) finally: if f: f.close() if changed: result = 2 else: result = 0 return self.endTiming(result, quiet=quiet)
if module_sources.cpp(source_file): extension = "cpp" original_filename = sourcename[6:] + "." + extension else: extension = "c" filename = "opera_" + sourcename + ".cpp" file_path[-1] = filename; options = module_sources.getSourceOptionString(source_file) if len(options) == 0: module_sources_out.write("%s\n" % '/'.join(file_path)) else: module_sources_out.write("%s # [%s]\n" % ('/'.join(file_path).ljust(34), options)) if util.readTemplate(wrapper_template, os.path.join(libopeayDir, *file_path), HandleTemplateAction(extension=="cpp", module_sources, source_file, "/".join(file_path[0:-1] + [original_filename]))): changed_files.append(os.path.join(*file_path)) if util.updateFile(module_sources_out, os.path.join(libopeayDir, "module.sources")): print "module.sources updated" else: print "module.sources not changed" if len(changed_files): print "%d wrapper files updated:" % len(changed_files), changed_files else: print "No wrapper file changed"