Bug 1625033 - Create build artifact to generate "Built from" links in Treeherder. r=darktrojan CLOSED TREE
authorRob Lemley <rob@thunderbird.net>
Tue, 28 Apr 2020 20:42:30 -0400
changeset 38996 dce2046514b0a603c84bbf6cbf1cbc8730faf35e
parent 38995 afa946f9ac2eec9551adf7cdd8a6af156fd3d028
child 38997 c26f73fefb05e92cbe37c4e35c12a2a2a9d46eb1
push id401
push userclokep@gmail.com
push dateMon, 01 Jun 2020 20:41:59 +0000
reviewersdarktrojan
bugs1625033
Bug 1625033 - Create build artifact to generate "Built from" links in Treeherder. r=darktrojan CLOSED TREE Treeherder is getting an update later this week that affects the "Built from" links that appear in the Job Details panel. Rather than parsing log files, a build artifact will be used to display these links. The artifact is a JSON file in the suggested format.
build/source_repos.py
mail/Makefile.in
mail/defs.mk
mail/installer/Makefile.in
--- a/build/source_repos.py
+++ b/build/source_repos.py
@@ -1,25 +1,55 @@
 #  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 print_function, unicode_literals, absolute_import
 
 import sys
 import os
+import json
 
 import buildconfig
 
 sourcestamp_tmpl = """{buildid}
 {comm_repo}/rev/{comm_rev}
 {gecko_repo}/rev/{gecko_rev}
 """
 
 
+def mk_hg_url(repo, revision):
+    """
+    Return a URL to a specific revision in the given repo.
+    """
+    return "{}/rev/{}".format(repo, revision)
+
+
+def gen_treeherder_build_links(output):
+    """
+    Create a JSON file that is used by Treeherder to display "Built from" links.
+    """
+    gecko_repo = buildconfig.substs.get('MOZ_GECKO_SOURCE_REPO')
+    gecko_rev = buildconfig.substs.get('MOZ_GECKO_SOURCE_CHANGESET')
+    comm_repo = buildconfig.substs.get('MOZ_COMM_SOURCE_REPO')
+    comm_rev = buildconfig.substs.get('MOZ_COMM_SOURCE_CHANGESET')
+
+    def mk_built_from_line(repo, revision):
+        repo_name = repo.split('/')[-1]  # Last component of base URL
+        title = "Built from {} revision {}".format(repo_name, revision)
+        url = mk_hg_url(repo, revision)
+        return dict(title=title,
+                    value=revision,
+                    url=url)
+
+    built_from = [mk_built_from_line(gecko_repo, gecko_rev),
+                  mk_built_from_line(comm_repo, comm_rev)]
+    json.dump(built_from, output)
+
+
 def gen_platformini(output, platform_ini):
     gecko_repo = buildconfig.substs.get('MOZ_GECKO_SOURCE_REPO', '')
     gecko_rev = buildconfig.substs.get('MOZ_GECKO_SOURCE_CHANGESET', '')
 
     with open(platform_ini, 'r') as fp:
         data = fp.readlines()
 
     for i in range(len(data)):
@@ -60,18 +90,18 @@ def source_repo_header(output):
                   "as well as MOZ_SOURCE_REPO and MOZ_SOURCE_CHANGESET"
                   "environment variables and running mach configure again.")
 
     output.write('#define MOZ_GECKO_SOURCE_STAMP {}\n'.format(gecko_rev))
     output.write('#define MOZ_COMM_SOURCE_STAMP {}\n'.format(comm_rev))
     output.write('#define MOZ_SOURCE_STAMP {}\n'.format(comm_rev))
 
     if buildconfig.substs.get('MOZ_INCLUDE_SOURCE_INFO'):
-        gecko_source_url = '%s/rev/%s' % (gecko_repo, gecko_rev)
-        comm_source_url = '%s/rev/%s' % (comm_repo, comm_rev)
+        gecko_source_url = mk_hg_url(gecko_repo, gecko_rev)
+        comm_source_url = mk_hg_url(comm_repo, comm_rev)
         output.write('#define MOZ_GECKO_SOURCE_REPO {}\n'.format(gecko_repo))
         output.write('#define MOZ_GECKO_SOURCE_URL {}\n'.format(gecko_source_url))
         output.write('#define MOZ_COMM_SOURCE_REPO {}\n'.format(comm_repo))
         output.write('#define MOZ_COMM_SOURCE_URL {}\n'.format(comm_source_url))
         output.write('#define MOZ_SOURCE_REPO {}\n'.format(comm_repo))
         output.write('#define MOZ_SOURCE_URL {}\n'.format(comm_source_url))
 
 
--- a/mail/Makefile.in
+++ b/mail/Makefile.in
@@ -18,8 +18,11 @@ endif
 
 # As fallout from bug 1247162, the sourcestamp in application.ini and
 # platform.ini are the same, which isn't a problem for Firefox, but
 # it's not right for anything else. So we correct platform.ini here.
 libs:: $(DIST)/bin/platform.ini
 	$(PYTHON) $(commtopsrcdir)/build/source_repos.py gen_platformini \
 		$(DIST)/bin/platform.ini
 
+libs::
+	@echo Generating $(MOZ_BUILT_FROM_FILE) for Treeherder.
+	$(PYTHON) $(commtopsrcdir)/build/source_repos.py gen_treeherder_build_links > $(DIST)/$(MOZ_BUILT_FROM_FILE)
--- a/mail/defs.mk
+++ b/mail/defs.mk
@@ -1,8 +1,9 @@
 # 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/.
 
 # The variables defined here will be set for all files within the mail/
 # subdirectory.
 
 XPI_ROOT_APPID=$(MOZ_APP_ID)
+MOZ_BUILT_FROM_FILE = built_from.json
--- a/mail/installer/Makefile.in
+++ b/mail/installer/Makefile.in
@@ -128,16 +128,17 @@ endif
 #
 # Also, the JS minification setup really only works correctly on Android:
 # we need extra setup to use the newly-built shell for Linux and Windows,
 # and Mac requires some extra care due to cross-compilation.
 MOZ_PACKAGER_MINIFY=1
 
 NON_OMNIJAR_FILES = defaults/messenger/mailViews.dat
 
+UPLOAD_EXTRA_FILES = $(MOZ_BUILT_FROM_FILE)
 include $(moztopsrcdir)/toolkit/mozapps/installer/packager.mk
 
 ifeq (bundle, $(MOZ_FS_LAYOUT))
 BINPATH = $(_BINPATH)
 DEFINES += -DAPPNAME='$(_APPNAME)'
 else
 # Every other platform just winds up in dist/bin
 BINPATH = bin