Bug 1451521 - Generate built_in_addons.json in the Tup backend. draft
authorChris Manchester <cmanchester@mozilla.com>
Fri, 06 Apr 2018 14:38:05 -0700
changeset 778810 9c54345696c5e9fd41958ea569e88a200e83aa01
parent 778809 8281a630145e4340089039b712685290b60243a7
push id105583
push userbmo:cmanchester@mozilla.com
push dateFri, 06 Apr 2018 21:38:16 +0000
bugs1451521
milestone61.0a1
Bug 1451521 - Generate built_in_addons.json in the Tup backend. MozReview-Commit-ID: LdYtRMopfJM
python/mozbuild/mozbuild/backend/tup.py
--- a/python/mozbuild/mozbuild/backend/tup.py
+++ b/python/mozbuild/mozbuild/backend/tup.py
@@ -1,15 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, unicode_literals
 
 import os
+import json
 import sys
 
 import mozpack.path as mozpath
 from mozbuild.base import MozbuildObject
 from mozbuild.backend.base import PartialBackend, HybridBackend
 from mozbuild.backend.recursivemake import RecursiveMakeBackend
 from mozbuild.shellutil import quote as shell_quote
 from mozbuild.util import OrderedDefaultDict
@@ -199,16 +200,19 @@ class TupOnly(CommonBackend, PartialBack
         # will be built before any rules that list this as an input.
         self._installed_idls = '$(MOZ_OBJ_ROOT)/<installed-idls>'
         self._installed_files = '$(MOZ_OBJ_ROOT)/<installed-files>'
         # The preprocessor including source-repo.h and buildid.h creates
         # dependencies that aren't specified by moz.build and cause errors
         # in Tup. Express these as a group dependency.
         self._early_generated_files = '$(MOZ_OBJ_ROOT)/<early-generated-files>'
 
+        self._built_in_addons = set()
+        self._built_in_addons_file = 'dist/bin/browser/chrome/browser/content/browser/built_in_addons.json'
+
         # application.ini.h is a special case since we need to process
         # the FINAL_TARGET_PP_FILES for application.ini before running
         # the GENERATED_FILES script, and tup doesn't handle the rules
         # out of order. Similarly, dependentlibs.list uses libxul as
         # an input, so must be written after the rule for libxul.
         self._delayed_files = (
             'application.ini.h',
             'dependentlibs.list',
@@ -437,16 +441,21 @@ class TupOnly(CommonBackend, PartialBack
 
         # The approach here is similar to fastermake.py, but we
         # simply write out the resulting files here.
         for target, entries in self._manifest_entries.iteritems():
             with self._write_file(mozpath.join(self.environment.topobjdir,
                                                target)) as fh:
                 fh.write(''.join('%s\n' % e for e in sorted(entries)))
 
+        if self._built_in_addons:
+            with self._write_file(mozpath.join(self.environment.topobjdir,
+                                               self._built_in_addons_file)) as fh:
+                json.dump({'system': sorted(list(self._built_in_addons))}, fh)
+
         for objdir, backend_file in sorted(self._backend_files.items()):
             backend_file.gen_sources_rules([self._installed_files])
             for condition, gen_method in ((backend_file.shared_lib, self._gen_shared_library),
                                           (backend_file.static_lib and backend_file.static_lib.no_expand_lib,
                                            self._gen_static_library),
                                           (backend_file.program, self._gen_program)):
                 if condition:
                     backend_file.export_shell()
@@ -540,16 +549,22 @@ class TupOnly(CommonBackend, PartialBack
     def _process_defines(self, backend_file, obj, host=False):
         defines = list(obj.get_defines())
         if defines:
             if host:
                 backend_file.host_defines = defines
             else:
                 backend_file.defines = defines
 
+    def _add_features(self, target, path):
+        path_parts = mozpath.split(path)
+        if all([target == 'dist/bin/browser', path_parts[0] == 'features',
+                len(path_parts) > 1]):
+            self._built_in_addons.add(path_parts[1])
+
     def _process_final_target_files(self, obj):
         target = obj.install_target
         if not isinstance(obj, ObjdirFiles):
             path = mozpath.basedir(target, (
                 'dist/bin',
                 'dist/xpi-stage',
                 '_tests',
                 'dist/include',
@@ -559,16 +574,17 @@ class TupOnly(CommonBackend, PartialBack
                 raise Exception("Cannot install to " + target)
 
         if target.startswith('_tests'):
             # TODO: TEST_HARNESS_FILES present a few challenges for the tup
             # backend (bug 1372381).
             return
 
         for path, files in obj.files.walk():
+            self._add_features(target, path)
             for f in files:
                 if not isinstance(f, ObjDirPath):
                     backend_file = self._get_backend_file(mozpath.join(target, path))
                     if '*' in f:
                         if f.startswith('/') or isinstance(f, AbsolutePath):
                             basepath, wild = os.path.split(f.full_path)
                             if '*' in basepath:
                                 raise Exception("Wildcards are only supported in the filename part of "
@@ -610,16 +626,17 @@ class TupOnly(CommonBackend, PartialBack
                             gen_backend_file.delayed_installed_files.append((f.full_path, output))
                         else:
                             gen_backend_file.symlink_rule(f.full_path, output=output,
                                                           output_group=self._installed_files)
 
 
     def _process_final_target_pp_files(self, obj, backend_file):
         for i, (path, files) in enumerate(obj.files.walk()):
+            self._add_features(obj.install_target, path)
             for f in files:
                 self._preprocess(backend_file, f.full_path,
                                  destdir=mozpath.join(self.environment.topobjdir, obj.install_target, path),
                                  target=f.target_basename)
 
     def _process_computed_flags(self, obj, backend_file):
         for var, flags in obj.get_flags():
             backend_file.local_flags[var] = flags