servo: Merge #5842 - Add a ./mach grep command (from dhananjay92:i5838); r=Manishearth
Solves Issue #5838. Source-Repo: https://github.com/servo/servo Source-Revision: ef536372cdf26e5fd2ac7728e76482dc5d702cd0
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
from os import path, getcwd
|
from os import path, getcwd, listdir
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@@ -76,3 +76,25 @@ class MachCommands(CommandBase):
|
|||||||
category='devenv')
|
category='devenv')
|
||||||
def rust_root(self):
|
def rust_root(self):
|
||||||
print(self.config["tools"]["rust-root"])
|
print(self.config["tools"]["rust-root"])
|
||||||
|
|
||||||
|
@Command('grep',
|
||||||
|
description='`git grep` for selected directories.',
|
||||||
|
category='devenv')
|
||||||
|
@CommandArgument(
|
||||||
|
'params', default=None, nargs='...',
|
||||||
|
help="Command-line arguments to be passed through to `git grep`")
|
||||||
|
def grep(self, params):
|
||||||
|
if not params:
|
||||||
|
params = []
|
||||||
|
# get all directories under tests/
|
||||||
|
tests_dirs = listdir('tests')
|
||||||
|
# Remove 'wpt' from obtained dir list
|
||||||
|
tests_dirs = filter(lambda dir: dir != 'wpt', tests_dirs)
|
||||||
|
# Set of directories in project root
|
||||||
|
root_dirs = ['components', 'ports', 'python', 'etc', 'resources']
|
||||||
|
# Generate absolute paths for directories in tests/ and project-root/
|
||||||
|
tests_dirs_abs = [path.join(self.context.topdir, 'tests', s) for s in tests_dirs]
|
||||||
|
root_dirs_abs = [path.join(self.context.topdir, s) for s in root_dirs]
|
||||||
|
# Absolute paths for all directories to be considered
|
||||||
|
grep_paths = root_dirs_abs + tests_dirs_abs
|
||||||
|
return subprocess.call(["git"] + ["grep"] + params + ['--'] + grep_paths, env=self.build_env())
|
||||||
|
|||||||
Reference in New Issue
Block a user