4194N/A#
4194N/A# CDDL HEADER START
4194N/A#
4194N/A# The contents of this file are subject to the terms of the
4194N/A# Common Development and Distribution License (the "License").
4194N/A# You may not use this file except in compliance with the License.
4194N/A#
4194N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4194N/A# or http://www.opensolaris.org/os/licensing.
4194N/A# See the License for the specific language governing permissions
4194N/A# and limitations under the License.
4194N/A#
4194N/A# When distributing Covered Code, include this CDDL HEADER in each
4194N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4194N/A# If applicable, add the following below this CDDL HEADER, with the
4194N/A# fields enclosed by brackets "[]" replaced with your own identifying
4194N/A# information: Portions Copyright [yyyy] [name of copyright owner]
4194N/A#
4194N/A# CDDL HEADER END
4194N/A#
5680N/A
5680N/A#
5436N/A# Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
4194N/A#
4194N/A
4194N/AGIT = /usr/bin/git
4194N/A
4194N/A#
4194N/A# Anything that we pull from a GIT repo must have a GIT_REPO{_[0-9]+} and
4194N/A# GIT_COMMIT_ID{_[0-9]+} to match.
4194N/A#
4194N/A
4249N/AGIT_SUFFIXES = $(subst GIT_REPO_,, $(filter GIT_REPO_%, $(.VARIABLES)))
4194N/A
6909N/A# Templates for git variables and rules. We separate the variable assignments
6909N/A# from the rules so that all the variable assignments are given a chance to
6909N/A# complete before those variables are used in targets or prerequisites, where
6909N/A# they'll be expanded immediately.
6909N/Adefine git-variables
4194N/Aifdef GIT_REPO$(1)
5436N/Aifeq ("",$(strip $(or $(GIT_BRANCH$(1)),$(GIT_COMMIT_ID$(1)))))
5436N/A $$(error GIT_BRANCH$(1) and/or GIT_COMMIT_ID$(1) must be defined)
6909N/Aendif
4194N/A
5436N/Aifdef GIT_BRANCH$(1)
5436N/A GIT_BRANCH_ARG$(1) = -b $$(GIT_BRANCH$(1))
5436N/Aelse
5436N/A GIT_BRANCH_ARG$(1) = -b master
5436N/Aendif
5436N/A
6909N/A# If the label is not already defined (including to empty), set it to the version.
6909N/ACOMPONENT_LABEL$(1) ?= $$(COMPONENT_VERSION$(1))
6909N/A# The source directory is <name>-(<label>|<version>)[-(<tag>|<branch>)][-<commit].
6909N/ACOMPONENT_SRC$(1) ?= $$(COMPONENT_NAME$(1))$$(COMPONENT_LABEL$(1):%=-%)$$($$(or $$(GIT_TAG$(1)),$$(GIT_BRANCH$(1))))$$(GIT_COMMIT_ID$(1):%=-%)
5095N/ACOMPONENT_ARCHIVE$(1) ?= $$(COMPONENT_SRC$(1)).tar.gz
6909N/A# If the source is github attempt to generate an archive url. Defining
6909N/A# COMPONENT_ARCHIVE_URL here messes with prep-download.mk, which keys off of
6909N/A# that variable to build download rules, so keep track of which suffixes
6909N/A# generated a github archive URL, and prep-download.mk will use that list to
6909N/A# remove those URLs. If the primary (unsuffixed) archive is from github, then
6909N/A# we add a dummy __BLANK__ suffix to the list, and filter that out separately.
5436N/Aifeq (github,$(findstring github,$(GIT_REPO$(1))))
5436N/A COMPONENT_ARCHIVE_URL$(1) ?= $(GIT_REPO$(1))/tarball/$(GIT_BRANCH$(1))
6909N/A GITHUB_ARCHIVE_SUFFIXES += $(or $(strip $(1:_%=%)),__BLANK__)
5680N/Aelse
5680N/A COMPONENT_ARCHIVE_SRC$(1) = git
5436N/Aendif
4194N/A
4194N/ACLEAN_PATHS += $$(COMPONENT_SRC$(1))
4194N/ACLOBBER_PATHS += $$(COMPONENT_ARCHIVE$(1))
4194N/ASOURCE_DIR$(1) = $$(COMPONENT_DIR)/$(COMPONENT_SRC$(1))
6909N/Aendif
6909N/Aendef
4194N/A
6909N/Adefine git-rules
6909N/Aifdef GIT_REPO$(1)
4194N/Adownload:: $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1))
4194N/A
4194N/A# First attempt to download a cached archive of the SCM repo at the proper
5436N/A# changeset ID, If COMPONENT_ARCHIVE_URL is defined try that as well.
5436N/A# If that fails, create an archive by cloning the SCM repo,
4194N/A# updating to the selected changeset, archiving that directory, and cleaning up
4194N/A# when complete.
5436N/A#
5436N/A# GIT CLONE ARGS
5831N/A# A shallow clone (--depth=1) to git clone takes only the top level (named)
5831N/A# commits on any branches or tags and can cause use of other commit IDs to
5831N/A# fail. As such, it should never be used here as it can make it impossible to
5831N/A# reliably reproduce archives created from the result since git clone (unlike
5831N/A# mercurial) currently has no way of cloning to a specific commit id.
4194N/A$$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1)): $(MAKEFILE_PREREQ)
5436N/A $$(FETCH) --file $$@ \
5436N/A $$(GIT_HASH$(1):%=--hash %) || \
5436N/A ( \
5436N/A $$(FETCH) --file $$@ \
5436N/A $$(COMPONENT_ARCHIVE_URL$(1):%=--url %) || \
4194N/A (TMP_REPO=$$$$(mktemp --directory) && \
5831N/A $(GIT) clone $$(GIT_REPO$(1)) $$(GIT_BRANCH_ARG$(1)) $$$${TMP_REPO} && \
5436N/A (cd $$$${TMP_REPO} ; $(GIT) checkout \
5436N/A $$(GIT_COMMIT_ID$(1))) && \
6950N/A (cd $$$${TMP_REPO} ; \
6950N/A $(GIT) config tar.tar.bz2.command "bzip2 -c"; \
6950N/A $(GIT) config tar.tar.xz.command "xz -c"; \
6950N/A $(GIT) archive \
6950N/A --format $(subst $(COMPONENT_SRC$(1)).,,$(COMPONENT_ARCHIVE$(1))) \
4194N/A --prefix $$(COMPONENT_SRC$(1))/ \
5436N/A $$(or $$(GIT_COMMIT_ID$(1)),$$(GIT_BRANCH$(1)))) > $$@ && \
5436N/A $(RM) -r $$$${TMP_REPO} ) && \
5436N/A ( GIT_HASH=$$$$(digest -a sha256 $$@) && \
5436N/A $(GSED) -i \
6949N/A -e "s/\(GIT_HASH$(1)[[:space:]]*=[[:space:]]*\).*/\1sha256:$$$${GIT_HASH}/" \
5436N/A Makefile ))
4194N/A
4194N/A
4194N/AREQUIRED_PACKAGES += developer/versioning/git
4194N/A
4194N/Aendif
4194N/Aendef
4194N/A
6909N/A# Evaluate the variable assignments immediately
6909N/A$(eval $(call git-variables,))
6909N/A$(foreach suffix, $(GIT_SUFFIXES), $(eval $(call git-variables,_$(suffix))))
6909N/A
6909N/A# Put the rule evaluations in a variable for deferred evaluation.
6909N/Adefine eval-git-rules
4194N/A$(eval $(call git-rules,))
4249N/A$(foreach suffix, $(GIT_SUFFIXES), $(eval $(call git-rules,_$(suffix))))
6909N/Aendef