summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorathenian200 <athenian200@outlook.com>2019-10-04 02:59:26 -0500
committerathenian200 <athenian200@outlook.com>2019-10-21 04:53:42 -0500
commit1faa786476c508628af9e7fbaefb1e3b8270f22c (patch)
treec538455ae1ca6e4cba2e33d57d0dd5658fac1abf
parent7d1bea31d8c18e1d9cc7d03d94f255fd8c2cdabe (diff)
downloadaura-central-1faa786476c508628af9e7fbaefb1e3b8270f22c.tar.gz
MoonchildProductions%1251 - Part 19: Make the unpreprocessed file script work on Solaris.
https://www.tachytelic.net/2019/01/grep-recursively/ During testing, I tried simply replacing grep with ggrep, which was non-portable but worked fine. Using an environment variable with os.getenv set to 'g' also worked, but the problem with that approach is that you have to set it manually and some times the script will mess up if you don't explictly define it to an empty string for platforms that don't need it. Setting TOOLCHAIN_PREFIX to 'g' seemed to solve all of my problems except this one, and it appears to be the only non-portable use of GNU grep in the whole tree. To understand what I tried to do here, let me present with you with two commands that yield the same output on my machine: find . -name '*.xul' | xargs grep -E "%include" ggrep -E -r "%include" --include="*.xul" . I just tried to make the Python script follow the logic of those two commands, though I'm not sure how well I succeeded since I got no errors. I visualized everything this way: ggrep -E -r "<strings>" --include="<filesuffixes>" <path> find <path> -name '<filesuffixes>' | xargs grep -E "<strings>" And arranged it all accordingly to the best of my ability, though I should point out that Python is not my strong suit.
-rw-r--r--python/mozbuild/mozbuild/mach_commands.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py
index a45656b37..c2e1a3e89 100644
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -544,9 +544,14 @@ class Build(MachCommandBase):
# Check if there are any unpreprocessed files in '@MOZ_OBJDIR@/dist/bin'
# See python/mozbuild/mozbuild/preprocessor.py#L293-L309 for the list of directives
# We skip if, ifdef, ifndef, else, elif, elifdef and elifndef, because they are never used alone
- grepcmd = 'grep -E -r "^(#|%)(define|endif|error|expand|filter|include|literal|undef|unfilter)" '\
- + '--include=\*.{css,dtd,html,js,jsm,xhtml,xml,xul,manifest,properties,rdf} '\
- + self.topobjdir + '/dist/bin | awk "/\.css:%/ || (!/\.css/ && /:#/)"'
+ #
+ # The original version of this script only worked with GNU grep because of the --include flag.
+ # Not a problem in and of itself, except that it didn't take TOOLCHAIN_PREFIX and simply assumed
+ # all operating systems use GNU grep as the system grep (often it's called ggrep or something).
+ # This script is a bit slower, but should do the same thing on all Unix platforms.
+
+ grepcmd = 'find ' + self.topobjdir + '/dist/bin' + ' -name \'\*.{css,dtd,html,js,jsm,xhtml,xml,xul,manifest,properties,rdf}\' ' + '| xargs grep -E "^(#|%)(define|endif|error|expand|filter|include|literal|undef|unfilter)" '\
+ + '| awk "/\.css:%/ || (!/\.css/ && /:#/)"'
grepresult = subprocess.Popen(grepcmd, stdout=subprocess.PIPE, shell=True).communicate()[0]
if grepresult:
print('\nERROR: preprocessor was not applied to the following files:\n\n' + grepresult)