# HG changeset patch
# User Nathan Froyd <froydnj@mozilla.com>
# Date 1591734204 0
# Node ID a9239d02662726ebc80e3c0b02213b32795feaf4
# Parent  fba4303d6219d355e1a767727f308a80328ef2b9
Bug 1642032 - part 1 - factor out install targets for final target files; r=nalexander

We're going to reuse this machinery in a subsequent patch.  I think this
change, by virtue of moving all the output to a single place, also makes
things clearer.

Differential Revision: https://phabricator.services.mozilla.com/D78617

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
@@ -1421,16 +1421,24 @@ class RecursiveMakeBackend(CommonBackend
         assert len(direct_linked) == 1
 
         # TODO: see bug 1310063 for checking dependencies are set up correctly.
 
         direct_linked = direct_linked[0]
         backend_file.write('RUST_STATIC_LIB_FOR_SHARED_LIB := %s\n' %
                            pretty_relpath(direct_linked, direct_linked.import_name))
 
+    def _add_install_target(self, backend_file, install_target, tier, dest, files):
+        self._no_skip[tier].add(backend_file.relobjdir)
+        for f in files:
+            backend_file.write('%s_FILES += %s\n' % (install_target, f))
+        backend_file.write('%s_DEST := %s\n' % (install_target, dest))
+        backend_file.write('%s_TARGET := %s\n' % (install_target, tier))
+        backend_file.write('INSTALL_TARGETS += %s\n' % install_target)
+
     def _process_final_target_files(self, obj, files, backend_file):
         target = obj.install_target
         path = mozpath.basedir(target, (
             'dist/bin',
             'dist/xpi-stage',
             '_tests',
             'dist/include',
         ))
@@ -1443,17 +1451,18 @@ class RecursiveMakeBackend(CommonBackend
 
         manifest = path.replace('/', '_')
         install_manifest = self._install_manifests[manifest]
         reltarget = mozpath.relpath(target, path)
 
         for path, files in files.walk():
             target_var = (mozpath.join(target, path)
                           if path else target).replace('/', '_')
-            have_objdir_files = False
+            objdir_files = []
+
             for f in files:
                 assert not isinstance(f, RenamedSourcePath)
                 dest = mozpath.join(reltarget, path, f.target_basename)
                 if not isinstance(f, ObjDirPath):
                     if '*' in f:
                         if f.startswith('/') or isinstance(f, AbsolutePath):
                             basepath, wild = os.path.split(f.full_path)
                             if '*' in basepath:
@@ -1462,27 +1471,22 @@ class RecursiveMakeBackend(CommonBackend
 
                             install_manifest.add_pattern_link(basepath, wild, path)
                         else:
                             install_manifest.add_pattern_link(f.srcdir, f, path)
                     else:
                         install_manifest.add_link(f.full_path, dest)
                 else:
                     install_manifest.add_optional_exists(dest)
-                    backend_file.write('%s_FILES += %s\n' % (
-                        target_var, self._pretty_path(f, backend_file)))
-                    have_objdir_files = True
-            if have_objdir_files:
+                    objdir_files.append(self._pretty_path(f, backend_file))
+            if objdir_files:
                 tier = 'export' if obj.install_target == 'dist/include' else 'misc'
-                self._no_skip[tier].add(backend_file.relobjdir)
-                backend_file.write('%s_DEST := $(DEPTH)/%s\n'
-                                   % (target_var,
-                                      mozpath.join(target, path)))
-                backend_file.write('%s_TARGET := %s\n' % (target_var, tier))
-                backend_file.write('INSTALL_TARGETS += %s\n' % target_var)
+                self._add_install_target(backend_file, target_var, tier,
+                                         '$(DEPTH)/%s' % mozpath.join(target, path),
+                                         objdir_files)
 
     def _process_final_target_pp_files(self, obj, files, backend_file, name):
         # Bug 1177710 - We'd like to install these via manifests as
         # preprocessed files. But they currently depend on non-standard flags
         # being added via some Makefiles, so for now we just pass them through
         # to the underlying Makefile.in.
         #
         # Note that if this becomes a manifest, OBJDIR_PP_FILES will likely
