Bug 1246881 - Generate a header defining MOZ_BUILDID draft
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 09 Feb 2016 14:36:07 +0900
changeset 330165 9dd52c75fd8e920cf796aab88ecb4da91f14ed1d
parent 330020 6c98cc47620dc96dcd2ed18eb1833b47a69810a6
child 330166 72b84371c71f15c883dce80f20255b2d9dc8cb76
push id10696
push userbmo:mh+mozilla@glandium.org
push dateWed, 10 Feb 2016 21:56:58 +0000
bugs1246881
milestone47.0a1
Bug 1246881 - Generate a header defining MOZ_BUILDID
Makefile.in
build/Makefile.in
build/application.ini
build/moz.build
build/variables.py
config/faster/rules.mk
mobile/android/base/Makefile.in
mobile/android/base/moz.build
moz.build
toolkit/xre/Makefile.in
toolkit/xre/moz.build
toolkit/xre/nsAppRunner.cpp
toolkit/xre/platform.ini
webapprt/Makefile.in
webapprt/gtk/Makefile.in
webapprt/gtk/webapprt.cpp
webapprt/mac/Makefile.in
webapprt/mac/webapprt.mm
webapprt/moz.build
webapprt/webapprt.ini
webapprt/win/Makefile.in
webapprt/win/webapprt.cpp
--- a/Makefile.in
+++ b/Makefile.in
@@ -10,29 +10,33 @@ make_min_ver := 3.81
 ifneq ($(make_min_ver),$(firstword $(sort $(make_min_ver) $(MAKE_VERSION))))
 $(error GNU Make $(make_min_ver) or higher is required)
 endif
 
 export TOPLEVEL_BUILD := 1
 
 default::
 
+ifndef TEST_MOZBUILD
 ifdef MOZ_BUILD_APP
 include $(topsrcdir)/$(MOZ_BUILD_APP)/build.mk
 endif
+endif
 
 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
+
 ifdef JS_STANDALONE
 configure_dir = $(topsrcdir)/js/src
 else
 configure_dir = $(topsrcdir)
 endif
 
 BUILD_BACKEND_FILES := $(addprefix backend.,$(addsuffix Backend,$(BUILD_BACKENDS)))
 
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -4,21 +4,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 USE_RCS_MK := 1
 include $(topsrcdir)/config/makefiles/makeutils.mk
 
 ifdef MOZ_APP_BASENAME
 APP_INI_DEPS = $(topsrcdir)/config/milestone.txt
 
-MOZ_BUILDID := $(shell cat $(DEPTH)/config/buildid)
-APP_INI_DEPS += $(DEPTH)/config/buildid
-
-DEFINES += -DMOZ_BUILDID=$(MOZ_BUILDID)
-
 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
--- a/build/application.ini
+++ b/build/application.ini
@@ -10,16 +10,17 @@
 #endif
 #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
 [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/moz.build
+++ b/build/moz.build
@@ -70,8 +70,10 @@ FINAL_TARGET_FILES += ['/.gdbinit']
 # Install the clang-cl runtime library for ASAN next to the binaries we produce.
 if CONFIG['MOZ_ASAN'] and CONFIG['CLANG_CL']:
     FINAL_TARGET_FILES += ['%' + CONFIG['MOZ_CLANG_RT_ASAN_LIB_PATH']]
 
 if CONFIG['MOZ_APP_BASENAME']:
     FINAL_TARGET_PP_FILES += ['application.ini']
     if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android' and CONFIG['MOZ_UPDATER']:
         FINAL_TARGET_PP_FILES += ['update-settings.ini']
+
+DEFINES['TOPOBJDIR'] = TOPOBJDIR
new file mode 100644
--- /dev/null
+++ b/build/variables.py
@@ -0,0 +1,19 @@
+# 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 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)
--- a/config/faster/rules.mk
+++ b/config/faster/rules.mk
@@ -75,28 +75,27 @@ ACDEFINES += -DBUILD_FASTER
 	$(MAKE) -C $(dir $@) $(notdir $@)
 
 # Install files using install manifests
 #
 # The list of base directories is given in INSTALL_MANIFESTS. The
 # corresponding install manifests are named correspondingly, with forward
 # slashes replaced with underscores, and prefixed with `install_`. That is,
 # the install manifest for `dist/bin` would be `install_dist_bin`.
-$(addprefix install-,$(INSTALL_MANIFESTS)): install-%: $(TOPOBJDIR)/config/buildid
+$(addprefix install-,$(INSTALL_MANIFESTS)): install-%: $(TOPOBJDIR)/buildid.h
 	@# For now, force preprocessed files to be reprocessed every time.
 	@# The overhead is not that big, and this avoids waiting for proper
 	@# support for defines tracking in process_install_manifest.
 	@touch install_$(subst /,_,$*)
 	@# BOOKMARKS_INCLUDE_DIR is for bookmarks.html only.
 	$(PYTHON) -m mozbuild.action.process_install_manifest \
 		--track install_$(subst /,_,$*).track \
 		$(TOPOBJDIR)/$* \
 		-DAB_CD=en-US \
 		-DBOOKMARKS_INCLUDE_DIR=$(TOPSRCDIR)/browser/locales/en-US/profile \
-		-DMOZ_BUILDID=$(shell cat $(TOPOBJDIR)/config/buildid) \
 		$(ACDEFINES) \
 		install_$(subst /,_,$*)
 
 # ============================================================================
 # Below is a set of additional dependencies and variables used to build things
 # that are not supported by data in moz.build.
 
 # The xpidl target in config/makefiles/xpidl requires the install manifest for
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -1,13 +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/.
 
-MOZ_BUILDID := $(shell cat $(DEPTH)/config/buildid)
+MOZ_BUILDID := $(shell awk '{print $$3}' $(DEPTH)/buildid.h)
 
 # Set the appropriate version code, based on the existance of the
 # MOZ_APP_ANDROID_VERSION_CODE variable.
 ifdef MOZ_APP_ANDROID_VERSION_CODE
     ANDROID_VERSION_CODE:=$(MOZ_APP_ANDROID_VERSION_CODE)
 else
     ANDROID_VERSION_CODE:=$(shell $(PYTHON) \
       $(topsrcdir)/python/mozbuild/mozbuild/android_version_code.py \
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -949,8 +949,10 @@ if CONFIG['MOZ_ANDROID_SEARCH_ACTIVITY']
         'gecko-R.jar',
         'gecko-browser.jar',
         'gecko-mozglue.jar',
         'gecko-thirdparty.jar',
         'gecko-util.jar'
     ]
 
 FINAL_TARGET_PP_FILES += ['package-name.txt.in']
+
+DEFINES['TOPOBJDIR'] = TOPOBJDIR
--- a/moz.build
+++ b/moz.build
@@ -26,19 +26,26 @@ DIRS += [
 if not CONFIG['JS_STANDALONE']:
     CONFIGURE_SUBST_FILES += [
         'tools/update-packaging/Makefile',
     ]
     CONFIGURE_DEFINE_FILES += [
         'mozilla-config.h',
     ]
     EXPORTS += [
+        '!buildid.h',
         '!mozilla-config.h',
     ]
 
+    GENERATED_FILES += [
+        'buildid.h',
+    ]
+
+    GENERATED_FILES['buildid.h'].script = 'build/variables.py:buildid_header'
+
     DIRS += [
         'build',
         'probes',
     ]
 
 DIRS += [
     'config/external/zlib',
     'memory',
--- a/toolkit/xre/Makefile.in
+++ b/toolkit/xre/Makefile.in
@@ -23,14 +23,18 @@ ifneq (,$(strip $(MOZ_SOURCE_STAMP)))
     # 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   := $(strip $(firstword $(shell cat $(DEPTH)/config/buildid 2>/dev/null)))
+MOZ_BUILDID   := $(shell awk '{print $$3}' $(DEPTH)/buildid.h)
 $(call errorIfEmpty,GRE_MILESTONE MOZ_BUILDID)
 
 DEFINES += -DMOZ_BUILDID=$(MOZ_BUILDID)
 
-$(srcdir)/nsAppRunner.cpp: $(DEPTH)/config/buildid $(milestone_txt)
+# 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/moz.build
+++ b/toolkit/xre/moz.build
@@ -175,11 +175,12 @@ if CONFIG['MOZ_B2G_LOADER']:
 
 CXXFLAGS += CONFIG['TK_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
 
 if CONFIG['MOZ_WIDGET_GTK']:
     CXXFLAGS += CONFIG['MOZ_PANGO_CFLAGS']
 
+DEFINES['TOPOBJDIR'] = TOPOBJDIR
 FINAL_TARGET_PP_FILES += [
     'platform.ini'
 ]
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -248,16 +248,22 @@ static char **gQtOnlyArgv;
 #include <gtk/gtk.h>
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #endif /* MOZ_X11 */
 #include "nsGTKToolkit.h"
 #include <fontconfig/fontconfig.h>
 #endif
 #include "BinaryPath.h"
+#ifndef MOZ_BUILDID
+// See comment in Makefile.in why we want to avoid including buildid.h.
+// Still include it when MOZ_BUILDID is not set, which can happen with some
+// build backends.
+#include "buildid.h"
+#endif
 
 #ifdef MOZ_LINKER
 extern "C" MFBT_API bool IsSignalHandlingBroken();
 #endif
 
 namespace mozilla {
 int (*RunGTest)() = 0;
 } // namespace mozilla
--- a/toolkit/xre/platform.ini
+++ b/toolkit/xre/platform.ini
@@ -1,14 +1,15 @@
 #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
 [Build]
 BuildID=@MOZ_BUILDID@
 Milestone=@GRE_MILESTONE@
 #ifdef MOZ_SOURCE_REPO
 SourceRepository=@MOZ_SOURCE_REPO@
 #endif
 #ifdef MOZ_SOURCE_STAMP
 SourceStamp=@MOZ_SOURCE_STAMP@
deleted file mode 100644
--- a/webapprt/Makefile.in
+++ /dev/null
@@ -1,12 +0,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/.
-
-# Include rules.mk explicitly so we can use FINAL_TARGET. Also, the dependencies
-# for webapprt.ini need to be set after PP_TARGETS are expanded in rules.mk.
-include $(topsrcdir)/config/rules.mk
-
-MOZ_BUILDID := $(shell cat $(DEPTH)/config/buildid)
-DEFINES += -DMOZ_BUILDID=$(MOZ_BUILDID)
-
-$(FINAL_TARGET)/webapprt.ini: $(DEPTH)/config/buildid $(topsrcdir)/config/milestone.txt
--- a/webapprt/gtk/Makefile.in
+++ b/webapprt/gtk/Makefile.in
@@ -1,14 +1,7 @@
 # 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/.
 
 NSDISTMODE = copy
 
 PROGRAMS_DEST = $(DIST)/bin
-
-include $(topsrcdir)/config/rules.mk
-
-MOZ_BUILDID := $(shell cat $(DEPTH)/config/buildid)
-DEFINES += -DMOZ_BUILDID=$(MOZ_BUILDID)
-
-webapprt.$(OBJ_SUFFIX): $(DEPTH)/config/buildid
--- a/webapprt/gtk/webapprt.cpp
+++ b/webapprt/gtk/webapprt.cpp
@@ -14,16 +14,17 @@
 
 // Mozilla headers
 #include "nsIFile.h"
 #include "nsINIParser.h"
 #include "nsXPCOMGlue.h"
 #include "nsXPCOMPrivate.h"              // for MAXPATHLEN and XPCOM_DLL
 #include "nsXULAppAPI.h"
 #include "BinaryPath.h"
+#include "buildid.h"
 
 const char kAPP_INI[] = "application.ini";
 const char kWEBAPP_INI[] = "webapp.ini";
 const char kWEBAPP_JSON[] = "webapp.json";
 const char kWEBAPP_PACKAGE[] = "application.zip";
 const char kWEBAPPRT_INI[] = "webapprt.ini";
 const char kWEBAPPRT_PATH[] = "webapprt";
 const char kAPP_ENV_VAR[] = "XUL_APP_FILE";
--- a/webapprt/mac/Makefile.in
+++ b/webapprt/mac/Makefile.in
@@ -2,15 +2,8 @@
 # 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/.
 
 # This switches $(INSTALL) to copy mode, like $(SYSINSTALL), so things that
 # shouldn't get 755 perms need $(IFLAGS1) for either way of calling nsinstall.
 NSDISTMODE = copy
 
 PROGRAMS_DEST = $(DIST)/bin
-
-include $(topsrcdir)/config/rules.mk
-
-MOZ_BUILDID := $(shell cat $(DEPTH)/config/buildid)
-DEFINES += -DMOZ_BUILDID=$(MOZ_BUILDID)
-
-webapprt.$(OBJ_SUFFIX): $(DEPTH)/config/buildid
--- a/webapprt/mac/webapprt.mm
+++ b/webapprt/mac/webapprt.mm
@@ -24,16 +24,17 @@
 #include "nsINIParser.h"
 #include "nsXPCOMPrivate.h"              // for MAXPATHLEN and XPCOM_DLL
 #include "nsXULAppAPI.h"
 #include "nsComponentManagerUtils.h"
 #include "nsCOMPtr.h"
 #include "nsIFile.h"
 #include "nsStringGlue.h"
 #include "mozilla/AppData.h"
+#include "buildid.h"
 
 using namespace mozilla;
 
 const char WEBAPPRT_EXECUTABLE[] = "webapprt-stub";
 const char FXAPPINI_NAME[] = "application.ini";
 const char WEBAPPINI_NAME[] = "webapp.ini";
 const char WEBRTINI_NAME[] = "webapprt.ini";
 
--- a/webapprt/moz.build
+++ b/webapprt/moz.build
@@ -52,8 +52,10 @@ JAR_MANIFESTS += ['jar.mn']
 
 JS_PREFERENCE_PP_FILES += [
     'prefs.js',
 ]
 
 FINAL_TARGET_PP_FILES += [
     'webapprt.ini',
 ]
+
+DEFINES['TOPOBJDIR'] = TOPOBJDIR
--- a/webapprt/webapprt.ini
+++ b/webapprt/webapprt.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
 
 [App]
 ID=webapprt@mozilla.org
 Vendor=Mozilla
 ; Note: the Windows stub executable sets nsXREAppData::name to the webapp
 ; origin, overriding the value below, to make the app runner treat webapps
 ; as distinct products, per bug 747409.
 Name=Webapp Runtime
--- a/webapprt/win/Makefile.in
+++ b/webapprt/win/Makefile.in
@@ -43,13 +43,8 @@ libs::
 	$(MAKE) webapp_uninstaller
 
 GARBAGE_DIRS += instgen
 
 PROGRAMS_DEST = $(DIST)/bin
 
 include $(topsrcdir)/config/rules.mk
 include $(topsrcdir)/toolkit/mozapps/installer/windows/nsis/makensis.mk
-
-MOZ_BUILDID := $(shell cat $(DEPTH)/config/buildid)
-DEFINES += -DMOZ_BUILDID=$(MOZ_BUILDID)
-
-webapprt.$(OBJ_SUFFIX): $(DEPTH)/config/buildid
--- a/webapprt/win/webapprt.cpp
+++ b/webapprt/win/webapprt.cpp
@@ -14,16 +14,17 @@
 // Mozilla headers (alphabetical)
 #include "nsIFile.h"
 #include "nsINIParser.h"
 #include "nsWindowsWMain.cpp"   // we want a wmain entry point
 #include "nsXPCOMGlue.h"
 #include "nsXPCOMPrivate.h"     // for MAXPATHLEN and XPCOM_DLL
 #include "nsXULAppAPI.h"
 #include "mozilla/AppData.h"
+#include "buildid.h"
 
 using namespace mozilla;
 
 XRE_GetFileFromPathType XRE_GetFileFromPath;
 XRE_CreateAppDataType XRE_CreateAppData;
 XRE_FreeAppDataType XRE_FreeAppData;
 XRE_mainType XRE_main;