Magnus Ihse Bursie | b58f0c9 | 2016-11-28 09:20:13 +0100 | [diff] [blame] | 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 | |
| 26 | default: all |
| 27 | |
| 28 | include $(SPEC) |
| 29 | include MakeBase.gmk |
| 30 | |
Magnus Ihse Bursie | 5f7dcca | 2017-10-05 12:41:06 +0200 | [diff] [blame] | 31 | $(eval $(call IncludeCustomExtension, SourceRevision.gmk)) |
Erik Joelsson | 72c4ec5 | 2017-09-12 19:03:56 +0200 | [diff] [blame] | 32 | |
Magnus Ihse Bursie | b58f0c9 | 2016-11-28 09:20:13 +0100 | [diff] [blame] | 33 | ################################################################################ |
| 34 | # Keep track of what source revision is used to create the build, by creating |
| 35 | # a tracker file in the output directory. This tracker file is included in the |
| 36 | # image, and can be used to recreate the source revision used. |
| 37 | # |
| 38 | # We're either building directly from a mercurial forest, and if so, use the |
| 39 | # current revision from mercurial. Otherwise, we are building from a source |
| 40 | # bundle. As a part of creating this source bundle, the current mercurial |
| 41 | # revisions of all repos will be stored in a file in the top dir, which is then |
| 42 | # used when creating the tracker file. |
| 43 | |
| 44 | STORED_SOURCE_REVISION := $(TOPDIR)/.src-rev |
| 45 | |
| 46 | # Are we using mercurial? |
| 47 | ifneq ($(and $(HG), $(wildcard $(TOPDIR)/.hg)), ) |
| 48 | |
| 49 | # Verify that the entire forest is consistent |
| 50 | $(foreach repo, $(call FindAllReposRel), \ |
| 51 | $(if $(wildcard $(TOPDIR)/$(repo)/.hg),, \ |
| 52 | $(error Inconsistent revision control: $(repo) is missing .hg directory)) \ |
| 53 | ) |
| 54 | |
| 55 | # Replace "." with "_top" and "/" with "-" |
| 56 | MakeFilenameFromRepo = \ |
| 57 | $(strip $(subst .,top, $(subst /,-, $1))) |
| 58 | |
| 59 | ################################################################################ |
| 60 | # SetupGetRevisionForRepo defines a make rule for creating a file containing |
| 61 | # the name of the repository and the output of "hg id" for that repository. |
| 62 | # Argument 1 is the relative path to the repository from the top dir. |
| 63 | # |
| 64 | SetupGetRevisionForRepo = $(NamedParamsMacroTemplate) |
| 65 | define SetupGetRevisionForRepoBody |
| 66 | $1_REPO_PATH := $$(TOPDIR)/$$(strip $1) |
| 67 | $1_FILENAME := $$(call MakeFilenameFromRepo, $1) |
| 68 | |
| 69 | $$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME): FRC |
Magnus Ihse Bursie | bac0ea6 | 2016-11-28 10:13:18 +0100 | [diff] [blame] | 70 | $$(call MakeDir, $$(@D)) |
| 71 | $$(ECHO) $$(strip $1):`$$(HG) id -i --repository $$($1_REPO_PATH)` > $$@ |
Magnus Ihse Bursie | b58f0c9 | 2016-11-28 09:20:13 +0100 | [diff] [blame] | 72 | |
| 73 | REPO_REVISIONS += $$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME) |
| 74 | endef |
| 75 | |
| 76 | # Setup rules for all repos. This makes sure all the "hg id" calls are made |
| 77 | # in parallel. |
| 78 | $(foreach repo, $(call FindAllReposRel), \ |
| 79 | $(eval $(call SetupGetRevisionForRepo, $(repo))) \ |
| 80 | ) |
| 81 | |
| 82 | # Create a complete source revision output file from all repos |
| 83 | # Param 1: The output file |
| 84 | define CreateSourceRevisionFile |
| 85 | $1: $$(REPO_REVISIONS) |
Magnus Ihse Bursie | bac0ea6 | 2016-11-28 10:13:18 +0100 | [diff] [blame] | 86 | $$(call MakeDir, $$(@D)) |
Magnus Ihse Bursie | b58f0c9 | 2016-11-28 09:20:13 +0100 | [diff] [blame] | 87 | $$(ECHO) `$$(CAT) $$(REPO_REVISIONS)` > $$@.tmp |
| 88 | if [ ! -f $$@ ] || [ "`$$(CAT) $$@`" != "`$$(CAT) $$@.tmp`" ]; then \ |
| 89 | $$(MV) $$@.tmp $$@ ; \ |
| 90 | else \ |
| 91 | $$(RM) $$@.tmp ; \ |
| 92 | fi |
| 93 | endef |
| 94 | |
| 95 | $(eval $(call CreateSourceRevisionFile, $(STORED_SOURCE_REVISION))) |
| 96 | |
| 97 | store-source-revision: $(STORED_SOURCE_REVISION) |
| 98 | |
| 99 | $(eval $(call CreateSourceRevisionFile, $(SOURCE_REVISION_TRACKER))) |
| 100 | |
| 101 | create-source-revision-tracker: $(SOURCE_REVISION_TRACKER) |
| 102 | |
| 103 | else |
| 104 | # Not using HG |
| 105 | |
| 106 | ifneq ($(wildcard $(STORED_SOURCE_REVISION)), ) |
| 107 | # We have a stored source revision (.src-rev) |
| 108 | |
| 109 | store-source-revision: |
Erik Joelsson | d8f522b | 2016-12-21 13:30:35 +0100 | [diff] [blame] | 110 | $(call LogInfo, No mercurial configuration present$(COMMA) not updating .src-rev) |
Magnus Ihse Bursie | b58f0c9 | 2016-11-28 09:20:13 +0100 | [diff] [blame] | 111 | |
| 112 | $(SOURCE_REVISION_TRACKER): $(STORED_SOURCE_REVISION) |
| 113 | $(install-file) |
| 114 | |
| 115 | create-source-revision-tracker: $(SOURCE_REVISION_TRACKER) |
| 116 | else |
| 117 | # We don't have a stored source revision. Can't do anything, really. |
| 118 | |
| 119 | store-source-revision: |
Erik Joelsson | d8f522b | 2016-12-21 13:30:35 +0100 | [diff] [blame] | 120 | $(call LogWarn, Error: No mercurial configuration present$(COMMA) cannot create .src-rev) |
Magnus Ihse Bursie | b58f0c9 | 2016-11-28 09:20:13 +0100 | [diff] [blame] | 121 | exit 2 |
| 122 | |
| 123 | create-source-revision-tracker: |
Erik Joelsson | ffc4d62 | 2016-11-28 15:19:08 +0100 | [diff] [blame] | 124 | $(call LogWarn, Warning: No mercurial configuration present and no .src-rev) |
Magnus Ihse Bursie | b58f0c9 | 2016-11-28 09:20:13 +0100 | [diff] [blame] | 125 | endif |
| 126 | |
| 127 | endif |
| 128 | |
| 129 | all: store-source-revision create-source-revision-tracker |
| 130 | |
| 131 | FRC: # Force target |
| 132 | |
| 133 | .PHONY: all store-source-revision create-source-revision-tracker |