SourceRevision.gmk revision 2409:acf8119d2b86
1222578Shselasky# 2222578Shselasky# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3222578Shselasky# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4222578Shselasky# 5222578Shselasky# This code is free software; you can redistribute it and/or modify it 6222578Shselasky# under the terms of the GNU General Public License version 2 only, as 7222578Shselasky# published by the Free Software Foundation. Oracle designates this 8222578Shselasky# particular file as subject to the "Classpath" exception as provided 9222578Shselasky# by Oracle in the LICENSE file that accompanied this code. 10222578Shselasky# 11222578Shselasky# This code is distributed in the hope that it will be useful, but WITHOUT 12222578Shselasky# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13222578Shselasky# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14222578Shselasky# version 2 for more details (a copy is included in the LICENSE file that 15222578Shselasky# accompanied this code). 16222578Shselasky# 17222578Shselasky# You should have received a copy of the GNU General Public License version 18222578Shselasky# 2 along with this work; if not, write to the Free Software Foundation, 19222578Shselasky# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20222578Shselasky# 21222578Shselasky# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22222578Shselasky# or visit www.oracle.com if you need additional information or have any 23222578Shselasky# questions. 24222578Shselasky# 25222578Shselasky 26222578Shselaskydefault: all 27222578Shselasky 28222578Shselaskyinclude $(SPEC) 29222578Shselaskyinclude MakeBase.gmk 30222578Shselasky 31222578Shselasky################################################################################ 32222578Shselasky# Keep track of what source revision is used to create the build, by creating 33222578Shselasky# a tracker file in the output directory. This tracker file is included in the 34222578Shselasky# image, and can be used to recreate the source revision used. 35222578Shselasky# 36222578Shselasky# We're either building directly from a mercurial forest, and if so, use the 37222578Shselasky# current revision from mercurial. Otherwise, we are building from a source 38222578Shselasky# bundle. As a part of creating this source bundle, the current mercurial 39222578Shselasky# revisions of all repos will be stored in a file in the top dir, which is then 40222578Shselasky# used when creating the tracker file. 41222578Shselasky 42222578ShselaskySTORED_SOURCE_REVISION := $(TOPDIR)/.src-rev 43222578Shselasky 44222578Shselasky# Are we using mercurial? 45222578Shselaskyifneq ($(and $(HG), $(wildcard $(TOPDIR)/.hg)), ) 46222578Shselasky 47222578Shselasky # Verify that the entire forest is consistent 48222578Shselasky $(foreach repo, $(call FindAllReposRel), \ 49222578Shselasky $(if $(wildcard $(TOPDIR)/$(repo)/.hg),, \ 50222578Shselasky $(error Inconsistent revision control: $(repo) is missing .hg directory)) \ 51222578Shselasky ) 52222578Shselasky 53222578Shselasky # Replace "." with "_top" and "/" with "-" 54222578Shselasky MakeFilenameFromRepo = \ 55222578Shselasky $(strip $(subst .,top, $(subst /,-, $1))) 56222578Shselasky 57222578Shselasky ################################################################################ 58222578Shselasky # SetupGetRevisionForRepo defines a make rule for creating a file containing 59222578Shselasky # the name of the repository and the output of "hg id" for that repository. 60222578Shselasky # Argument 1 is the relative path to the repository from the top dir. 61222578Shselasky # 62222578Shselasky SetupGetRevisionForRepo = $(NamedParamsMacroTemplate) 63222578Shselasky define SetupGetRevisionForRepoBody 64222578Shselasky $1_REPO_PATH := $$(TOPDIR)/$$(strip $1) 65222578Shselasky $1_FILENAME := $$(call MakeFilenameFromRepo, $1) 66222578Shselasky 67222578Shselasky $$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME): FRC 68222578Shselasky $$(call MakeDir, $$(@D)) 69222696Shselasky $$(ECHO) $$(strip $1):`$$(HG) id -i --repository $$($1_REPO_PATH)` > $$@ 70222578Shselasky 71222578Shselasky REPO_REVISIONS += $$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME) 72222578Shselasky endef 73222578Shselasky 74222578Shselasky # Setup rules for all repos. This makes sure all the "hg id" calls are made 75222696Shselasky # in parallel. 76222578Shselasky $(foreach repo, $(call FindAllReposRel), \ 77222578Shselasky $(eval $(call SetupGetRevisionForRepo, $(repo))) \ 78222578Shselasky ) 79222578Shselasky 80222696Shselasky # Create a complete source revision output file from all repos 81222578Shselasky # Param 1: The output file 82222696Shselasky define CreateSourceRevisionFile 83222696Shselasky $1: $$(REPO_REVISIONS) 84222578Shselasky $$(call MakeDir, $$(@D)) 85222578Shselasky $$(ECHO) `$$(CAT) $$(REPO_REVISIONS)` > $$@.tmp 86222578Shselasky if [ ! -f $$@ ] || [ "`$$(CAT) $$@`" != "`$$(CAT) $$@.tmp`" ]; then \ 87222578Shselasky $$(MV) $$@.tmp $$@ ; \ 88222578Shselasky else \ 89222578Shselasky $$(RM) $$@.tmp ; \ 90222578Shselasky fi 91222578Shselasky endef 92222578Shselasky 93222578Shselasky $(eval $(call CreateSourceRevisionFile, $(STORED_SOURCE_REVISION))) 94222578Shselasky 95222578Shselasky store-source-revision: $(STORED_SOURCE_REVISION) 96222578Shselasky 97222578Shselasky $(eval $(call CreateSourceRevisionFile, $(SOURCE_REVISION_TRACKER))) 98222578Shselasky 99222578Shselasky create-source-revision-tracker: $(SOURCE_REVISION_TRACKER) 100222578Shselasky 101222578Shselaskyelse 102222578Shselasky # Not using HG 103222578Shselasky 104222578Shselasky ifneq ($(wildcard $(STORED_SOURCE_REVISION)), ) 105222578Shselasky # We have a stored source revision (.src-rev) 106222578Shselasky 107222578Shselasky store-source-revision: 108222578Shselasky $(call LogInfo, No mercurial configuration present$(COMMA) not updating .src-rev) 109222578Shselasky 110222578Shselasky $(SOURCE_REVISION_TRACKER): $(STORED_SOURCE_REVISION) 111222578Shselasky $(install-file) 112222578Shselasky 113222578Shselasky create-source-revision-tracker: $(SOURCE_REVISION_TRACKER) 114222578Shselasky else 115222578Shselasky # We don't have a stored source revision. Can't do anything, really. 116222578Shselasky 117222578Shselasky store-source-revision: 118222578Shselasky $(call LogWarn, Error: No mercurial configuration present$(COMMA) cannot create .src-rev) 119222578Shselasky exit 2 120222578Shselasky 121222578Shselasky create-source-revision-tracker: 122222578Shselasky $(call LogWarn, Warning: No mercurial configuration present and no .src-rev) 123222578Shselasky endif 124222578Shselasky 125222578Shselaskyendif 126222578Shselasky 127222578Shselaskyall: store-source-revision create-source-revision-tracker 128222578Shselasky 129222578ShselaskyFRC: # Force target 130222578Shselasky 131222578Shselasky.PHONY: all store-source-revision create-source-revision-tracker 132222578Shselasky