From e51afbcc2fe7360bbcf5654f6e31752c48098ca0 Mon Sep 17 00:00:00 2001 From: athenian200 Date: Fri, 4 Oct 2019 02:59:26 -0500 Subject: 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 "" --include="" find -name '' | xargs grep -E "" And arranged it all accordingly to the best of my ability, though I should point out that Python is not my strong suit. --- python/mozbuild/mozbuild/mach_commands.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'python') 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) -- cgit v1.2.3