SourceRevision.gmk revision 2342:61d55f2ba01e
1# 2# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4# 5# This code is free software; you can redistribute it and/or modify it 6# under the terms of the GNU General Public License version 2 only, as 7# published by the Free Software Foundation. Oracle designates this 8# particular file as subject to the "Classpath" exception as provided 9# by Oracle in the LICENSE file that accompanied this code. 10# 11# This code is distributed in the hope that it will be useful, but WITHOUT 12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14# version 2 for more details (a copy is included in the LICENSE file that 15# accompanied this code). 16# 17# You should have received a copy of the GNU General Public License version 18# 2 along with this work; if not, write to the Free Software Foundation, 19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20# 21# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22# or visit www.oracle.com if you need additional information or have any 23# questions. 24# 25 26default: all 27 28include $(SPEC) 29include MakeBase.gmk 30 31################################################################################ 32# Keep track of what source revision is used to create the build, by creating 33# a tracker file in the output directory. This tracker file is included in the 34# image, and can be used to recreate the source revision used. 35# 36# We're either building directly from a mercurial forest, and if so, use the 37# current revision from mercurial. Otherwise, we are building from a source 38# bundle. As a part of creating this source bundle, the current mercurial 39# revisions of all repos will be stored in a file in the top dir, which is then 40# used when creating the tracker file. 41 42STORED_SOURCE_REVISION := $(TOPDIR)/.src-rev 43 44# Are we using mercurial? 45ifneq ($(and $(HG), $(wildcard $(TOPDIR)/.hg)), ) 46 47 # Verify that the entire forest is consistent 48 $(foreach repo, $(call FindAllReposRel), \ 49 $(if $(wildcard $(TOPDIR)/$(repo)/.hg),, \ 50 $(error Inconsistent revision control: $(repo) is missing .hg directory)) \ 51 ) 52 53 # Replace "." with "_top" and "/" with "-" 54 MakeFilenameFromRepo = \ 55 $(strip $(subst .,top, $(subst /,-, $1))) 56 57 ################################################################################ 58 # SetupGetRevisionForRepo defines a make rule for creating a file containing 59 # the name of the repository and the output of "hg id" for that repository. 60 # Argument 1 is the relative path to the repository from the top dir. 61 # 62 SetupGetRevisionForRepo = $(NamedParamsMacroTemplate) 63 define SetupGetRevisionForRepoBody 64 $1_REPO_PATH := $$(TOPDIR)/$$(strip $1) 65 $1_FILENAME := $$(call MakeFilenameFromRepo, $1) 66 67 $$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME): FRC 68 $(call MakeDir $$(@D)) 69 $(ECHO) $$(strip $1):`$(HG) id -i --repository $$($1_REPO_PATH)` > $$@ 70 71 REPO_REVISIONS += $$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME) 72 endef 73 74 # Setup rules for all repos. This makes sure all the "hg id" calls are made 75 # in parallel. 76 $(foreach repo, $(call FindAllReposRel), \ 77 $(eval $(call SetupGetRevisionForRepo, $(repo))) \ 78 ) 79 80 # Create a complete source revision output file from all repos 81 # Param 1: The output file 82 define CreateSourceRevisionFile 83 $1: $$(REPO_REVISIONS) 84 $(call MakeDir $$(@D)) 85 $$(ECHO) `$$(CAT) $$(REPO_REVISIONS)` > $$@.tmp 86 if [ ! -f $$@ ] || [ "`$$(CAT) $$@`" != "`$$(CAT) $$@.tmp`" ]; then \ 87 $$(MV) $$@.tmp $$@ ; \ 88 else \ 89 $$(RM) $$@.tmp ; \ 90 fi 91 endef 92 93 $(eval $(call CreateSourceRevisionFile, $(STORED_SOURCE_REVISION))) 94 95 store-source-revision: $(STORED_SOURCE_REVISION) 96 97 $(eval $(call CreateSourceRevisionFile, $(SOURCE_REVISION_TRACKER))) 98 99 create-source-revision-tracker: $(SOURCE_REVISION_TRACKER) 100 101else 102 # Not using HG 103 104 ifneq ($(wildcard $(STORED_SOURCE_REVISION)), ) 105 # We have a stored source revision (.src-rev) 106 107 store-source-revision: 108 $(call LogWarn, Warning: No mercurial configuration present, not updating .src-rev) 109 110 $(SOURCE_REVISION_TRACKER): $(STORED_SOURCE_REVISION) 111 $(install-file) 112 113 create-source-revision-tracker: $(SOURCE_REVISION_TRACKER) 114 else 115 # We don't have a stored source revision. Can't do anything, really. 116 117 store-source-revision: 118 $(call LogWarn, Error: No mercurial configuration present, cannot create .src-rev) 119 exit 2 120 121 create-source-revision-tracker: 122 $(call LogWarn, Error: No mercurial configuration present and no .src-rev) 123 exit 2 124 endif 125 126endif 127 128all: store-source-revision create-source-revision-tracker 129 130FRC: # Force target 131 132.PHONY: all store-source-revision create-source-revision-tracker 133