jdk

Форк
0
/
SourceRevision.gmk 
169 строк · 6.1 Кб
1
#
2
# Copyright (c) 2016, 2024, 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
include $(SPEC)
27
include MakeBase.gmk
28

29
$(eval $(call IncludeCustomExtension, SourceRevision-pre.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
# source image, and can be used to recreate the source revision used.
35
#
36
# We're either building directly from an SCM repository, and if so, use the
37
# current revision from that SCM. Otherwise, we are building from a source
38
# bundle. As a part of creating this source bundle, the current SCM revisions of
39
# all repos will be stored in a file in the top dir, which is then used when
40
# creating the tracker file.
41

42
STORED_SOURCE_REVISION := $(TOPDIR)/.src-rev
43

44
# Locate all sourcecode repositories included in the forest, as absolute paths
45
FindAllReposAbs = \
46
    $(strip $(sort $(dir $(filter-out $(TOPDIR)/build/%, $(wildcard \
47
        $(addprefix $(TOPDIR)/, .git */.git */*/.git */*/*/.git */*/*/*/.git) \
48
    )))))
49

50
# Locate all sourcecode repositories included in the forest, as relative paths
51
FindAllReposRel = \
52
    $(strip $(subst $(TOPDIR)/,.,$(patsubst $(TOPDIR)/%/, %, $(FindAllReposAbs))))
53

54
USE_SCM := false
55
ifneq ($(and $(GIT), $(wildcard $(TOPDIR)/.git)), )
56
  USE_SCM := true
57
  SCM_DIR := .git
58
  ID_COMMAND := $(PRINTF) "git:%s%s\n" \
59
      "$$($(GIT) log -n1 --format=%H | cut -c1-12)" \
60
      "$$(if test -n "$$($(GIT) status --porcelain)"; then printf '+'; fi)"
61
endif
62

63
ifeq ($(USE_SCM), true)
64

65
  # Verify that the entire forest is consistent
66
  $(foreach repo, $(call FindAllReposRel), \
67
    $(if $(wildcard $(TOPDIR)/$(repo)/$(SCM_DIR)),, \
68
        $(error Inconsistent revision control: $(repo) is missing $(SCM_DIR) directory)) \
69
  )
70

71
  # Replace "." with "_top" and "/" with "-"
72
  MakeFilenameFromRepo = \
73
      $(strip $(subst .,top, $(subst /,-, $1)))
74

75
  ################################################################################
76
  # SetupGetRevisionForRepo defines a make rule for creating a file containing
77
  # the name of the repository and the output of the scm command for that
78
  # repository.
79
  #
80
  # Argument 1 is the relative path to the repository from the top dir.
81
  #
82
  SetupGetRevisionForRepo = $(NamedParamsMacroTemplate)
83
  define SetupGetRevisionForRepoBody
84
    $1_REPO_PATH :=  $$(TOPDIR)/$$(strip $1)
85
    $1_FILENAME := $$(call MakeFilenameFromRepo, $1)
86

87
    $$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME): FRC
88
	$$(call MakeDir, $$(@D))
89
	$$(ECHO) $$(strip $1):`$$(CD) $$($1_REPO_PATH) && $$(ID_COMMAND)` > $$@
90

91
    REPO_REVISIONS += $$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME)
92
  endef
93

94
  # Setup rules for all repos. This makes sure all the "git log" calls are made
95
  # in parallel.
96
  $(foreach repo, $(call FindAllReposRel), \
97
    $(eval $(call SetupGetRevisionForRepo, $(repo))) \
98
  )
99

100
  # Create a complete source revision output file from all repos
101
  # Param 1: The output file
102
  define CreateSourceRevisionFile
103
    $1: $$(REPO_REVISIONS)
104
	$$(call MakeDir, $$(@D))
105
	$$(ECHO) `$$(CAT) $$(REPO_REVISIONS)` > $$@.tmp
106
	if [ ! -f $$@ ] || [ "`$$(CAT) $$@`" != "`$$(CAT) $$@.tmp`" ]; then \
107
	  $$(MV) $$@.tmp $$@ ; \
108
	else \
109
	  $$(RM) $$@.tmp ; \
110
	fi
111
  endef
112

113
  $(eval $(call CreateSourceRevisionFile, $(STORED_SOURCE_REVISION)))
114

115
  scm-store-source-revision: $(STORED_SOURCE_REVISION)
116

117
  $(eval $(call CreateSourceRevisionFile, $(SOURCE_REVISION_TRACKER)))
118

119
  scm-create-source-revision-tracker: $(SOURCE_REVISION_TRACKER)
120

121
  STORE_SOURCE_REVISION_TARGET := scm-store-source-revision
122
  CREATE_SOURCE_REVISION_TRACKER_TARGET := scm-create-source-revision-tracker
123

124
  .PHONY: scm-store-source-revision scm-create-source-revision-tracker
125

126
else
127
  # Not using any SCM
128

129
  ifneq ($(wildcard $(STORED_SOURCE_REVISION)), )
130
    # We have a stored source revision (.src-rev)
131

132
    src-store-source-revision:
133
	$(call LogInfo, No SCM configuration present$(COMMA) not updating .src-rev)
134

135
    $(SOURCE_REVISION_TRACKER): $(STORED_SOURCE_REVISION)
136
	$(install-file)
137

138
    src-create-source-revision-tracker: $(SOURCE_REVISION_TRACKER)
139
  else
140
    # We don't have a stored source revision. Can't do anything, really.
141

142
    src-store-source-revision:
143
	$(call LogWarn, Error: No SCM configuration present$(COMMA) cannot create .src-rev)
144
	exit 2
145

146
    src-create-source-revision-tracker:
147
	$(call LogWarn, Warning: No SCM configuration present and no .src-rev)
148
  endif
149

150
  STORE_SOURCE_REVISION_TARGET := src-store-source-revision
151
  CREATE_SOURCE_REVISION_TRACKER_TARGET := src-create-source-revision-tracker
152

153
  .PHONY: src-store-source-revision src-create-source-revision-tracker
154

155
endif
156

157
################################################################################
158

159
$(eval $(call IncludeCustomExtension, SourceRevision-post.gmk))
160

161
################################################################################
162

163
store-source-revision: $(STORE_SOURCE_REVISION_TARGET)
164

165
create-source-revision-tracker: $(CREATE_SOURCE_REVISION_TRACKER_TARGET)
166

167
FRC: # Force target
168

169
.PHONY: store-source-revision create-source-revision-tracker
170

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.