Bug 1297013 part.2 Implement some helper methods to log constants related to event handling r=smaug
This patch implements some helper methods to log constants related to event handling.
ToString(KeyNameIndex) and ToString(CodeNameIndex) converts the enum itmes to human readable string. They use WidgetKeyboardEvent's helper class which returns Unicode text. Therefore, this need to convert from UTF16 to UTF8. That's the reason why these methods don't return |const char*|.
GetDOMKeyCodeName(uint32_t) returns DOM keycode name if it's defined. Otherwise, returns hexadecimal value. For generating switch-case statement, VirtualKeyCodeList.h shouldn't include ",". Therefore, this patch removes "," from VirtualKeyCodeList.h and append it at defining NS_DEFINE_VK. Additionally, the last item of enum and array should not end with ",". Therefore, this adds dummy last item at each of them. Finally, some of the keyCode values are shared between 2 keys. Therefore, it needs to support NS_DISALLOW_SAME_KEYCODE for switch-case generator. See the comment in the file for more detail.
GetModifiersName(Modifiers) returns all modifier names included in the given value.
MozReview-Commit-ID: 9i2ftFOTpDn

# -*- coding: utf-8 -*-# This Source Code Form is subject to the terms of the Mozilla Public# License, v. 2.0. If a copy of the MPL was not distributed with this# file, You can obtain one at http://mozilla.org/MPL/2.0/.from__future__importabsolute_import,print_function,unicode_literalsimportjsonimportloggingimportsysimporttracebackfrommach.decoratorsimport(CommandArgument,CommandProvider,Command,SubCommand,)frommozbuild.baseimportMachCommandBaseARTIFACT_URL='https://queue.taskcluster.net/v1/task/{}/artifacts/{}'classShowTaskGraphSubCommand(SubCommand):"""A SubCommand with TaskGraph-specific arguments"""def__call__(self,func):after=SubCommand.__call__(self,func)args=[CommandArgument('--root','-r',default='taskcluster/ci',help="root of the taskgraph definition relative to topsrcdir"),CommandArgument('--quiet','-q',action="store_true",help="suppress all logging output"),CommandArgument('--verbose','-v',action="store_true",help="include debug-level logging output"),CommandArgument('--json','-J',action="store_const",dest="format",const="json",help="Output task graph as a JSON object"),CommandArgument('--labels','-L',action="store_const",dest="format",const="labels",help="Output the label for each task in the task graph (default)"),CommandArgument('--parameters','-p',required=True,help="parameters file (.yml or .json; see ""`taskcluster/docs/parameters.rst`)`"),CommandArgument('--no-optimize',dest="optimize",action="store_false",default="true",help="do not remove tasks from the graph that are found in the ""index (a.k.a. optimize the graph)"),]forarginargs:after=arg(after)returnafter@CommandProviderclassMachCommands(MachCommandBase):@Command('taskgraph',category="ci",description="Manipulate TaskCluster task graphs defined in-tree")deftaskgraph(self):"""The taskgraph subcommands all relate to the generation of task graphs for Gecko continuous integration. A task graph is a set of tasks linked by dependencies: for example, a binary must be built before it is tested, and that build may further depend on various toolchains, libraries, etc. """@SubCommand('taskgraph','python-tests',description='Run the taskgraph unit tests')deftaskgraph_python_tests(self,**options):importunittestimportmozunitsuite=unittest.defaultTestLoader.discover('taskgraph.test')runner=mozunit.MozTestRunner(verbosity=2)result=runner.run(suite)ifnotresult.wasSuccessful():sys.exit(1)@ShowTaskGraphSubCommand('taskgraph','tasks',description="Show all tasks in the taskgraph")deftaskgraph_tasks(self,**options):returnself.show_taskgraph('full_task_set',options)@ShowTaskGraphSubCommand('taskgraph','full',description="Show the full taskgraph")deftaskgraph_full(self,**options):returnself.show_taskgraph('full_task_graph',options)@ShowTaskGraphSubCommand('taskgraph','target',description="Show the target task set")deftaskgraph_target(self,**options):returnself.show_taskgraph('target_task_set',options)@ShowTaskGraphSubCommand('taskgraph','target-graph',description="Show the target taskgraph")deftaskgraph_target_taskgraph(self,**options):returnself.show_taskgraph('target_task_graph',options)@ShowTaskGraphSubCommand('taskgraph','optimized',description="Show the optimized taskgraph")deftaskgraph_optimized(self,**options):returnself.show_taskgraph('optimized_task_graph',options)@SubCommand('taskgraph','decision',description="Run the decision task")@CommandArgument('--root','-r',default='taskcluster/ci',help="root of the taskgraph definition relative to topsrcdir")@CommandArgument('--base-repository',required=True,help='URL for "base" repository to clone')@CommandArgument('--head-repository',required=True,help='URL for "head" repository to fetch revision from')@CommandArgument('--head-ref',required=True,help='Reference (this is same as rev usually for hg)')@CommandArgument('--head-rev',required=True,help='Commit revision to use from head repository')@CommandArgument('--message',required=True,help='Commit message to be parsed. Example: "try: -b do -p all -u all"')@CommandArgument('--revision-hash',required=True,help='Treeherder revision hash (long revision id) to attach results to')@CommandArgument('--project',required=True,help='Project to use for creating task graph. Example: --project=try')@CommandArgument('--pushlog-id',dest='pushlog_id',required=True,default=0)@CommandArgument('--pushdate',dest='pushdate',required=True,type=int,default=0)@CommandArgument('--owner',required=True,help='email address of who owns this graph')@CommandArgument('--level',required=True,help='SCM level of this repository')@CommandArgument('--triggered-by',choices=['nightly','push'],default='push',help='Source of execution of the decision graph')@CommandArgument('--target-tasks-method',help='method for selecting the target tasks to generate')deftaskgraph_decision(self,**options):"""Run the decision task: generate a task graph and submit to TaskCluster. This is only meant to be called within decision tasks, and requires a great many arguments. Commands like `mach taskgraph optimized` are better suited to use on the command line, and can take the parameters file generated by a decision task. """importtaskgraph.decisiontry:self.setup_logging()returntaskgraph.decision.taskgraph_decision(options)exceptException:traceback.print_exc()sys.exit(1)@SubCommand('taskgraph','action-task',description="Run the action task")@CommandArgument('--root','-r',default='taskcluster/ci',help="root of the taskgraph definition relative to topsrcdir")@CommandArgument('--decision-id',required=True,help="Decision Task ID of the reference decision task")@CommandArgument('--task-labels',required=True,help='Comma separated list of task labels to be scheduled')deftaskgraph_action(self,**options):"""Run the action task: Generates a task graph using the set of labels provided in the task-labels parameter. It uses the full-task file of the gecko decision task."""importtaskgraph.actiontry:self.setup_logging()returntaskgraph.action.taskgraph_action(options)exceptException:traceback.print_exc()sys.exit(1)defsetup_logging(self,quiet=False,verbose=True):""" Set up Python logging for all loggers, sending results to stderr (so that command output can be redirected easily) and adding the typical mach timestamp. """# remove the old terminal handlerold=self.log_manager.replace_terminal_handler(None)# re-add it, with level and fh set appropriatelyifnotquiet:level=logging.DEBUGifverboseelselogging.INFOself.log_manager.add_terminal_logging(fh=sys.stderr,level=level,write_interval=old.formatter.write_interval,write_times=old.formatter.write_times)# all of the taskgraph logging is unstructured loggingself.log_manager.enable_unstructured()defshow_taskgraph(self,graph_attr,options):importtaskgraph.parametersimporttaskgraph.target_tasksimporttaskgraph.generatortry:self.setup_logging(quiet=options['quiet'],verbose=options['verbose'])parameters=taskgraph.parameters.load_parameters_file(options)target_tasks_method=parameters.get('target_tasks_method','all_tasks')target_tasks_method=taskgraph.target_tasks.get_method(target_tasks_method)tgg=taskgraph.generator.TaskGraphGenerator(root_dir=options['root'],parameters=parameters,target_tasks_method=target_tasks_method)tg=getattr(tgg,graph_attr)show_method=getattr(self,'show_taskgraph_'+(options['format']or'labels'))show_method(tg)exceptException:traceback.print_exc()sys.exit(1)defshow_taskgraph_labels(self,taskgraph):forlabelintaskgraph.graph.visit_postorder():print(label)defshow_taskgraph_json(self,taskgraph):print(json.dumps(taskgraph.to_json(),sort_keys=True,indent=2,separators=(',',': ')))@CommandProviderclassTaskClusterImagesProvider(object):@Command('taskcluster-load-image',category="ci",description="Load a pre-built Docker image")@CommandArgument('--task-id',help="Load the image at public/image.tar in this task,""rather than searching the index")@CommandArgument('image_name',nargs='?',help="Load the image of this name based on the current""contents of the tree (as built for mozilla-central""or mozilla-inbound)")defload_image(self,image_name,task_id):fromtaskgraph.dockerimportload_image_by_name,load_image_by_task_idifnotimage_nameandnottask_id:print("Specify either IMAGE-NAME or TASK-ID")sys.exit(1)try:iftask_id:ok=load_image_by_task_id(task_id)else:ok=load_image_by_name(image_name)ifnotok:sys.exit(1)exceptException:traceback.print_exc()sys.exit(1)@Command('taskcluster-build-image',category='ci',description='Build a Docker image')@CommandArgument('image_name',help='Name of the image to build')defbuild_image(self,image_name):fromtaskgraph.dockerimportbuild_imagetry:build_image(image_name)exceptException:traceback.print_exc()sys.exit(1)