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.
This commit is contained in:
Mike Hommey 2016-02-10 13:38:31 +09:00
parent 22dd1b2230
commit 635d33e292
20 changed files with 75 additions and 155 deletions

View File

@ -31,7 +31,7 @@ DIST_GARBAGE = config.cache config.log config.status* config-defs.h \
.mozconfig.mk
ifndef MOZ_PROFILE_USE
buildid.h: FORCE
buildid.h source-repo.h: FORCE
endif
ifdef JS_STANDALONE
@ -315,12 +315,6 @@ ifdef SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE
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

View File

@ -2,9 +2,6 @@
# 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

View File

@ -10,19 +10,6 @@ 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.

View File

@ -16,6 +16,7 @@
#endif
#filter substitution
#include @TOPOBJDIR@/buildid.h
#include @TOPOBJDIR@/source-repo.h
[App]
Vendor=@MOZ_APP_VENDOR@
Name=@MOZ_APP_BASENAME@

View File

@ -5,6 +5,7 @@
from __future__ import print_function, unicode_literals
import os
import subprocess
import sys
from datetime import datetime
@ -19,6 +20,53 @@ def buildid_header(output):
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)
def main(args):
if (len(args)):
func = globals().get(args[0])

View File

@ -117,9 +117,5 @@ 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 -)

View File

@ -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 #}

View File

@ -8724,15 +8724,8 @@ 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

View File

@ -33,13 +33,16 @@ if not CONFIG['JS_STANDALONE']:
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',

View File

@ -3,9 +3,6 @@
# 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.

View File

@ -3,24 +3,7 @@
# 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

View File

@ -4,6 +4,7 @@
# 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">
@ -18,14 +19,9 @@
</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>

View File

@ -31,3 +31,5 @@ with Files('customizeToolbar.*'):
with Files('widgets/*'):
BUG_COMPONENT = ('Toolkit', 'XUL Widgets')
DEFINES['TOPOBJDIR'] = TOPOBJDIR

View File

@ -1,4 +1,5 @@
#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/. */
@ -308,7 +309,10 @@ this.AppConstants = Object.freeze({
// 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

View File

@ -118,8 +118,7 @@ for var in ('ANDROID_PACKAGE_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',
@ -128,3 +127,5 @@ for var in ('MOZ_TOOLKIT_SEARCH',
'MOZ_UPDATER'):
if CONFIG[var]:
DEFINES[var] = True
DEFINES['TOPOBJDIR'] = TOPOBJDIR

View File

@ -156,16 +156,6 @@ ifndef INCLUDED_RCS_MK
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

View File

@ -96,8 +96,8 @@ 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
@ -105,8 +105,8 @@ 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

View File

@ -198,8 +198,8 @@ RPM_CMD = \
--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)' \

View File

@ -5,29 +5,10 @@
# 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)

View File

@ -5,6 +5,7 @@
#endif
#filter substitution
#include @TOPOBJDIR@/buildid.h
#include @TOPOBJDIR@/source-repo.h
[Build]
BuildID=@MOZ_BUILDID@
Milestone=@GRE_MILESTONE@