4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
28 COMPONENT_PREP_GIT?
=yes
29 ifeq ($(strip $(COMPONENT_PREP_GIT
)), yes
)
32 # Anything that we pull from a GIT repo must have a GIT_REPO{_[0-9]+} and
33 # GIT_COMMIT_ID{_[0-9]+} to match.
36 GIT_SUFFIXES
= $(subst GIT_REPO_
,, $(filter GIT_REPO_
%, $(.VARIABLES
)))
38 # Templates for git variables and rules. We separate the variable assignments
39 # from the rules so that all the variable assignments are given a chance to
40 # complete before those variables are used in targets or prerequisites, where
41 # they'll be expanded immediately.
44 ifeq ("",$(strip $(or
$(GIT_BRANCH
$(1)),$(GIT_COMMIT_ID
$(1)))))
45 $$(error GIT_BRANCH
$(1) and
/or GIT_COMMIT_ID
$(1) must be defined
)
49 GIT_BRANCH_ARG
$(1) = -b
$$(GIT_BRANCH
$(1))
51 GIT_BRANCH_ARG
$(1) = -b master
54 # If the label is not already defined (including to empty), set it to the version.
55 COMPONENT_LABEL
$(1) ?
= $$(COMPONENT_VERSION
$(1))
56 # The source directory is <name>-(<label>|<version>)[-(<tag>|<branch>)][-<commit].
57 COMPONENT_SRC
$(1) ?
= $$(COMPONENT_NAME
$(1))$$(COMPONENT_LABEL
$(1):%=-%)$$($$(or
$$(GIT_TAG
$(1)),$$(GIT_BRANCH
$(1))))$$(GIT_COMMIT_ID
$(1):%=-%)
58 COMPONENT_ARCHIVE
$(1) ?
= $$(COMPONENT_SRC
$(1)).
tar.gz
59 # If the source is github attempt to generate an archive url. Defining
60 # COMPONENT_ARCHIVE_URL here messes with prep-download.mk, which keys off of
61 # that variable to build download rules, so keep track of which suffixes
62 # generated a github archive URL, and prep-download.mk will use that list to
63 # remove those URLs. If the primary (unsuffixed) archive is from github, then
64 # we add a dummy __BLANK__ suffix to the list, and filter that out separately.
65 ifeq (github
,$(findstring github
,$(GIT_REPO
$(1))))
66 COMPONENT_ARCHIVE_URL
$(1) ?
= $(GIT_REPO
$(1))/archive
/$(GIT_BRANCH
$(1)).
tar.gz
67 GITHUB_ARCHIVE_SUFFIXES
+= $(or
$(strip $(1:_
%=%)),__BLANK__
)
69 COMPONENT_ARCHIVE_SRC
$(1) = git
72 CLEAN_PATHS
+= $$(COMPONENT_SRC
$(1))
73 CLOBBER_PATHS
+= $$(COMPONENT_ARCHIVE
$(1))
74 SOURCE_DIR
$(1) = $$(COMPONENT_DIR
)/$$(COMPONENT_SRC
$(1))
80 download
:: $$(USERLAND_ARCHIVES
)$$(COMPONENT_ARCHIVE
$(1))
82 # First attempt to download a cached archive of the SCM repo at the proper
83 # changeset ID, If COMPONENT_ARCHIVE_URL is defined try that as well.
84 # If that fails, create an archive by cloning the SCM repo,
85 # updating to the selected changeset, archiving that directory, and cleaning up
89 # A shallow clone (--depth=1) to git clone takes only the top level (named)
90 # commits on any branches or tags and can cause use of other commit IDs to
91 # fail. As such, it should never be used here as it can make it impossible to
92 # reliably reproduce archives created from the result since git clone (unlike
93 # mercurial) currently has no way of cloning to a specific commit id.
94 $$(USERLAND_ARCHIVES
)$$(COMPONENT_ARCHIVE
$(1)): $(MAKEFILE_PREREQ
)
95 $$(FETCH
) --file
$$@
$$(GIT_HASH
$(1):%=--hash
%) --url GIT || \
96 ($$(FETCH
) --file
$$@
$$(COMPONENT_ARCHIVE_URL
$(1):%=--url
%) || \
97 (TMP_REPO
=$$$$($(MKTEMP
) --directory
) && \
98 $(GIT
) clone
$$(GIT_REPO
$(1)) $$(GIT_BRANCH_ARG
$(1)) $$$${TMP_REPO} && \
99 (cd
$$$${TMP_REPO} ; $(GIT
) checkout \
100 $$(GIT_COMMIT_ID
$(1))) && \
101 (cd
$$$${TMP_REPO} ; \
102 $(GIT
) config
tar.
tar.bz2.command
"bzip2 -c"; \
103 $(GIT
) config
tar.
tar.xz.command
"xz -c"; \
105 --format
$(subst $(COMPONENT_SRC
$(1)).
,,$(COMPONENT_ARCHIVE
$(1))) \
106 --prefix $$(COMPONENT_SRC
$(1))/ \
107 $$(or
$$(GIT_COMMIT_ID
$(1)),$$(GIT_BRANCH
$(1)))) > $$@
&& \
108 $(RM
) -r
$$$${TMP_REPO} ) && \
109 ( GIT_HASH
=$$$$(digest
-a sha256
$$@
) && \
111 -e
"s/\(GIT_HASH$(1)[[:space:]]*=[[:space:]]*\).*/\1sha256:$$$${GIT_HASH}/" \
115 USERLAND_REQUIRED_PACKAGES
+= developer
/versioning
/git
120 # Evaluate the variable assignments immediately
121 $(eval
$(call git-variables
,))
122 $(foreach suffix, $(GIT_SUFFIXES
), $(eval
$(call git-variables
,_
$(suffix))))
124 $(eval
$(call git-rules
,))
125 $(foreach suffix, $(GIT_SUFFIXES
), $(eval
$(call git-rules
,_
$(suffix))))