2016-11-28 08:20:13 +00:00
|
|
|
#
|
2024-04-11 14:15:34 +00:00
|
|
|
# Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
|
2016-11-28 08:20:13 +00:00
|
|
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
#
|
|
|
|
# This code is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License version 2 only, as
|
|
|
|
# published by the Free Software Foundation. Oracle designates this
|
|
|
|
# particular file as subject to the "Classpath" exception as provided
|
|
|
|
# by Oracle in the LICENSE file that accompanied this code.
|
|
|
|
#
|
|
|
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
# version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
# accompanied this code).
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License version
|
|
|
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
# or visit www.oracle.com if you need additional information or have any
|
|
|
|
# questions.
|
|
|
|
#
|
|
|
|
|
|
|
|
include $(SPEC)
|
|
|
|
include MakeBase.gmk
|
|
|
|
|
2018-08-28 22:17:52 +00:00
|
|
|
$(eval $(call IncludeCustomExtension, SourceRevision-pre.gmk))
|
2017-09-12 17:03:56 +00:00
|
|
|
|
2016-11-28 08:20:13 +00:00
|
|
|
################################################################################
|
|
|
|
# Keep track of what source revision is used to create the build, by creating
|
|
|
|
# a tracker file in the output directory. This tracker file is included in the
|
2018-09-07 21:54:15 +00:00
|
|
|
# source image, and can be used to recreate the source revision used.
|
2016-11-28 08:20:13 +00:00
|
|
|
#
|
2018-09-07 21:54:15 +00:00
|
|
|
# We're either building directly from an SCM repository, and if so, use the
|
|
|
|
# current revision from that SCM. Otherwise, we are building from a source
|
|
|
|
# bundle. As a part of creating this source bundle, the current SCM revisions of
|
|
|
|
# all repos will be stored in a file in the top dir, which is then used when
|
|
|
|
# creating the tracker file.
|
2016-11-28 08:20:13 +00:00
|
|
|
|
|
|
|
STORED_SOURCE_REVISION := $(TOPDIR)/.src-rev
|
|
|
|
|
2024-04-11 14:15:34 +00:00
|
|
|
# Locate all sourcecode repositories included in the forest, as absolute paths
|
|
|
|
FindAllReposAbs = \
|
|
|
|
$(strip $(sort $(dir $(filter-out $(TOPDIR)/build/%, $(wildcard \
|
|
|
|
$(addprefix $(TOPDIR)/, .git */.git */*/.git */*/*/.git */*/*/*/.git) \
|
|
|
|
)))))
|
|
|
|
|
|
|
|
# Locate all sourcecode repositories included in the forest, as relative paths
|
|
|
|
FindAllReposRel = \
|
|
|
|
$(strip $(subst $(TOPDIR)/,.,$(patsubst $(TOPDIR)/%/, %, $(FindAllReposAbs))))
|
|
|
|
|
2018-09-07 21:54:15 +00:00
|
|
|
USE_SCM := false
|
2022-10-05 07:25:49 +00:00
|
|
|
ifneq ($(and $(GIT), $(wildcard $(TOPDIR)/.git)), )
|
2018-09-07 21:54:15 +00:00
|
|
|
USE_SCM := true
|
|
|
|
SCM_DIR := .git
|
|
|
|
ID_COMMAND := $(PRINTF) "git:%s%s\n" \
|
2022-05-05 00:27:42 +00:00
|
|
|
"$$($(GIT) log -n1 --format=%H | cut -c1-12)" \
|
|
|
|
"$$(if test -n "$$($(GIT) status --porcelain)"; then printf '+'; fi)"
|
2018-09-07 21:54:15 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(USE_SCM), true)
|
2016-11-28 08:20:13 +00:00
|
|
|
|
|
|
|
# Verify that the entire forest is consistent
|
|
|
|
$(foreach repo, $(call FindAllReposRel), \
|
2024-09-03 15:31:09 +00:00
|
|
|
$(if $(wildcard $(TOPDIR)/$(repo)/$(SCM_DIR)), , \
|
2018-09-07 21:54:15 +00:00
|
|
|
$(error Inconsistent revision control: $(repo) is missing $(SCM_DIR) directory)) \
|
2016-11-28 08:20:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Replace "." with "_top" and "/" with "-"
|
|
|
|
MakeFilenameFromRepo = \
|
|
|
|
$(strip $(subst .,top, $(subst /,-, $1)))
|
|
|
|
|
2024-09-03 15:31:09 +00:00
|
|
|
##############################################################################
|
2016-11-28 08:20:13 +00:00
|
|
|
# SetupGetRevisionForRepo defines a make rule for creating a file containing
|
2018-09-07 21:54:15 +00:00
|
|
|
# the name of the repository and the output of the scm command for that
|
|
|
|
# repository.
|
|
|
|
#
|
2016-11-28 08:20:13 +00:00
|
|
|
# Argument 1 is the relative path to the repository from the top dir.
|
|
|
|
#
|
|
|
|
SetupGetRevisionForRepo = $(NamedParamsMacroTemplate)
|
|
|
|
define SetupGetRevisionForRepoBody
|
|
|
|
$1_REPO_PATH := $$(TOPDIR)/$$(strip $1)
|
|
|
|
$1_FILENAME := $$(call MakeFilenameFromRepo, $1)
|
|
|
|
|
|
|
|
$$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME): FRC
|
2016-11-28 09:13:18 +00:00
|
|
|
$$(call MakeDir, $$(@D))
|
2018-09-07 21:54:15 +00:00
|
|
|
$$(ECHO) $$(strip $1):`$$(CD) $$($1_REPO_PATH) && $$(ID_COMMAND)` > $$@
|
2016-11-28 08:20:13 +00:00
|
|
|
|
|
|
|
REPO_REVISIONS += $$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME)
|
|
|
|
endef
|
|
|
|
|
2022-10-05 07:25:49 +00:00
|
|
|
# Setup rules for all repos. This makes sure all the "git log" calls are made
|
2016-11-28 08:20:13 +00:00
|
|
|
# in parallel.
|
|
|
|
$(foreach repo, $(call FindAllReposRel), \
|
|
|
|
$(eval $(call SetupGetRevisionForRepo, $(repo))) \
|
|
|
|
)
|
|
|
|
|
|
|
|
# Create a complete source revision output file from all repos
|
|
|
|
# Param 1: The output file
|
|
|
|
define CreateSourceRevisionFile
|
|
|
|
$1: $$(REPO_REVISIONS)
|
2016-11-28 09:13:18 +00:00
|
|
|
$$(call MakeDir, $$(@D))
|
2016-11-28 08:20:13 +00:00
|
|
|
$$(ECHO) `$$(CAT) $$(REPO_REVISIONS)` > $$@.tmp
|
|
|
|
if [ ! -f $$@ ] || [ "`$$(CAT) $$@`" != "`$$(CAT) $$@.tmp`" ]; then \
|
|
|
|
$$(MV) $$@.tmp $$@ ; \
|
|
|
|
else \
|
|
|
|
$$(RM) $$@.tmp ; \
|
|
|
|
fi
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(eval $(call CreateSourceRevisionFile, $(STORED_SOURCE_REVISION)))
|
|
|
|
|
2018-09-07 21:54:15 +00:00
|
|
|
scm-store-source-revision: $(STORED_SOURCE_REVISION)
|
2016-11-28 08:20:13 +00:00
|
|
|
|
|
|
|
$(eval $(call CreateSourceRevisionFile, $(SOURCE_REVISION_TRACKER)))
|
|
|
|
|
2018-09-07 21:54:15 +00:00
|
|
|
scm-create-source-revision-tracker: $(SOURCE_REVISION_TRACKER)
|
2018-08-28 22:17:52 +00:00
|
|
|
|
2018-09-07 21:54:15 +00:00
|
|
|
STORE_SOURCE_REVISION_TARGET := scm-store-source-revision
|
|
|
|
CREATE_SOURCE_REVISION_TRACKER_TARGET := scm-create-source-revision-tracker
|
|
|
|
|
|
|
|
.PHONY: scm-store-source-revision scm-create-source-revision-tracker
|
2016-11-28 08:20:13 +00:00
|
|
|
|
|
|
|
else
|
2018-09-07 21:54:15 +00:00
|
|
|
# Not using any SCM
|
2016-11-28 08:20:13 +00:00
|
|
|
|
|
|
|
ifneq ($(wildcard $(STORED_SOURCE_REVISION)), )
|
|
|
|
# We have a stored source revision (.src-rev)
|
|
|
|
|
2018-08-28 22:17:52 +00:00
|
|
|
src-store-source-revision:
|
2018-09-07 21:54:15 +00:00
|
|
|
$(call LogInfo, No SCM configuration present$(COMMA) not updating .src-rev)
|
2016-11-28 08:20:13 +00:00
|
|
|
|
|
|
|
$(SOURCE_REVISION_TRACKER): $(STORED_SOURCE_REVISION)
|
|
|
|
$(install-file)
|
|
|
|
|
2018-08-28 22:17:52 +00:00
|
|
|
src-create-source-revision-tracker: $(SOURCE_REVISION_TRACKER)
|
2016-11-28 08:20:13 +00:00
|
|
|
else
|
|
|
|
# We don't have a stored source revision. Can't do anything, really.
|
|
|
|
|
2018-08-28 22:17:52 +00:00
|
|
|
src-store-source-revision:
|
2018-09-07 21:54:15 +00:00
|
|
|
$(call LogWarn, Error: No SCM configuration present$(COMMA) cannot create .src-rev)
|
2016-11-28 08:20:13 +00:00
|
|
|
exit 2
|
|
|
|
|
2018-08-28 22:17:52 +00:00
|
|
|
src-create-source-revision-tracker:
|
2018-09-07 21:54:15 +00:00
|
|
|
$(call LogWarn, Warning: No SCM configuration present and no .src-rev)
|
2016-11-28 08:20:13 +00:00
|
|
|
endif
|
|
|
|
|
2018-08-28 22:17:52 +00:00
|
|
|
STORE_SOURCE_REVISION_TARGET := src-store-source-revision
|
|
|
|
CREATE_SOURCE_REVISION_TRACKER_TARGET := src-create-source-revision-tracker
|
|
|
|
|
2018-09-07 21:54:15 +00:00
|
|
|
.PHONY: src-store-source-revision src-create-source-revision-tracker
|
|
|
|
|
2016-11-28 08:20:13 +00:00
|
|
|
endif
|
|
|
|
|
2018-08-28 22:17:52 +00:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
$(eval $(call IncludeCustomExtension, SourceRevision-post.gmk))
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
store-source-revision: $(STORE_SOURCE_REVISION_TARGET)
|
|
|
|
|
|
|
|
create-source-revision-tracker: $(CREATE_SOURCE_REVISION_TRACKER_TARGET)
|
2016-11-28 08:20:13 +00:00
|
|
|
|
|
|
|
FRC: # Force target
|
|
|
|
|
2018-08-28 22:17:52 +00:00
|
|
|
.PHONY: store-source-revision create-source-revision-tracker
|