# HG changeset patch
# User Mike Shal <mshal@mozilla.com>
# Date 1525899199 14400
# Node ID 82c74467f638711b16996f2a0dca28a597f32a0d
# Parent  4dbe6c1bea4db5f0ae77a3487328c32ec240a5d7
Bug 1454912 - Only output dependencies for GENERATED_FILES with scripts; r=nalexander

Some GENERATED_FILES entries don't have .scripts associated with them
(notably midl on Windows builds). In this case, we don't want to
generate dependencies automatically since they will be handled by the
Makefiles.

MozReview-Commit-ID: AXmN2Unk9AY

diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py
--- a/python/mozbuild/mozbuild/backend/recursivemake.py
+++ b/python/mozbuild/mozbuild/backend/recursivemake.py
@@ -562,38 +562,38 @@ class RecursiveMakeBackend(CommonBackend
                 else:
                     inputs = [self._pretty_path(f, backend_file) for f in obj.inputs]
             else:
                 inputs = []
 
             if needs_AB_rCD:
                 backend_file.write_once('include $(topsrcdir)/config/AB_rCD.mk\n')
 
-            # If we're doing this during export that means we need it during
-            # compile, but if we have an artifact build we don't run compile,
-            # so we can skip it altogether or let the rule run as the result of
-            # something depending on it.
-            if tier != 'export' or not self.environment.is_artifact_build:
-                if not needs_AB_rCD:
-                    # Android localized resources have special Makefile
-                    # handling.
-                    backend_file.write('%s:: %s\n' % (tier, first_output))
-            for output in outputs:
-                if output != first_output:
-                    backend_file.write('%s: %s ;\n' % (output, first_output))
-                backend_file.write('GARBAGE += %s\n' % output)
-            backend_file.write('EXTRA_MDDEPEND_FILES += %s\n' % dep_file)
-
             force = ''
             if obj.force:
                 force = ' FORCE'
             elif obj.localized:
                 force = ' $(if $(IS_LANGUAGE_REPACK),FORCE)'
 
             if obj.script:
+                # If we're doing this during export that means we need it during
+                # compile, but if we have an artifact build we don't run compile,
+                # so we can skip it altogether or let the rule run as the result of
+                # something depending on it.
+                if tier != 'export' or not self.environment.is_artifact_build:
+                    if not needs_AB_rCD:
+                        # Android localized resources have special Makefile
+                        # handling.
+                        backend_file.write('%s:: %s\n' % (tier, first_output))
+                for output in outputs:
+                    if output != first_output:
+                        backend_file.write('%s: %s ;\n' % (output, first_output))
+                    backend_file.write('GARBAGE += %s\n' % output)
+                backend_file.write('EXTRA_MDDEPEND_FILES += %s\n' % dep_file)
+
                 backend_file.write("""{output}: {script}{inputs}{backend}{force}
 \t$(REPORT_BUILD)
 \t$(call py_action,file_generate,{locale}{script} {method} {output} $(MDDEPDIR)/{dep_file}{inputs}{flags})
 
 """.format(output=first_output,
            dep_file=dep_file,
            inputs=' ' + ' '.join(inputs) if inputs else '',
            flags=' ' + ' '.join(shell_quote(f) for f in obj.flags) if obj.flags else '',
diff --git a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
--- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
+++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
@@ -405,19 +405,16 @@ class TestRecursiveMakeBackend(BackendTe
             '',
             'export:: foo.c',
             'GARBAGE += foo.c',
             'EXTRA_MDDEPEND_FILES += foo.c.pp',
             'foo.c: %s/generate-foo.py $(srcdir)/foo-data' % (env.topsrcdir),
             '$(REPORT_BUILD)',
             '$(call py_action,file_generate,%s/generate-foo.py main foo.c $(MDDEPDIR)/foo.c.pp $(srcdir)/foo-data)' % (env.topsrcdir),
             '',
-            'export:: quux.c',
-            'GARBAGE += quux.c',
-            'EXTRA_MDDEPEND_FILES += quux.c.pp',
         ]
 
         self.maxDiff = None
         self.assertEqual(lines, expected)
 
     def test_generated_files_force(self):
         """Ensure GENERATED_FILES with .force is handled properly."""
         env = self._consume('generated-files-force', RecursiveMakeBackend)
@@ -435,19 +432,16 @@ class TestRecursiveMakeBackend(BackendTe
             '',
             'export:: foo.c',
             'GARBAGE += foo.c',
             'EXTRA_MDDEPEND_FILES += foo.c.pp',
             'foo.c: %s/generate-foo.py $(srcdir)/foo-data' % (env.topsrcdir),
             '$(REPORT_BUILD)',
             '$(call py_action,file_generate,%s/generate-foo.py main foo.c $(MDDEPDIR)/foo.c.pp $(srcdir)/foo-data)' % (env.topsrcdir),
             '',
-            'export:: quux.c',
-            'GARBAGE += quux.c',
-            'EXTRA_MDDEPEND_FILES += quux.c.pp',
         ]
 
         self.maxDiff = None
         self.assertEqual(lines, expected)
 
     def test_localized_generated_files(self):
         """Ensure LOCALIZED_GENERATED_FILES is handled properly."""
         env = self._consume('localized-generated-files', RecursiveMakeBackend)
@@ -544,28 +538,16 @@ class TestRecursiveMakeBackend(BackendTe
         self.assertIn('mozilla/mozilla2.h', m)
         self.assertIn('mozilla/dom/dom2.h', m)
         self.assertIn('mozilla/dom/dom3.h', m)
         # EXPORTS files that are also GENERATED_FILES should be handled as
         # INSTALL_TARGETS.
         backend_path = mozpath.join(env.topobjdir, 'backend.mk')
         lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]]
         expected = [
-            'export:: bar.h',
-            'GARBAGE += bar.h',
-            'EXTRA_MDDEPEND_FILES += bar.h.pp',
-            'export:: mozilla2.h',
-            'GARBAGE += mozilla2.h',
-            'EXTRA_MDDEPEND_FILES += mozilla2.h.pp',
-            'export:: dom2.h',
-            'GARBAGE += dom2.h',
-            'EXTRA_MDDEPEND_FILES += dom2.h.pp',
-            'export:: dom3.h',
-            'GARBAGE += dom3.h',
-            'EXTRA_MDDEPEND_FILES += dom3.h.pp',
             'dist_include_FILES += bar.h',
             'dist_include_DEST := $(DEPTH)/dist/include/',
             'dist_include_TARGET := export',
             'INSTALL_TARGETS += dist_include',
             'dist_include_mozilla_FILES += mozilla2.h',
             'dist_include_mozilla_DEST := $(DEPTH)/dist/include/mozilla',
             'dist_include_mozilla_TARGET := export',
             'INSTALL_TARGETS += dist_include_mozilla',
