@@ -31,23 +31,35 @@ $(eval $(call IncludeCustomExtension, SourceRevision-pre.gmk))
31
31
################################################################################
32
32
# Keep track of what source revision is used to create the build, by creating
33
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.
34
+ # source image, and can be used to recreate the source revision used.
35
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.
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
41
42
42
STORED_SOURCE_REVISION := $(TOPDIR)/.src-rev
43
43
44
- # Are we using mercurial?
44
+ USE_SCM := false
45
45
ifneq ($(and $(HG), $(wildcard $(TOPDIR)/.hg)), )
46
+ USE_SCM := true
47
+ SCM_DIR := .hg
48
+ ID_COMMAND := $(PRINTF) "hg:%s" "$$($(HG) id -i)"
49
+ else ifneq ($(and $(GIT), $(wildcard $(TOPDIR)/.git)), )
50
+ USE_SCM := true
51
+ SCM_DIR := .git
52
+ ID_COMMAND := $(PRINTF) "git:%s%s\n" \
53
+ "$$(git log -n1 --format=%H | cut -c1-12)" \
54
+ "$$(if test -n "$$(git status --porcelain)"; then printf '+'; fi)"
55
+ endif
56
+
57
+ ifeq ($(USE_SCM), true)
46
58
47
59
# Verify that the entire forest is consistent
48
60
$(foreach repo, $(call FindAllReposRel), \
49
- $(if $(wildcard $(TOPDIR)/$(repo)/.hg ),, \
50
- $(error Inconsistent revision control: $(repo) is missing .hg directory)) \
61
+ $(if $(wildcard $(TOPDIR)/$(repo)/$(SCM_DIR) ),, \
62
+ $(error Inconsistent revision control: $(repo) is missing $(SCM_DIR) directory)) \
51
63
)
52
64
53
65
# Replace "." with "_top" and "/" with "-"
@@ -56,7 +68,9 @@ ifneq ($(and $(HG), $(wildcard $(TOPDIR)/.hg)), )
56
68
57
69
################################################################################
58
70
# 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.
71
+ # the name of the repository and the output of the scm command for that
72
+ # repository.
73
+ #
60
74
# Argument 1 is the relative path to the repository from the top dir.
61
75
#
62
76
SetupGetRevisionForRepo = $(NamedParamsMacroTemplate)
@@ -66,7 +80,7 @@ ifneq ($(and $(HG), $(wildcard $(TOPDIR)/.hg)), )
66
80
67
81
$$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME): FRC
68
82
$$(call MakeDir, $$(@D))
69
- $$(ECHO) $$(strip $1):`$$(HG) id -i --repository $$($1_REPO_PATH)` > $$@
83
+ $$(ECHO) $$(strip $1):`$$(CD) $$($1_REPO_PATH) && $$(ID_COMMAND )` > $$@
70
84
71
85
REPO_REVISIONS += $$(SUPPORT_OUTPUTDIR)/src-rev/$$($1_FILENAME)
72
86
endef
@@ -92,23 +106,25 @@ ifneq ($(and $(HG), $(wildcard $(TOPDIR)/.hg)), )
92
106
93
107
$(eval $(call CreateSourceRevisionFile, $(STORED_SOURCE_REVISION)))
94
108
95
- hg -store-source-revision: $(STORED_SOURCE_REVISION)
109
+ scm -store-source-revision: $(STORED_SOURCE_REVISION)
96
110
97
111
$(eval $(call CreateSourceRevisionFile, $(SOURCE_REVISION_TRACKER)))
98
112
99
- hg -create-source-revision-tracker: $(SOURCE_REVISION_TRACKER)
113
+ scm -create-source-revision-tracker: $(SOURCE_REVISION_TRACKER)
100
114
101
- STORE_SOURCE_REVISION_TARGET := hg-store-source-revision
102
- CREATE_SOURCE_REVISION_TRACKER_TARGET := hg-create-source-revision-tracker
115
+ STORE_SOURCE_REVISION_TARGET := scm-store-source-revision
116
+ CREATE_SOURCE_REVISION_TRACKER_TARGET := scm-create-source-revision-tracker
117
+
118
+ .PHONY: scm-store-source-revision scm-create-source-revision-tracker
103
119
104
120
else
105
- # Not using HG
121
+ # Not using any SCM
106
122
107
123
ifneq ($(wildcard $(STORED_SOURCE_REVISION)), )
108
124
# We have a stored source revision (.src-rev)
109
125
110
126
src-store-source-revision:
111
- $(call LogInfo, No mercurial configuration present$(COMMA) not updating .src-rev)
127
+ $(call LogInfo, No SCM configuration present$(COMMA) not updating .src-rev)
112
128
113
129
$(SOURCE_REVISION_TRACKER): $(STORED_SOURCE_REVISION)
114
130
$(install-file)
@@ -118,16 +134,18 @@ else
118
134
# We don't have a stored source revision. Can't do anything, really.
119
135
120
136
src-store-source-revision:
121
- $(call LogWarn, Error: No mercurial configuration present$(COMMA) cannot create .src-rev)
137
+ $(call LogWarn, Error: No SCM configuration present$(COMMA) cannot create .src-rev)
122
138
exit 2
123
139
124
140
src-create-source-revision-tracker:
125
- $(call LogWarn, Warning: No mercurial configuration present and no .src-rev)
141
+ $(call LogWarn, Warning: No SCM configuration present and no .src-rev)
126
142
endif
127
143
128
144
STORE_SOURCE_REVISION_TARGET := src-store-source-revision
129
145
CREATE_SOURCE_REVISION_TRACKER_TARGET := src-create-source-revision-tracker
130
146
147
+ .PHONY: src-store-source-revision src-create-source-revision-tracker
148
+
131
149
endif
132
150
133
151
################################################################################
0 commit comments