Bug 1247162 - Generate a header defining MOZ_SOURCE_*. r=mshal draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 10 Feb 2016 13:38:31 +0900
changeset 330168 edbbebb4b836f2b44b97c30d68852d27099adb45
parent 330167 fd001b5e6bdc94b8a503728c8815df70edc8a9a6
child 330169 235082272e8c924a4fdb57b2209417c9b92a7202
push id10696
push userbmo:mh+mozilla@glandium.org
push dateWed, 10 Feb 2016 21:56:58 +0000
reviewersmshal
bugs1247162
milestone47.0a1
Bug 1247162 - Generate a header defining MOZ_SOURCE_*. r=mshal The behavior is not entirely idempotent (most notably for buildconfig.html), but this can be improved later if necessary. It is idempotent where it matters. This allows to get rid of config/makefiles/rcs.mk and its uses.
Makefile.in
b2g/app/Makefile.in
build/Makefile.in
build/application.ini
build/variables.py
config/makefiles/makeutils.mk
config/makefiles/rcs.mk
configure.in
moz.build
toolkit/components/telemetry/Makefile.in
toolkit/content/Makefile.in
toolkit/content/buildconfig.html
toolkit/content/moz.build
toolkit/modules/AppConstants.jsm
toolkit/modules/moz.build
toolkit/mozapps/installer/package-name.mk
toolkit/mozapps/installer/packager.mk
toolkit/mozapps/installer/upload-files.mk
toolkit/xre/Makefile.in
toolkit/xre/platform.ini
--- a/Makefile.in
+++ b/Makefile.in
@@ -25,17 +25,17 @@ include $(topsrcdir)/config/config.mk
 
 GARBAGE_DIRS += _javagen _profile staticlib
 DIST_GARBAGE = config.cache config.log config.status* config-defs.h \
    config/autoconf.mk \
    mozilla-config.h \
    netwerk/necko-config.h xpcom/xpcom-config.h xpcom/xpcom-private.h \
    .mozconfig.mk
 
-buildid.h: FORCE
+buildid.h source-repo.h: FORCE
 
 ifdef JS_STANDALONE
 configure_dir = $(topsrcdir)/js/src
 else
 configure_dir = $(topsrcdir)
 endif
 
 BUILD_BACKEND_FILES := $(addprefix backend.,$(addsuffix Backend,$(BUILD_BACKENDS)))
@@ -308,22 +308,16 @@ endif # MOZ_CRASHREPORTER
 
 uploadsymbols:
 ifdef MOZ_CRASHREPORTER
 ifdef SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE
 	$(PYTHON) -u $(topsrcdir)/toolkit/crashreporter/tools/upload_symbols.py '$(DIST)/$(PKG_PATH)$(SYMBOL_FULL_ARCHIVE_BASENAME).zip'
 else
 	$(SHELL) $(topsrcdir)/toolkit/crashreporter/tools/upload_symbols.sh $(SYMBOL_INDEX_NAME) '$(DIST)/$(PKG_PATH)$(SYMBOL_FULL_ARCHIVE_BASENAME).zip'
 endif
-
-# MOZ_SOURCE_STAMP is defined in package-name.mk with a deferred assignment.
-# exporting it makes make run its $(shell) command for each invoked submake,
-# so transform it to an immediate assignment.
-MOZ_SOURCE_STAMP := $(MOZ_SOURCE_STAMP)
-export MOZ_SOURCE_STAMP
 endif
 
 .PHONY: update-packaging
 update-packaging:
 	$(MAKE) -C tools/update-packaging
 
 .PHONY: pretty-package
 pretty-package:
--- a/b2g/app/Makefile.in
+++ b/b2g/app/Makefile.in
@@ -1,15 +1,12 @@
 # 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/.
 
-USE_RCS_MK := 1
-include $(topsrcdir)/config/makefiles/rcs.mk
-
 # Make sure the standalone glue doesn't try to get libxpcom.so from b2g/app.
 NSDISTMODE = copy
 
 include $(topsrcdir)/config/rules.mk
 
 APP_ICON = app
 
 APP_BINARY = $(MOZ_APP_NAME)$(BIN_SUFFIX)
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -5,29 +5,16 @@
 
 USE_RCS_MK := 1
 include $(topsrcdir)/config/makefiles/makeutils.mk
 
 ifdef MOZ_APP_BASENAME
 APP_INI_DEPS = $(topsrcdir)/config/milestone.txt
 
 APP_INI_DEPS += $(DEPTH)/config/autoconf.mk
-
-MOZ_SOURCE_STAMP := $(firstword $(shell cd $(topsrcdir)/$(MOZ_BUILD_APP)/.. && hg parent --template='{node}\n' 2>/dev/null))
-ifdef MOZ_SOURCE_STAMP
-DEFINES += -DMOZ_SOURCE_STAMP='$(MOZ_SOURCE_STAMP)'
-endif
-
-ifdef MOZ_INCLUDE_SOURCE_INFO
-source_repo ?= $(call getSourceRepo,$(topsrcdir)/$(MOZ_BUILD_APP)/..)
-ifneq (,$(source_repo))
-  DEFINES += -DMOZ_SOURCE_REPO='$(source_repo)'
-endif
-endif
-
 endif
 
 # NOTE: Keep .gdbinit in the topsrcdir for people who run gdb from the topsrcdir.
 # needs to be absolute to be distinct from $(topsrcdir)/.gdbinit
 GDBINIT_OBJDIR_FILES = $(topsrcdir)/.gdbinit
 GDBINIT_OBJDIR_DEST = $(topobjdir)
 INSTALL_TARGETS += GDBINIT_OBJDIR
 
--- a/build/application.ini
+++ b/build/application.ini
@@ -11,16 +11,17 @@
 #endif
 #if 0
 ; 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/.
 #endif
 #filter substitution
 #include @TOPOBJDIR@/buildid.h
+#include @TOPOBJDIR@/source-repo.h
 [App]
 Vendor=@MOZ_APP_VENDOR@
 Name=@MOZ_APP_BASENAME@
 RemotingName=@MOZ_APP_REMOTINGNAME@
 #ifdef MOZ_APP_DISPLAYNAME
 CodeName=@MOZ_APP_DISPLAYNAME@
 #endif
 Version=@MOZ_APP_VERSION@
--- a/build/variables.py
+++ b/build/variables.py
@@ -1,19 +1,68 @@
 # 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
 
 import os
+import subprocess
 import sys
 from datetime import datetime
 
 
 def buildid_header(output):
     buildid = os.environ.get('MOZ_BUILD_DATE')
     if buildid and len(buildid) != 14:
         print('Ignoring invalid MOZ_BUILD_DATE: %s' % buildid, file=sys.stderr)
         buildid = None
     if not buildid:
         buildid = datetime.now().strftime('%Y%m%d%H%M%S')
     output.write("#define MOZ_BUILDID %s\n" % buildid)
+
+
+def get_program_output(*command):
+    try:
+        with open(os.devnull) as stderr:
+            return subprocess.check_output(command, stderr=stderr)
+    except:
+        return ''
+
+
+def get_hg_info(workdir):
+    repo = get_program_output('hg', '-R', workdir, 'path', 'default')
+    if repo:
+        repo = repo.strip()
+        if repo.startswith('ssh://'):
+            repo = 'https://' + repo[6:]
+        repo = repo.rstrip('/')
+
+    changeset = get_program_output(
+        'hg', '-R', workdir, 'parent', '--template={node}')
+
+    return repo, changeset
+
+
+def source_repo_header(output):
+    # We allow the source repo and changeset to be specified via the
+    # environment (see configure)
+    import buildconfig
+    repo = buildconfig.substs.get('MOZ_SOURCE_REPO')
+    changeset = buildconfig.substs.get('MOZ_SOURCE_CHANGESET')
+    source = ''
+
+    if bool(repo) != bool(changeset):
+        raise Exception('MOZ_SOURCE_REPO and MOZ_SOURCE_CHANGESET both must '
+                        'be set (or not set).')
+
+    if not repo:
+        if os.path.exists(os.path.join(buildconfig.topsrcdir, '.hg')):
+            repo, changeset = get_hg_info(buildconfig.topsrcdir)
+
+    if changeset:
+        output.write('#define MOZ_SOURCE_STAMP %s\n' % changeset)
+
+    if repo and buildconfig.substs.get('MOZ_INCLUDE_SOURCE_INFO'):
+        source = '%s/rev/%s' % (repo, changeset)
+        output.write('#define MOZ_SOURCE_REPO %s\n' % repo)
+        output.write('#define MOZ_SOURCE_URL %s\n' % source)
+
--- a/config/makefiles/makeutils.mk
+++ b/config/makefiles/makeutils.mk
@@ -112,14 +112,10 @@ topORerr = $(MOZILLA_DIR)
 else
 topORerr = $(if $(topsrcdir),$(topsrcdir),$(error topsrcdir is not defined))
 endif
 
 ifdef USE_AUTOTARGETS_MK # mkdir_deps
   include $(topORerr)/config/makefiles/autotargets.mk
 endif
 
-ifdef USE_RCS_MK
-  include $(topORerr)/config/makefiles/rcs.mk
-endif
-
 ## copy(src, dst): recursive copy
 copy_dir = (cd $(1)/. && $(TAR) $(TAR_CREATE_FLAGS) - .) | (cd $(2)/. && tar -xf -)
deleted file mode 100644
--- a/config/makefiles/rcs.mk
+++ /dev/null
@@ -1,54 +0,0 @@
-# -*- makefile -*-
-# vim:set ts=8 sw=8 sts=8 noet:
-#
-# 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/.
-#
-
-ifdef USE_RCS_MK #{
-
-ifndef INCLUDED_RCS_MK #{
-
-MOZ_RCS_TYPE_HG ?= $(notdir $(wildcard $(topsrcdir)/.hg))
-MOZ_RCS_TYPE_GIT ?= $(notdir $(wildcard $(topsrcdir)/.git))
-
-
-###########################################################################
-# HAVE_MERCURIAL_RCS
-###########################################################################
-ifeq (.hg,$(MOZ_RCS_TYPE_HG)) #{
-
-# Intent: Retrieve the http:// repository path for a directory.
-# Usage: $(call getSourceRepo[,repo_dir|args])
-# Args:
-#   path (optional): repository to query.  Defaults to $(topsrcdir)
-getSourceRepo = \
-  $(call FUNC_getSourceRepo,$(if $(1),cd $(1) && hg,hg --repository $(topsrcdir)))
-
-# return: http://hg.mozilla.org/mozilla-central
-FUNC_getSourceRepo = \
-  $(strip \
-    $(patsubst %/,%,\
-    $(patsubst ssh://%,http://%,\
-    $(firstword $(shell $(getargv) showconfig paths.default))\
-    )))
-
-#} HAVE_MERCURIAL_RCS
-
-###########################################################################
-# HAVE_GIT_RCS
-###########################################################################
-else ifeq (.git,$(MOZ_RCS_TYPE_GIT)) #{
-
-GIT ?= git
-getSourceRepo = \
-  $(shell cd $(topsrcdir) && $(GIT) rev-parse --verify HEAD)
-
-endif #} HAVE_GIT_RCS
-
-
-INCLUDED_RCS_MK := 1
-endif #}
-
-endif #}
--- a/configure.in
+++ b/configure.in
@@ -8718,25 +8718,18 @@ AC_SUBST(MOZILLA_OFFICIAL)
 if test "$MOZILLA_OFFICIAL"; then
     AC_DEFINE(MOZILLA_OFFICIAL)
     # Build revisions should always be present in official builds
     MOZ_INCLUDE_SOURCE_INFO=1
 fi
 
 # External builds (specifically Ubuntu) may drop the hg repo information, so we allow to
 # explicitly set the repository and changeset information in.
-if test "$MOZILLA_OFFICIAL"; then
-    if test -z "$MOZ_SOURCE_REPO" && test -z "$MOZ_SOURCE_CHANGESET" && test -d ${_topsrcdir}/.hg; then
-        MOZ_SOURCE_CHANGESET=`cd $_topsrcdir && hg parent --template='{node}'`
-        MOZ_SOURCE_REPO=`cd $_topsrcdir && hg showconfig paths.default | sed -e 's|^ssh://|http://|' -e 's|/$||'`
-    fi
-    SOURCE_REV_URL=$MOZ_SOURCE_REPO/rev/$MOZ_SOURCE_CHANGESET
-fi
-AC_SUBST(SOURCE_REV_URL)
-
+AC_SUBST(MOZ_SOURCE_REPO)
+AC_SUBST(MOZ_SOURCE_CHANGESET)
 AC_SUBST(MOZ_INCLUDE_SOURCE_INFO)
 
 if test "$MOZ_TELEMETRY_REPORTING"; then
     AC_DEFINE(MOZ_TELEMETRY_REPORTING)
 
     # Enable Telemetry by default for nightly and aurora channels
     if test -z "$RELEASE_BUILD"; then
       AC_DEFINE(MOZ_TELEMETRY_ON_BY_DEFAULT)
--- a/moz.build
+++ b/moz.build
@@ -28,23 +28,26 @@ if not CONFIG['JS_STANDALONE']:
         'tools/update-packaging/Makefile',
     ]
     CONFIGURE_DEFINE_FILES += [
         'mozilla-config.h',
     ]
     EXPORTS += [
         '!buildid.h',
         '!mozilla-config.h',
+        '!source-repo.h',
     ]
 
     GENERATED_FILES += [
         'buildid.h',
+        'source-repo.h',
     ]
 
     GENERATED_FILES['buildid.h'].script = 'build/variables.py:buildid_header'
+    GENERATED_FILES['source-repo.h'].script = 'build/variables.py:source_repo_header'
 
     DIRS += [
         'build',
         'probes',
     ]
 
 DIRS += [
     'config/external/zlib',
--- a/toolkit/components/telemetry/Makefile.in
+++ b/toolkit/components/telemetry/Makefile.in
@@ -1,16 +1,13 @@
 #
 # 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/.
 
-USE_RCS_MK := 1
-include $(topsrcdir)/config/makefiles/rcs.mk
-
 include $(topsrcdir)/config/rules.mk
 
 # This is so hacky. Waiting on bug 988938.
 addondir = $(srcdir)/tests/addons
 testdir = $(topobjdir)/_tests/xpcshell/toolkit/components/telemetry/tests/unit
 
 misc:: $(call mkdir_deps,$(testdir))
 	$(EXIT_ON_ERROR) \
--- a/toolkit/content/Makefile.in
+++ b/toolkit/content/Makefile.in
@@ -1,26 +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/.
 
-USE_RCS_MK := 1
-include $(topsrcdir)/config/makefiles/makeutils.mk
-
 DEFINES += \
   -DCXXFLAGS='$(CXXFLAGS)' \
   -DCPPFLAGS='$(CPPFLAGS)' \
   $(NULL)
-
-MOZ_SOURCE_STAMP ?= $(shell hg -R $(topsrcdir) parent --template='{node}\n' 2>/dev/null)
-ifdef MOZ_SOURCE_STAMP
-DEFINES += -DSOURCE_CHANGESET='$(MOZ_SOURCE_STAMP)'
-endif
-
-ifdef MOZ_INCLUDE_SOURCE_INFO
-source_repo ?= $(call getSourceRepo)
-ifneq (,$(filter http%,$(source_repo)))
-  DEFINES += -DSOURCE_REPO='$(source_repo)'
-else ifneq (,$(strip $(source_repo)))
-  DEFINES += -DSOURCE_GIT_COMMIT='$(source_repo)'
-endif
-endif
--- a/toolkit/content/buildconfig.html
+++ b/toolkit/content/buildconfig.html
@@ -1,36 +1,32 @@
 <!DOCTYPE html>
 # 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/.
 #
 #filter substitution
+#include @TOPOBJDIR@/source-repo.h
 <html>
 <head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width; user-scalable=false;">
   <title>about:buildconfig</title>
   <link rel="stylesheet" href="chrome://global/skin/about.css" type="text/css">
   <style type="text/css">
     th { text-align: start; }
     h2 { margin-top: 1.5em; }
     th, td { vertical-align: top; }
   </style>
 </head>
 <body class="aboutPageWideContainer">
 <h1>about:buildconfig</h1>
-#ifdef SOURCE_REPO
-#ifdef SOURCE_CHANGESET
+#ifdef MOZ_SOURCE_URL
 <h2>Source</h2>
-<p>Built from <a href="@SOURCE_REPO@/rev/@SOURCE_CHANGESET@">@SOURCE_REPO@/rev/@SOURCE_CHANGESET@</a></p>
-#endif
-#elifdef SOURCE_GIT_COMMIT
-<h2>Source</h2>
-<p>Built from git commit <a href="#">@SOURCE_GIT_COMMIT@</a></p>
+<p>Built from <a href="@MOZ_SOURCE_URL@">@MOZ_SOURCE_URL@</a></p>
 #endif
 <h2>Build platform</h2>
 <table>
   <tbody>
     <tr>
       <th>target</th>
     </tr>
     <tr>
--- a/toolkit/content/moz.build
+++ b/toolkit/content/moz.build
@@ -26,8 +26,10 @@ JAR_MANIFESTS += ['jar.mn']
 with Files('aboutTelemetry.*'):
     BUG_COMPONENT = ('Toolkit', 'Telemetry')
 
 with Files('customizeToolbar.*'):
     BUG_COMPONENT = ('Toolkit', 'Toolbars and Toolbar Customization')
 
 with Files('widgets/*'):
     BUG_COMPONENT = ('Toolkit', 'XUL Widgets')
+
+DEFINES['TOPOBJDIR'] = TOPOBJDIR
--- a/toolkit/modules/AppConstants.jsm
+++ b/toolkit/modules/AppConstants.jsm
@@ -1,9 +1,10 @@
 #filter substitution
+#include @TOPOBJDIR@/source-repo.h
 /* 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/. */
 
 "use strict";
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm");
@@ -303,17 +304,20 @@ this.AppConstants = Object.freeze({
 #else
     false,
 #endif
   DEBUG_JS_MODULES: "@DEBUG_JS_MODULES@",
 
   // URL to the hg revision this was built from (e.g.
   // "https://hg.mozilla.org/mozilla-central/rev/6256ec9113c1")
   // On unofficial builds, this is an empty string.
-  SOURCE_REVISION_URL: "@SOURCE_REV_URL@",
+#ifndef MOZ_SOURCE_URL
+#define MOZ_SOURCE_URL
+#endif
+  SOURCE_REVISION_URL: "@MOZ_SOURCE_URL@",
 
   MOZ_NUWA_PROCESS:
 #ifdef MOZ_NUWA_PROCESS
     true
 #else
     false
 #endif
 });
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -112,18 +112,19 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'wind
 for var in ('ANDROID_PACKAGE_NAME',
             'MOZ_APP_NAME',
             'MOZ_APP_VERSION',
             'MOZ_APP_VERSION_DISPLAY',
             'MOZ_MACBUNDLE_NAME',
             'MOZ_WIDGET_TOOLKIT',
             'DLL_PREFIX',
             'DLL_SUFFIX',
-            'DEBUG_JS_MODULES',
-            'SOURCE_REV_URL'):
+            'DEBUG_JS_MODULES'):
             DEFINES[var] = CONFIG[var]
 
 for var in ('MOZ_TOOLKIT_SEARCH',
             'MOZ_REQUIRE_SIGNING',
             'MOZ_NATIVE_NSS',
             'MOZ_UPDATER'):
     if CONFIG[var]:
         DEFINES[var] = True
+
+DEFINES['TOPOBJDIR'] = TOPOBJDIR
--- a/toolkit/mozapps/installer/package-name.mk
+++ b/toolkit/mozapps/installer/package-name.mk
@@ -145,26 +145,16 @@ else
 BUILDID = $(shell $(PYTHON) $(MOZILLA_DIR)/config/printconfigsetting.py $(DIST)/bin/platform.ini Build BuildID)
 endif
 
 ifndef INCLUDED_RCS_MK
   USE_RCS_MK := 1
   include $(MOZILLA_DIR)/config/makefiles/makeutils.mk
 endif
 
-MOZ_SOURCE_STAMP = $(firstword $(shell hg -R $(MOZILLA_DIR) parent --template="{node}\n" 2>/dev/null))
-
-###########################################################################
-# bug: 746277 - preserve existing functionality.
-# MOZILLA_DIR="": cd $(SPACE); hg # succeeds if ~/.hg exists
-###########################################################################
-ifdef MOZ_INCLUDE_SOURCE_INFO
-MOZ_SOURCE_REPO = $(call getSourceRepo,$(MOZILLA_DIR)$(NULL) $(NULL))
-endif
-
 MOZ_SOURCESTAMP_FILE = $(DIST)/$(PKG_PATH)/$(MOZ_INFO_BASENAME).txt
 MOZ_BUILDINFO_FILE = $(DIST)/$(PKG_PATH)/$(MOZ_INFO_BASENAME).json
 MOZ_MOZINFO_FILE = $(DIST)/$(PKG_PATH)/$(MOZ_INFO_BASENAME).mozinfo.json
 MOZ_TEST_PACKAGES_FILE = $(DIST)/$(PKG_PATH)/test_packages.json
 MOZ_TEST_PACKAGES_FILE_TC = $(DIST)/$(PKG_PATH)/test_packages_tc.json
 
 # JavaScript Shell
 ifdef MOZ_SIMPLE_PACKAGE_NAME
--- a/toolkit/mozapps/installer/packager.mk
+++ b/toolkit/mozapps/installer/packager.mk
@@ -91,27 +91,27 @@ make-package: FORCE
 	$(MAKE) make-package-internal
 	$(TOUCH) $@
 
 GARBAGE += make-package
 
 make-sourcestamp-file::
 	$(NSINSTALL) -D $(DIST)/$(PKG_PATH)
 	@echo '$(BUILDID)' > $(MOZ_SOURCESTAMP_FILE)
-ifdef MOZ_SOURCE_REPO
-	@echo '$(MOZ_SOURCE_REPO)/rev/$(MOZ_SOURCE_STAMP)' >> $(MOZ_SOURCESTAMP_FILE)
+ifdef MOZ_INCLUDE_SOURCE_INFO
+	@awk '$$2 == "MOZ_SOURCE_URL" {print $$3}' $(DEPTH)/source-repo.h >> $(MOZ_SOURCESTAMP_FILE)
 endif
 
 .PHONY: make-buildinfo-file
 make-buildinfo-file:
 	$(PYTHON) $(MOZILLA_DIR)/toolkit/mozapps/installer/informulate.py \
 		$(MOZ_BUILDINFO_FILE) \
 		BUILDID=$(BUILDID) \
-		$(addprefix MOZ_SOURCE_REPO=,MOZ_SOURCE_REPO=$(MOZ_SOURCE_REPO)) \
-		MOZ_SOURCE_STAMP=$(MOZ_SOURCE_STAMP) \
+		$(addprefix MOZ_SOURCE_REPO=,MOZ_SOURCE_REPO=$(shell awk '$$2 == "MOZ_SOURCE_REPO" {print $$3}' $(DEPTH)/source-repo.h)) \
+		MOZ_SOURCE_STAMP=$(shell awk '$$2 == "MOZ_SOURCE_STAMP" {print $$3}' $(DEPTH)/source-repo.h) \
 		MOZ_PKG_PLATFORM=$(MOZ_PKG_PLATFORM)
 
 .PHONY: make-mozinfo-file
 make-mozinfo-file:
 	cp $(DEPTH)/mozinfo.json $(MOZ_MOZINFO_FILE)
 
 # The install target will install the application to prefix/lib/appname-version
 # In addition if INSTALL_SDK is set, it will install the development headers,
--- a/toolkit/mozapps/installer/upload-files.mk
+++ b/toolkit/mozapps/installer/upload-files.mk
@@ -188,18 +188,18 @@ RPM_CMD = \
   --target $(TARGET_CPU) \
   --buildroot $(RPMBUILD_TOPDIR)/BUILDROOT \
   --define 'moz_app_name $(MOZ_APP_NAME)' \
   --define 'moz_app_displayname $(MOZ_APP_DISPLAYNAME)' \
   --define 'moz_app_version $(MOZ_APP_VERSION)' \
   --define 'moz_numeric_app_version $(MOZ_NUMERIC_APP_VERSION)' \
   --define 'moz_rpm_release $(MOZ_RPM_RELEASE)' \
   --define 'buildid $(BUILDID)' \
-  $(if $(MOZ_SOURCE_REPO),--define 'moz_source_repo $(MOZ_SOURCE_REPO)') \
-  --define 'moz_source_stamp $(MOZ_SOURCE_STAMP)' \
+  --define 'moz_source_repo $(shell awk '$$2 == "MOZ_SOURCE_REPO" {print $$3}' $(DEPTH)/source-repo.h)' \
+  --define 'moz_source_stamp $(shell awk '$$2 == "MOZ_SOURCE_STAMP" {print $$3}' $(DEPTH)/source-repo.h)' \
   --define 'moz_branding_directory $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)' \
   --define '_topdir $(RPMBUILD_TOPDIR)' \
   --define '_rpmdir $(RPMBUILD_RPMDIR)' \
   --define '_sourcedir $(RPMBUILD_SOURCEDIR)' \
   --define '_specdir $(RPMBUILD_SPECDIR)' \
   --define '_srcrpmdir $(RPMBUILD_SRPMDIR)' \
   --define '_builddir $(RPMBUILD_BUILDDIR)' \
   --define '_prefix $(prefix)' \
--- a/toolkit/xre/Makefile.in
+++ b/toolkit/xre/Makefile.in
@@ -1,38 +1,19 @@
 # -*- makefile -*-
 # vim:set ts=8 sw=8 sts=8 noet:
 
 # 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/.
 
-USE_RCS_MK=1
-include $(topsrcdir)/config/makefiles/makeutils.mk
-
 milestone_txt = $(topsrcdir)/config/milestone.txt
 
 include $(topsrcdir)/config/rules.mk
 
-MOZ_SOURCE_STAMP ?= $(firstword $(shell hg -R $(topsrcdir) parent --template='{node}\n' 2>/dev/null))
-ifneq (,$(strip $(MOZ_SOURCE_STAMP)))
-
-  DEFINES += -DMOZ_SOURCE_STAMP=$(MOZ_SOURCE_STAMP)
-
-  ifdef MOZ_INCLUDE_SOURCE_INFO
-    source_repo := $(call getSourceRepo)
-
-    # extra sanity check for old versions of hg, no showconfig support
-    ifneq (,$(filter http%,$(source_repo)))
-      DEFINES += -DMOZ_SOURCE_REPO=$(source_repo)
-    endif
-  endif
-
-endif # MOZ_SOURCE_STAMP
-
 MOZ_BUILDID   := $(shell awk '{print $$3}' $(DEPTH)/buildid.h)
 $(call errorIfEmpty,GRE_MILESTONE MOZ_BUILDID)
 
 # Note these dependencies are broken because the target is *not* the cpp file.
 # BUT, actually fixing it would make libxul rebuilt on every single incremental
 # build because of the automatic buildid change. This is why we can't actually
 # include buildid.h there, because it would add the dependency.
 $(srcdir)/nsAppRunner.cpp: $(DEPTH)/buildid.h $(milestone_txt)
--- a/toolkit/xre/platform.ini
+++ b/toolkit/xre/platform.ini
@@ -1,15 +1,16 @@
 #if 0
 ; 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/.
 #endif
 #filter substitution
 #include @TOPOBJDIR@/buildid.h
+#include @TOPOBJDIR@/source-repo.h
 [Build]
 BuildID=@MOZ_BUILDID@
 Milestone=@GRE_MILESTONE@
 #ifdef MOZ_SOURCE_REPO
 SourceRepository=@MOZ_SOURCE_REPO@
 #endif
 #ifdef MOZ_SOURCE_STAMP
 SourceStamp=@MOZ_SOURCE_STAMP@