mach_commands.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, # You can obtain one at http://mozilla.org/MPL/2.0/.
  4. from __future__ import absolute_import, unicode_literals
  5. import os
  6. import sys
  7. from mach.decorators import (
  8. CommandArgument,
  9. CommandProvider,
  10. Command,
  11. )
  12. from mozbuild.base import MachCommandBase
  13. def get_test_parser():
  14. import runtests
  15. return runtests.get_parser
  16. @CommandProvider
  17. class WebIDLProvider(MachCommandBase):
  18. @Command('webidl-example', category='misc',
  19. description='Generate example files for a WebIDL interface.')
  20. @CommandArgument('interface', nargs='+',
  21. help='Interface(s) whose examples to generate.')
  22. def webidl_example(self, interface):
  23. from mozwebidlcodegen import BuildSystemWebIDL
  24. manager = self._spawn(BuildSystemWebIDL).manager
  25. for i in interface:
  26. manager.generate_example_files(i)
  27. @Command('webidl-parser-test', category='testing', parser=get_test_parser,
  28. description='Run WebIDL tests (Interface Browser parser).')
  29. def webidl_test(self, **kwargs):
  30. sys.path.insert(0, os.path.join(self.topsrcdir, 'other-licenses',
  31. 'ply'))
  32. # Make sure we drop our cached grammar bits in the objdir, not
  33. # wherever we happen to be running from.
  34. os.chdir(self.topobjdir)
  35. if kwargs["verbose"] is None:
  36. kwargs["verbose"] = False
  37. # Now we're going to create the cached grammar file in the
  38. # objdir. But we're going to try loading it as a python
  39. # module, so we need to make sure the objdir is in our search
  40. # path.
  41. sys.path.insert(0, self.topobjdir)
  42. import runtests
  43. return runtests.run_tests(kwargs["tests"], verbose=kwargs["verbose"])