From 27943c0ea57381d32a29874bf4ae7509440de45a Mon Sep 17 00:00:00 2001 From: Dhananjay Nakrani Date: Sat, 25 Apr 2015 10:03:14 -0700 Subject: [PATCH 1/2] Add a './mach grep' command. [Issue #5838] --- python/servo/devenv_commands.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/servo/devenv_commands.py b/python/servo/devenv_commands.py index 7caac6e33bd..770c5273397 100644 --- a/python/servo/devenv_commands.py +++ b/python/servo/devenv_commands.py @@ -76,3 +76,16 @@ class MachCommands(CommandBase): category='devenv') def rust_root(self): 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 = [] + grep_paths = [path.join(self.context.topdir, 'components'), + path.join(self.context.topdir, 'ports')] + return subprocess.call(["git"] + ["grep"] + params + ['--'] + grep_paths, env=self.build_env()) From bed9fc101bba666cfa2292a5e9c584f3cd914587 Mon Sep 17 00:00:00 2001 From: Dhananjay Nakrani Date: Sat, 25 Apr 2015 10:33:53 -0700 Subject: [PATCH 2/2] Add more directories into './mach grep' command. --- python/servo/devenv_commands.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/python/servo/devenv_commands.py b/python/servo/devenv_commands.py index 770c5273397..1f9456b0866 100644 --- a/python/servo/devenv_commands.py +++ b/python/servo/devenv_commands.py @@ -1,5 +1,5 @@ from __future__ import print_function, unicode_literals -from os import path, getcwd +from os import path, getcwd, listdir import subprocess @@ -86,6 +86,15 @@ class MachCommands(CommandBase): def grep(self, params): if not params: params = [] - grep_paths = [path.join(self.context.topdir, 'components'), - path.join(self.context.topdir, 'ports')] + # 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())