make-rules/prep-git.mk
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Thu, 16 Jun 2016 20:28:32 -0700
changeset 6235 309c116f1e44
parent 5833 c1e66c53301d
child 6911 7b878dfe6f0d
permissions -rw-r--r--
Close of build 102.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     1
#
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     2
# CDDL HEADER START
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     3
#
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     4
# The contents of this file are subject to the terms of the
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     5
# Common Development and Distribution License (the "License").
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     6
# You may not use this file except in compliance with the License.
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     7
#
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     8
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     9
# or http://www.opensolaris.org/os/licensing.
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    10
# See the License for the specific language governing permissions
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    11
# and limitations under the License.
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    12
#
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    13
# When distributing Covered Code, include this CDDL HEADER in each
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    14
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    15
# If applicable, add the following below this CDDL HEADER, with the
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    16
# fields enclosed by brackets "[]" replaced with your own identifying
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    17
# information: Portions Copyright [yyyy] [name of copyright owner]
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    18
#
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    19
# CDDL HEADER END
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    20
#
5682
94c0ca64c022 15558602 TCL_LD_SEARCH_FLAGS is wrongly defined in tclConfig.sh
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5438
diff changeset
    21
94c0ca64c022 15558602 TCL_LD_SEARCH_FLAGS is wrongly defined in tclConfig.sh
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5438
diff changeset
    22
#
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    23
# Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    24
#
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    25
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    26
GIT =		/usr/bin/git
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    27
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    28
#
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    29
# Anything that we pull from a GIT repo must have a GIT_REPO{_[0-9]+} and
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    30
# GIT_COMMIT_ID{_[0-9]+} to match.
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    31
#
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    32
4251
2bf7e2c1ca74 21029374 probably shouldn't overload TMP_SUFFIXES in userland fragments
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 4196
diff changeset
    33
GIT_SUFFIXES = $(subst GIT_REPO_,, $(filter GIT_REPO_%, $(.VARIABLES)))
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    34
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    35
define git-rules
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    36
ifdef GIT_REPO$(1)
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    37
ifeq ("",$(strip $(or $(GIT_BRANCH$(1)),$(GIT_COMMIT_ID$(1)))))
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    38
  $$(error GIT_BRANCH$(1) and/or GIT_COMMIT_ID$(1) must be defined)
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    39
else
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    40
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    41
ifdef GIT_BRANCH$(1)
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    42
  GIT_BRANCH_ARG$(1) = -b $$(GIT_BRANCH$(1))
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    43
else
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    44
  GIT_BRANCH_ARG$(1) = -b master
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    45
endif
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    46
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    47
COMPONENT_SRC$(1) ?= $$(COMPONENT_NAME$(1))$$(GIT_BRANCH$(1):%=-%)$$(GIT_COMMIT_ID$(1):%=-%)
5097
4359ece036d8 21542117 component variables for git cannot be set
John Martin <john.m.martin@oracle.com>
parents: 4358
diff changeset
    48
COMPONENT_ARCHIVE$(1) ?= $$(COMPONENT_SRC$(1)).tar.gz
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    49
# If the source is github attempt to generate an archive url
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    50
ifeq (github,$(findstring github,$(GIT_REPO$(1))))
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    51
  COMPONENT_ARCHIVE_URL$(1) ?= $(GIT_REPO$(1))/tarball/$(GIT_BRANCH$(1))
5682
94c0ca64c022 15558602 TCL_LD_SEARCH_FLAGS is wrongly defined in tclConfig.sh
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5438
diff changeset
    52
else
94c0ca64c022 15558602 TCL_LD_SEARCH_FLAGS is wrongly defined in tclConfig.sh
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5438
diff changeset
    53
  COMPONENT_ARCHIVE_SRC$(1) = git
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    54
endif
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    55
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    56
CLEAN_PATHS += $$(COMPONENT_SRC$(1))
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    57
CLOBBER_PATHS += $$(COMPONENT_ARCHIVE$(1))
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    58
SOURCE_DIR$(1) = $$(COMPONENT_DIR)/$(COMPONENT_SRC$(1))
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    59
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    60
download::	$$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1))
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    61
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    62
# First attempt to download a cached archive of the SCM repo at the proper
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    63
# changeset ID, If COMPONENT_ARCHIVE_URL is defined try that as well.
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    64
# If that fails, create an archive by cloning the SCM repo,
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    65
# updating to the selected changeset, archiving that directory, and cleaning up
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    66
# when complete.
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    67
#
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    68
# GIT CLONE ARGS
5833
c1e66c53301d 23126845 golang download target fails if source not cached
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5682
diff changeset
    69
# A shallow clone (--depth=1) to git clone takes only the top level (named)
c1e66c53301d 23126845 golang download target fails if source not cached
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5682
diff changeset
    70
# commits on any branches or tags and can cause use of other commit IDs to
c1e66c53301d 23126845 golang download target fails if source not cached
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5682
diff changeset
    71
# fail.  As such, it should never be used here as it can make it impossible to
c1e66c53301d 23126845 golang download target fails if source not cached
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5682
diff changeset
    72
# reliably reproduce archives created from the result since git clone (unlike
c1e66c53301d 23126845 golang download target fails if source not cached
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5682
diff changeset
    73
# mercurial) currently has no way of cloning to a specific commit id.
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    74
$$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1)):	$(MAKEFILE_PREREQ)
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    75
	$$(FETCH) --file $$@ \
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    76
		$$(GIT_HASH$(1):%=--hash %) || \
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    77
		( \
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    78
	$$(FETCH) --file $$@ \
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    79
		$$(COMPONENT_ARCHIVE_URL$(1):%=--url %) || \
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    80
	(TMP_REPO=$$$$(mktemp --directory) && \
5833
c1e66c53301d 23126845 golang download target fails if source not cached
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5682
diff changeset
    81
	$(GIT) clone $$(GIT_REPO$(1)) $$(GIT_BRANCH_ARG$(1)) $$$${TMP_REPO} && \
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    82
	(cd $$$${TMP_REPO} ; $(GIT) checkout \
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    83
	$$(GIT_COMMIT_ID$(1))) && \
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    84
	(cd $$$${TMP_REPO} ; $(GIT) archive --format tar.gz \
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    85
		--prefix $$(COMPONENT_SRC$(1))/ \
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    86
		$$(or $$(GIT_COMMIT_ID$(1)),$$(GIT_BRANCH$(1)))) > $$@ && \
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    87
	$(RM) -r $$$${TMP_REPO} ) && \
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    88
	( GIT_HASH=$$$$(digest -a sha256 $$@) && \
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    89
	$(GSED) -i \
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    90
		-e "s/^GIT_HASH$(1)=.*/GIT_HASH$(1)=  sha256:$$$${GIT_HASH}/" \
5438
c068f8c677e8 PSARC/2016/016 Rename/Refactor Puppet and Puppet Module Packages
Shawn Ferry <shawn.ferry@oracle.com>
parents: 5097
diff changeset
    91
		Makefile ))
4196
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    92
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    93
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    94
REQUIRED_PACKAGES += developer/versioning/git
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    95
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    96
endif
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    97
endif
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    98
endef
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    99
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   100
#
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   101
# Define the rules required to download any source archives and augment any
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   102
# cleanup macros.
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   103
#
d697072a92f5 19782029 userland should be able to build from SCM repositories
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   104
$(eval $(call git-rules,))
4251
2bf7e2c1ca74 21029374 probably shouldn't overload TMP_SUFFIXES in userland fragments
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 4196
diff changeset
   105
$(foreach suffix, $(GIT_SUFFIXES), $(eval $(call git-rules,_$(suffix))))