VMware vSphere Integrated Containers provider (#206)
* Add Virtual Kubelet provider for VIC Initial virtual kubelet provider for VMware VIC. This provider currently handles creating and starting of a pod VM via the VIC portlayer and persona server. Image store handling via the VIC persona server. This provider currently requires the feature/wolfpack branch of VIC. * Added pod stop and delete. Also added node capacity. Added the ability to stop and delete pod VMs via VIC. Also retrieve node capacity information from the VCH. * Cleanup and readme file Some file clean up and added a Readme.md markdown file for the VIC provider. * Cleaned up errors, added function comments, moved operation code 1. Cleaned up error handling. Set standard for creating errors. 2. Added method prototype comments for all interface functions. 3. Moved PodCreator, PodStarter, PodStopper, and PodDeleter to a new folder. * Add mocking code and unit tests for podcache, podcreator, and podstarter Used the unit test framework used in VIC to handle assertions in the provider's unit test. Mocking code generated using OSS project mockery, which is compatible with the testify assertion framework. * Vendored packages for the VIC provider Requires feature/wolfpack branch of VIC and a few specific commit sha of projects used within VIC. * Implementation of POD Stopper and Deleter unit tests (#4) * Updated files for initial PR
This commit is contained in:
940
vendor/github.com/vmware/vic/infra/util/gsml/__gmsl
generated
vendored
Normal file
940
vendor/github.com/vmware/vic/infra/util/gsml/__gmsl
generated
vendored
Normal file
@@ -0,0 +1,940 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
#
|
||||
# GNU Make Standard Library (GMSL)
|
||||
#
|
||||
# A library of functions to be used with GNU Make's $(call) that
|
||||
# provides functionality not available in standard GNU Make.
|
||||
#
|
||||
# Copyright (c) 2005-2014 John Graham-Cumming
|
||||
#
|
||||
# This file is part of GMSL
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# Neither the name of the John Graham-Cumming nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# This is the GNU Make Standard Library version number as a list with
|
||||
# three items: major, minor, revision
|
||||
|
||||
gmsl_version := 1 1 7
|
||||
|
||||
__gmsl_name := GNU Make Standard Library
|
||||
|
||||
# Used to output warnings and error from the library, it's possible to
|
||||
# disable any warnings or errors by overriding these definitions
|
||||
# manually or by setting GMSL_NO_WARNINGS or GMSL_NO_ERRORS
|
||||
|
||||
ifdef GMSL_NO_WARNINGS
|
||||
__gmsl_warning :=
|
||||
else
|
||||
__gmsl_warning = $(if $1,$(warning $(__gmsl_name): $1))
|
||||
endif
|
||||
|
||||
ifdef GMSL_NO_ERRORS
|
||||
__gmsl_error :=
|
||||
else
|
||||
__gmsl_error = $(if $1,$(error $(__gmsl_name): $1))
|
||||
endif
|
||||
|
||||
# If GMSL_TRACE is enabled then calls to the library functions are
|
||||
# traced to stdout using warning messages with their arguments
|
||||
|
||||
ifdef GMSL_TRACE
|
||||
__gmsl_tr1 = $(warning $0('$1'))
|
||||
__gmsl_tr2 = $(warning $0('$1','$2'))
|
||||
__gmsl_tr3 = $(warning $0('$1','$2','$3'))
|
||||
else
|
||||
__gmsl_tr1 :=
|
||||
__gmsl_tr2 :=
|
||||
__gmsl_tr3 :=
|
||||
endif
|
||||
|
||||
# See if spaces are valid in variable names (this was the case until
|
||||
# GNU Make 3.82)
|
||||
ifeq ($(MAKE_VERSION),3.82)
|
||||
__gmsl_spaced_vars := $(false)
|
||||
else
|
||||
__gmsl_spaced_vars := $(true)
|
||||
endif
|
||||
|
||||
# Figure out whether we have $(eval) or not (GNU Make 3.80 and above)
|
||||
# if we do not then output a warning message, if we do then some
|
||||
# functions will be enabled.
|
||||
|
||||
__gmsl_have_eval := $(false)
|
||||
__gmsl_ignore := $(eval __gmsl_have_eval := $(true))
|
||||
|
||||
# If this is being run with Electric Cloud's emake then warn that
|
||||
# their $(eval) support is incomplete in 1.x, 2.x, 3.x, 4.x and 5.0,
|
||||
# 5.1, 5.2 and 5.3
|
||||
|
||||
ifdef ECLOUD_BUILD_ID
|
||||
__gmsl_emake_major := $(word 1,$(subst ., ,$(EMAKE_VERSION)))
|
||||
__gmsl_emake_minor := $(word 2,$(subst ., ,$(EMAKE_VERSION)))
|
||||
ifneq ("$(findstring $(__gmsl_emake_major),1 2 3 4)$(findstring $(__gmsl_emake_major)$(__gmsl_emake_minor),50 51 52 53)","")
|
||||
$(warning You are using a version of Electric Cloud's emake which has incomplete $$(eval) support)
|
||||
__gmsl_have_eval := $(false)
|
||||
endif
|
||||
endif
|
||||
|
||||
# See if we have $(lastword) (GNU Make 3.81 and above)
|
||||
|
||||
__gmsl_have_lastword := $(lastword $(false) $(true))
|
||||
|
||||
# See if we have native or and and (GNU Make 3.81 and above)
|
||||
|
||||
__gmsl_have_or := $(if $(filter-out undefined, \
|
||||
$(origin or)),$(call or,$(true),$(false)))
|
||||
__gmsl_have_and := $(if $(filter-out undefined, \
|
||||
$(origin and)),$(call and,$(true),$(true)))
|
||||
|
||||
ifneq ($(__gmsl_have_eval),$(true))
|
||||
$(call __gmsl_warning,Your make version $(MAKE_VERSION) does not support $$$$(eval): some functions disabled)
|
||||
endif
|
||||
|
||||
__gmsl_dollar := $$
|
||||
__gmsl_hash := \#
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: gmsl_compatible
|
||||
# Arguments: List containing the desired library version number (maj min rev)
|
||||
# Returns: $(true) if this version of the library is compatible
|
||||
# with the requested version number, otherwise $(false)
|
||||
# ----------------------------------------------------------------------------
|
||||
gmsl_compatible = $(strip \
|
||||
$(if $(call gt,$(word 1,$1),$(word 1,$(gmsl_version))), \
|
||||
$(false), \
|
||||
$(if $(call lt,$(word 1,$1),$(word 1,$(gmsl_version))), \
|
||||
$(true), \
|
||||
$(if $(call gt,$(word 2,$1),$(word 2,$(gmsl_version))), \
|
||||
$(false), \
|
||||
$(if $(call lt,$(word 2,$1),$(word 2,$(gmsl_version))), \
|
||||
$(true), \
|
||||
$(call lte,$(word 3,$1),$(word 3,$(gmsl_version))))))))
|
||||
|
||||
# ###########################################################################
|
||||
# LOGICAL OPERATORS
|
||||
# ###########################################################################
|
||||
|
||||
# not is defined in gmsl
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: and
|
||||
# Arguments: Two boolean values
|
||||
# Returns: Returns $(true) if both of the booleans are true
|
||||
# ----------------------------------------------------------------------------
|
||||
ifneq ($(__gmsl_have_and),$(true))
|
||||
and = $(__gmsl_tr2)$(if $1,$(if $2,$(true),$(false)),$(false))
|
||||
endif
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: or
|
||||
# Arguments: Two boolean values
|
||||
# Returns: Returns $(true) if either of the booleans is true
|
||||
# ----------------------------------------------------------------------------
|
||||
ifneq ($(__gmsl_have_or),$(true))
|
||||
or = $(__gmsl_tr2)$(if $1$2,$(true),$(false))
|
||||
endif
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: xor
|
||||
# Arguments: Two boolean values
|
||||
# Returns: Returns $(true) if exactly one of the booleans is true
|
||||
# ----------------------------------------------------------------------------
|
||||
xor = $(__gmsl_tr2)$(if $1,$(if $2,$(false),$(true)),$(if $2,$(true),$(false)))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: nand
|
||||
# Arguments: Two boolean values
|
||||
# Returns: Returns value of 'not and'
|
||||
# ----------------------------------------------------------------------------
|
||||
nand = $(__gmsl_tr2)$(if $1,$(if $2,$(false),$(true)),$(true))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: nor
|
||||
# Arguments: Two boolean values
|
||||
# Returns: Returns value of 'not or'
|
||||
# ----------------------------------------------------------------------------
|
||||
nor = $(__gmsl_tr2)$(if $1$2,$(false),$(true))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: xnor
|
||||
# Arguments: Two boolean values
|
||||
# Returns: Returns value of 'not xor'
|
||||
# ----------------------------------------------------------------------------
|
||||
xnor =$(__gmsl_tr2)$(if $1,$(if $2,$(true),$(false)),$(if $2,$(false),$(true)))
|
||||
|
||||
# ###########################################################################
|
||||
# LIST MANIPULATION FUNCTIONS
|
||||
# ###########################################################################
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: first (same as LISP's car, or head)
|
||||
# Arguments: 1: A list
|
||||
# Returns: Returns the first element of a list
|
||||
# ----------------------------------------------------------------------------
|
||||
first = $(__gmsl_tr1)$(firstword $1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: last
|
||||
# Arguments: 1: A list
|
||||
# Returns: Returns the last element of a list
|
||||
# ----------------------------------------------------------------------------
|
||||
ifeq ($(__gmsl_have_lastword),$(true))
|
||||
last = $(__gmsl_tr1)$(lastword $1)
|
||||
else
|
||||
last = $(__gmsl_tr1)$(if $1,$(word $(words $1),$1))
|
||||
endif
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: rest (same as LISP's cdr, or tail)
|
||||
# Arguments: 1: A list
|
||||
# Returns: Returns the list with the first element removed
|
||||
# ----------------------------------------------------------------------------
|
||||
rest = $(__gmsl_tr1)$(wordlist 2,$(words $1),$1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: chop
|
||||
# Arguments: 1: A list
|
||||
# Returns: Returns the list with the last element removed
|
||||
# ----------------------------------------------------------------------------
|
||||
chop = $(__gmsl_tr1)$(wordlist 2,$(words $1),x $1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: map
|
||||
# Arguments: 1: Name of function to $(call) for each element of list
|
||||
# 2: List to iterate over calling the function in 1
|
||||
# Returns: The list after calling the function on each element
|
||||
# ----------------------------------------------------------------------------
|
||||
map = $(__gmsl_tr2)$(strip $(foreach a,$2,$(call $1,$a)))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: pairmap
|
||||
# Arguments: 1: Name of function to $(call) for each pair of elements
|
||||
# 2: List to iterate over calling the function in 1
|
||||
# 3: Second list to iterate over calling the function in 1
|
||||
# Returns: The list after calling the function on each pair of elements
|
||||
# ----------------------------------------------------------------------------
|
||||
pairmap = $(strip $(__gmsl_tr3)\
|
||||
$(if $2$3,$(call $1,$(call first,$2),$(call first,$3)) \
|
||||
$(call pairmap,$1,$(call rest,$2),$(call rest,$3))))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: leq
|
||||
# Arguments: 1: A list to compare against...
|
||||
# 2: ...this list
|
||||
# Returns: Returns $(true) if the two lists are identical
|
||||
# ----------------------------------------------------------------------------
|
||||
leq = $(__gmsl_tr2)$(strip $(if $(call seq,$(words $1),$(words $2)), \
|
||||
$(call __gmsl_list_equal,$1,$2),$(false)))
|
||||
|
||||
__gmsl_list_equal = $(if $(strip $1), \
|
||||
$(if $(call seq,$(call first,$1),$(call first,$2)), \
|
||||
$(call __gmsl_list_equal, \
|
||||
$(call rest,$1), \
|
||||
$(call rest,$2)), \
|
||||
$(false)), \
|
||||
$(true))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: lne
|
||||
# Arguments: 1: A list to compare against...
|
||||
# 2: ...this list
|
||||
# Returns: Returns $(true) if the two lists are different
|
||||
# ----------------------------------------------------------------------------
|
||||
lne = $(__gmsl_tr2)$(call not,$(call leq,$1,$2))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: reverse
|
||||
# Arguments: 1: A list to reverse
|
||||
# Returns: The list with its elements in reverse order
|
||||
# ----------------------------------------------------------------------------
|
||||
reverse =$(__gmsl_tr1)$(strip $(if $1,$(call reverse,$(call rest,$1)) \
|
||||
$(call first,$1)))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: uniq
|
||||
# Arguments: 1: A list from which to remove repeated elements
|
||||
# Returns: The list with duplicate elements removed without reordering
|
||||
# ----------------------------------------------------------------------------
|
||||
uniq = $(strip $(__gmsl_tr1) $(if $1,$(firstword $1) \
|
||||
$(call uniq,$(filter-out $(firstword $1),$1))))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: length
|
||||
# Arguments: 1: A list
|
||||
# Returns: The number of elements in the list
|
||||
# ----------------------------------------------------------------------------
|
||||
length = $(__gmsl_tr1)$(words $1)
|
||||
|
||||
# ###########################################################################
|
||||
# STRING MANIPULATION FUNCTIONS
|
||||
# ###########################################################################
|
||||
|
||||
# Helper function that translates any GNU Make 'true' value (i.e. a
|
||||
# non-empty string) to our $(true)
|
||||
|
||||
__gmsl_make_bool = $(if $(strip $1),$(true),$(false))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: seq
|
||||
# Arguments: 1: A string to compare against...
|
||||
# 2: ...this string
|
||||
# Returns: Returns $(true) if the two strings are identical
|
||||
# ----------------------------------------------------------------------------
|
||||
seq = $(__gmsl_tr2)$(if $(subst x$1,,x$2)$(subst x$2,,x$1),$(false),$(true))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: sne
|
||||
# Arguments: 1: A string to compare against...
|
||||
# 2: ...this string
|
||||
# Returns: Returns $(true) if the two strings are not the same
|
||||
# ----------------------------------------------------------------------------
|
||||
sne = $(__gmsl_tr2)$(call not,$(call seq,$1,$2))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: split
|
||||
# Arguments: 1: The character to split on
|
||||
# 2: A string to split
|
||||
# Returns: Splits a string into a list separated by spaces at the split
|
||||
# character in the first argument
|
||||
# ----------------------------------------------------------------------------
|
||||
split = $(__gmsl_tr2)$(strip $(subst $1, ,$2))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: merge
|
||||
# Arguments: 1: The character to put between fields
|
||||
# 2: A list to merge into a string
|
||||
# Returns: Merges a list into a single string, list elements are separated
|
||||
# by the character in the first argument
|
||||
# ----------------------------------------------------------------------------
|
||||
merge = $(__gmsl_tr2)$(strip $(if $2, \
|
||||
$(if $(call seq,1,$(words $2)), \
|
||||
$2,$(call first,$2)$1$(call merge,$1,$(call rest,$2)))))
|
||||
|
||||
ifdef __gmsl_have_eval
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: tr
|
||||
# Arguments: 1: The list of characters to translate from
|
||||
# 2: The list of characters to translate to
|
||||
# 3: The text to translate
|
||||
# Returns: Returns the text after translating characters
|
||||
# ----------------------------------------------------------------------------
|
||||
tr = $(strip $(__gmsl_tr3)$(call assert_no_dollar,$0,$1$2$3) \
|
||||
$(eval __gmsl_t := $3) \
|
||||
$(foreach c, \
|
||||
$(join $(addsuffix :,$1),$2), \
|
||||
$(eval __gmsl_t := \
|
||||
$(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)), \
|
||||
$(__gmsl_t))))$(__gmsl_t))
|
||||
|
||||
# Common character classes for use with the tr function. Each of
|
||||
# these is actually a variable declaration and must be wrapped with
|
||||
# $() or ${} to be used.
|
||||
|
||||
[A-Z] := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z #
|
||||
[a-z] := a b c d e f g h i j k l m n o p q r s t u v w x y z #
|
||||
[0-9] := 0 1 2 3 4 5 6 7 8 9 #
|
||||
[A-F] := A B C D E F #
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: uc
|
||||
# Arguments: 1: Text to upper case
|
||||
# Returns: Returns the text in upper case
|
||||
# ----------------------------------------------------------------------------
|
||||
uc = $(__gmsl_tr1)$(call assert_no_dollar,$0,$1)$(call tr,$([a-z]),$([A-Z]),$1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: lc
|
||||
# Arguments: 1: Text to lower case
|
||||
# Returns: Returns the text in lower case
|
||||
# ----------------------------------------------------------------------------
|
||||
lc = $(__gmsl_tr1)$(call assert_no_dollar,$0,$1)$(call tr,$([A-Z]),$([a-z]),$1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: strlen
|
||||
# Arguments: 1: A string
|
||||
# Returns: Returns the length of the string
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# This results in __gmsl_tab containing a tab
|
||||
|
||||
__gmsl_tab := #
|
||||
|
||||
__gmsl_characters := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
|
||||
__gmsl_characters += a b c d e f g h i j k l m n o p q r s t u v w x y z
|
||||
__gmsl_characters += 0 1 2 3 4 5 6 7 8 9
|
||||
__gmsl_characters += ` ~ ! @ \# $$ % ^ & * ( ) - _ = +
|
||||
__gmsl_characters += { } [ ] \ : ; ' " < > , . / ? |
|
||||
|
||||
# This results in __gmsl_space containing just a space
|
||||
|
||||
__gmsl_space :=
|
||||
__gmsl_space +=
|
||||
|
||||
strlen = $(__gmsl_tr1)$(call assert_no_dollar,$0,$1)$(strip $(eval __temp := $(subst $(__gmsl_space),x,$1))$(foreach a,$(__gmsl_characters),$(eval __temp := $$(subst $$a,x,$(__temp))))$(eval __temp := $(subst x,x ,$(__temp)))$(words $(__temp)))
|
||||
|
||||
# This results in __gmsl_newline containing just a newline
|
||||
|
||||
define __gmsl_newline
|
||||
|
||||
|
||||
endef
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: substr
|
||||
# Arguments: 1: A string
|
||||
# 2: Start position (first character is 1)
|
||||
# 3: End position (inclusive)
|
||||
# Returns: A substring.
|
||||
# Note: The string in $1 must not contain a <20>
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
substr = $(if $2,$(__gmsl_tr3)$(call assert_no_dollar,$0,$1$2$3)$(strip $(eval __temp := $$(subst $$(__gmsl_space),<2C> ,$$1))$(foreach a,$(__gmsl_characters),$(eval __temp := $$(subst $$a,$$a$$(__gmsl_space),$(__temp))))$(eval __temp := $(wordlist $2,$3,$(__temp))))$(subst <20>,$(__gmsl_space),$(subst $(__gmsl_space),,$(__temp))))
|
||||
|
||||
endif # __gmsl_have_eval
|
||||
|
||||
# ###########################################################################
|
||||
# SET MANIPULATION FUNCTIONS
|
||||
# ###########################################################################
|
||||
|
||||
# Sets are represented by sorted, deduplicated lists. To create a set
|
||||
# from a list use set_create, or start with the empty_set and
|
||||
# set_insert individual elements
|
||||
|
||||
# This is the empty set
|
||||
empty_set :=
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: set_create
|
||||
# Arguments: 1: A list of set elements
|
||||
# Returns: Returns the newly created set
|
||||
# ----------------------------------------------------------------------------
|
||||
set_create = $(__gmsl_tr1)$(sort $1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: set_insert
|
||||
# Arguments: 1: A single element to add to a set
|
||||
# 2: A set
|
||||
# Returns: Returns the set with the element added
|
||||
# ----------------------------------------------------------------------------
|
||||
set_insert = $(__gmsl_tr2)$(sort $1 $2)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: set_remove
|
||||
# Arguments: 1: A single element to remove from a set
|
||||
# 2: A set
|
||||
# Returns: Returns the set with the element removed
|
||||
# ----------------------------------------------------------------------------
|
||||
set_remove = $(__gmsl_tr2)$(filter-out $1,$2)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: set_is_member, set_is_not_member
|
||||
# Arguments: 1: A single element
|
||||
# 2: A set
|
||||
# Returns: (set_is_member) Returns $(true) if the element is in the set
|
||||
# (set_is_not_member) Returns $(false) if the element is in the set
|
||||
# ----------------------------------------------------------------------------
|
||||
set_is_member = $(__gmsl_tr2)$(if $(filter $1,$2),$(true),$(false))
|
||||
set_is_not_member = $(__gmsl_tr2)$(if $(filter $1,$2),$(false),$(true))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: set_union
|
||||
# Arguments: 1: A set
|
||||
# 2: Another set
|
||||
# Returns: Returns the union of the two sets
|
||||
# ----------------------------------------------------------------------------
|
||||
set_union = $(__gmsl_tr2)$(sort $1 $2)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: set_intersection
|
||||
# Arguments: 1: A set
|
||||
# 2: Another set
|
||||
# Returns: Returns the intersection of the two sets
|
||||
# ----------------------------------------------------------------------------
|
||||
set_intersection = $(__gmsl_tr2)$(filter $1,$2)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: set_is_subset
|
||||
# Arguments: 1: A set
|
||||
# 2: Another set
|
||||
# Returns: Returns $(true) if the first set is a subset of the second
|
||||
# ----------------------------------------------------------------------------
|
||||
set_is_subset = $(__gmsl_tr2)$(call set_equal,$(call set_intersection,$1,$2),$1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: set_equal
|
||||
# Arguments: 1: A set
|
||||
# 2: Another set
|
||||
# Returns: Returns $(true) if the two sets are identical
|
||||
# ----------------------------------------------------------------------------
|
||||
set_equal = $(__gmsl_tr2)$(call seq,$1,$2)
|
||||
|
||||
# ###########################################################################
|
||||
# ARITHMETIC LIBRARY
|
||||
# ###########################################################################
|
||||
|
||||
# Integers a represented by lists with the equivalent number of x's.
|
||||
# For example the number 4 is x x x x.
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_decode
|
||||
# Arguments: 1: A number of x's representation
|
||||
# Returns: Returns the integer for human consumption that is represented
|
||||
# by the string of x's
|
||||
# ----------------------------------------------------------------------------
|
||||
int_decode = $(__gmsl_tr1)$(words $1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_encode
|
||||
# Arguments: 1: A number in human-readable integer form
|
||||
# Returns: Returns the integer encoded as a string of x's
|
||||
# ----------------------------------------------------------------------------
|
||||
__int_encode = $(if $1,$(if $(call seq,$(words $(wordlist 1,$1,$2)),$1),$(wordlist 1,$1,$2),$(call __int_encode,$1,$(if $2,$2 $2,x))))
|
||||
__strip_leading_zero = $(if $1,$(if $(call seq,$(patsubst 0%,%,$1),$1),$1,$(call __strip_leading_zero,$(patsubst 0%,%,$1))),0)
|
||||
int_encode = $(__gmsl_tr1)$(call __int_encode,$(call __strip_leading_zero,$1))
|
||||
|
||||
# The arithmetic library functions come in two forms: one form of each
|
||||
# function takes integers as arguments and the other form takes the
|
||||
# encoded form (x's created by a call to int_encode). For example,
|
||||
# there are two plus functions:
|
||||
#
|
||||
# plus Called with integer arguments and returns an integer
|
||||
# int_plus Called with encoded arguments and returns an encoded result
|
||||
#
|
||||
# plus will be slower than int_plus because its arguments and result
|
||||
# have to be translated between the x's format and integers. If doing
|
||||
# a complex calculation use the int_* forms with a single encoding of
|
||||
# inputs and single decoding of the output. For simple calculations
|
||||
# the direct forms can be used.
|
||||
|
||||
# Helper function used to wrap an int_* function into a function that
|
||||
# takes a pair of integers, perhaps a function and returns an integer
|
||||
# result
|
||||
__gmsl_int_wrap = $(call int_decode,$(call $1,$(call int_encode,$2),$(call int_encode,$3)))
|
||||
__gmsl_int_wrap1 = $(call int_decode,$(call $1,$(call int_encode,$2)))
|
||||
__gmsl_int_wrap2 = $(call $1,$(call int_encode,$2),$(call int_encode,$3))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_plus
|
||||
# Arguments: 1: A number in x's representation
|
||||
# 2: Another number in x's represntation
|
||||
# Returns: Returns the sum of the two numbers in x's representation
|
||||
# ----------------------------------------------------------------------------
|
||||
int_plus = $(strip $(__gmsl_tr2)$1 $2)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: plus (wrapped version of int_plus)
|
||||
# Arguments: 1: An integer
|
||||
# 2: Another integer
|
||||
# Returns: Returns the sum of the two integers
|
||||
# ----------------------------------------------------------------------------
|
||||
plus = $(__gmsl_tr2)$(call __gmsl_int_wrap,int_plus,$1,$2)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_subtract
|
||||
# Arguments: 1: A number in x's representation
|
||||
# 2: Another number in x's represntation
|
||||
# Returns: Returns the difference of the two numbers in x's representation,
|
||||
# or outputs an error on a numeric underflow
|
||||
# ----------------------------------------------------------------------------
|
||||
int_subtract = $(strip $(__gmsl_tr2)$(if $(call int_gte,$1,$2), \
|
||||
$(filter-out xx,$(join $1,$2)), \
|
||||
$(call __gmsl_warning,Subtraction underflow)))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: subtract (wrapped version of int_subtract)
|
||||
# Arguments: 1: An integer
|
||||
# 2: Another integer
|
||||
# Returns: Returns the difference of the two integers,
|
||||
# or outputs an error on a numeric underflow
|
||||
# ----------------------------------------------------------------------------
|
||||
subtract = $(__gmsl_tr2)$(call __gmsl_int_wrap,int_subtract,$1,$2)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_multiply
|
||||
# Arguments: 1: A number in x's representation
|
||||
# 2: Another number in x's represntation
|
||||
# Returns: Returns the product of the two numbers in x's representation
|
||||
# ----------------------------------------------------------------------------
|
||||
int_multiply = $(strip $(__gmsl_tr2)$(foreach a,$1,$2))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: multiply (wrapped version of int_multiply)
|
||||
# Arguments: 1: An integer
|
||||
# 2: Another integer
|
||||
# Returns: Returns the product of the two integers
|
||||
# ----------------------------------------------------------------------------
|
||||
multiply = $(__gmsl_tr2)$(call __gmsl_int_wrap,int_multiply,$1,$2)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_divide
|
||||
# Arguments: 1: A number in x's representation
|
||||
# 2: Another number in x's represntation
|
||||
# Returns: Returns the result of integer division of argument 1 divided
|
||||
# by argument 2 in x's representation
|
||||
# ----------------------------------------------------------------------------
|
||||
int_divide = $(__gmsl_tr2)$(strip $(if $1,$(if $2, \
|
||||
$(if $(call int_gte,$1,$2), \
|
||||
x $(call int_divide,$(call int_subtract,$1,$2),$2),), \
|
||||
$(call __gmsl_error,Division by zero))))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: divide (wrapped version of int_divide)
|
||||
# Arguments: 1: An integer
|
||||
# 2: Another integer
|
||||
# Returns: Returns the integer division of the first argument by the second
|
||||
# ----------------------------------------------------------------------------
|
||||
divide = $(__gmsl_tr2)$(call __gmsl_int_wrap,int_divide,$1,$2)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_max, int_min
|
||||
# Arguments: 1: A number in x's representation
|
||||
# 2: Another number in x's represntation
|
||||
# Returns: Returns the maximum or minimum of its arguments in x's
|
||||
# representation
|
||||
# ----------------------------------------------------------------------------
|
||||
int_max = $(__gmsl_tr2)$(subst xx,x,$(join $1,$2))
|
||||
int_min = $(__gmsl_tr2)$(subst xx,x,$(filter xx,$(join $1,$2)))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: max, min
|
||||
# Arguments: 1: An integer
|
||||
# 2: Another integer
|
||||
# Returns: Returns the maximum or minimum of its integer arguments
|
||||
# ----------------------------------------------------------------------------
|
||||
max = $(__gmsl_tr2)$(call __gmsl_int_wrap,int_max,$1,$2)
|
||||
min = $(__gmsl_tr2)$(call __gmsl_int_wrap,int_min,$1,$2)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_gt, int_gte, int_lt, int_lte, int_eq, int_ne
|
||||
# Arguments: Two x's representation numbers to be compared
|
||||
# Returns: $(true) or $(false)
|
||||
#
|
||||
# int_gt First argument greater than second argument
|
||||
# int_gte First argument greater than or equal to second argument
|
||||
# int_lt First argument less than second argument
|
||||
# int_lte First argument less than or equal to second argument
|
||||
# int_eq First argument is numerically equal to the second argument
|
||||
# int_ne First argument is not numerically equal to the second argument
|
||||
# ----------------------------------------------------------------------------
|
||||
int_gt = $(__gmsl_tr2)$(call __gmsl_make_bool, \
|
||||
$(filter-out $(words $2), \
|
||||
$(words $(call int_max,$1,$2))))
|
||||
int_gte = $(__gmsl_tr2)$(call __gmsl_make_bool, \
|
||||
$(call int_gt,$1,$2)$(call int_eq,$1,$2))
|
||||
int_lt = $(__gmsl_tr2)$(call __gmsl_make_bool, \
|
||||
$(filter-out $(words $1), \
|
||||
$(words $(call int_max,$1,$2))))
|
||||
int_lte = $(__gmsl_tr2)$(call __gmsl_make_bool, \
|
||||
$(call int_lt,$1,$2)$(call int_eq,$1,$2))
|
||||
int_eq = $(__gmsl_tr2)$(call __gmsl_make_bool, \
|
||||
$(filter $(words $1),$(words $2)))
|
||||
int_ne = $(__gmsl_tr2)$(call __gmsl_make_bool, \
|
||||
$(filter-out $(words $1),$(words $2)))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: gt, gte, lt, lte, eq, ne
|
||||
# Arguments: Two integers to be compared
|
||||
# Returns: $(true) or $(false)
|
||||
#
|
||||
# gt First argument greater than second argument
|
||||
# gte First argument greater than or equal to second argument
|
||||
# lt First argument less than second argument
|
||||
# lte First argument less than or equal to second argument
|
||||
# eq First argument is numerically equal to the second argument
|
||||
# ne First argument is not numerically equal to the second argument
|
||||
# ----------------------------------------------------------------------------
|
||||
gt = $(__gmsl_tr2)$(call __gmsl_int_wrap2,int_gt,$1,$2)
|
||||
gte = $(__gmsl_tr2)$(call __gmsl_int_wrap2,int_gte,$1,$2)
|
||||
lt = $(__gmsl_tr2)$(call __gmsl_int_wrap2,int_lt,$1,$2)
|
||||
lte = $(__gmsl_tr2)$(call __gmsl_int_wrap2,int_lte,$1,$2)
|
||||
eq = $(__gmsl_tr2)$(call __gmsl_int_wrap2,int_eq,$1,$2)
|
||||
ne = $(__gmsl_tr2)$(call __gmsl_int_wrap2,int_ne,$1,$2)
|
||||
|
||||
# increment adds 1 to its argument, decrement subtracts 1. Note that
|
||||
# decrement does not range check and hence will not underflow, but
|
||||
# will incorrectly say that 0 - 1 = 0
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_inc
|
||||
# Arguments: 1: A number in x's representation
|
||||
# Returns: The number incremented by 1 in x's representation
|
||||
# ----------------------------------------------------------------------------
|
||||
int_inc = $(strip $(__gmsl_tr1)$1 x)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: inc
|
||||
# Arguments: 1: An integer
|
||||
# Returns: The argument incremented by 1
|
||||
# ----------------------------------------------------------------------------
|
||||
inc = $(__gmsl_tr1)$(call __gmsl_int_wrap1,int_inc,$1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_dec
|
||||
# Arguments: 1: A number in x's representation
|
||||
# Returns: The number decremented by 1 in x's representation
|
||||
# ----------------------------------------------------------------------------
|
||||
int_dec = $(__gmsl_tr1)$(strip \
|
||||
$(if $(call sne,0,$(words $1)), \
|
||||
$(wordlist 2,$(words $1),$1)))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: dec
|
||||
# Arguments: 1: An integer
|
||||
# Returns: The argument decremented by 1
|
||||
# ----------------------------------------------------------------------------
|
||||
dec = $(__gmsl_tr1)$(call __gmsl_int_wrap1,int_dec,$1)
|
||||
|
||||
# double doubles its argument, and halve halves it
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_double
|
||||
# Arguments: 1: A number in x's representation
|
||||
# Returns: The number doubled (i.e. * 2) and returned in x's representation
|
||||
# ----------------------------------------------------------------------------
|
||||
int_double = $(strip $(__gmsl_tr1)$1 $1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: double
|
||||
# Arguments: 1: An integer
|
||||
# Returns: The integer times 2
|
||||
# ----------------------------------------------------------------------------
|
||||
double = $(__gmsl_tr1)$(call __gmsl_int_wrap1,int_double,$1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: int_halve
|
||||
# Arguments: 1: A number in x's representation
|
||||
# Returns: The number halved (i.e. / 2) and returned in x's representation
|
||||
# ----------------------------------------------------------------------------
|
||||
int_halve = $(__gmsl_tr1)$(strip $(subst xx,x,$(filter-out xy x y, \
|
||||
$(join $1,$(foreach a,$1,y x)))))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: halve
|
||||
# Arguments: 1: An integer
|
||||
# Returns: The integer divided by 2
|
||||
# ----------------------------------------------------------------------------
|
||||
halve = $(__gmsl_tr1)$(call __gmsl_int_wrap1,int_halve,$1)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: sequence
|
||||
# Arguments: 1: An integer
|
||||
# 2: An integer
|
||||
# Returns: The sequence [arg1, arg2] of integers if arg1 < arg2 or
|
||||
# [arg2, arg1] if arg2 > arg1. If arg1 == arg1 return [arg1]
|
||||
# ----------------------------------------------------------------------------
|
||||
sequence = $(__gmsl_tr2)$(strip $(if $(call lte,$1,$2), \
|
||||
$(call __gmsl_sequence_up,$1,$2), \
|
||||
$(call __gmsl_sequence_dn,$2,$1)))
|
||||
|
||||
__gmsl_sequence_up = $(if $(call seq,$1,$2),$1,$1 $(call __gmsl_sequence_up,$(call inc,$1),$2))
|
||||
__gmsl_sequence_dn = $(if $(call seq,$1,$2),$1,$2 $(call __gmsl_sequence_dn,$1,$(call dec,$2)))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: dec2hex, dec2bin, dec2oct
|
||||
# Arguments: 1: An integer
|
||||
# Returns: The decimal argument converted to hexadecimal, binary or
|
||||
# octal
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
__gmsl_digit = $(subst 15,f,$(subst 14,e,$(subst 13,d,$(subst 12,c,$(subst 11,b,$(subst 10,a,$1))))))
|
||||
|
||||
dec2hex = $(call __gmsl_dec2base,$(call int_encode,$1),$(call int_encode,16))
|
||||
dec2bin = $(call __gmsl_dec2base,$(call int_encode,$1),$(call int_encode,2))
|
||||
dec2oct = $(call __gmsl_dec2base,$(call int_encode,$1),$(call int_encode,8))
|
||||
|
||||
__gmsl_base_divide = $(subst $2,X ,$1)
|
||||
__gmsl_q = $(strip $(filter X,$1))
|
||||
__gmsl_r = $(words $(filter x,$1))
|
||||
|
||||
__gmsl_dec2base = $(eval __gmsl_temp := $(call __gmsl_base_divide,$1,$2))$(call __gmsl_dec2base_,$(call __gmsl_q,$(__gmsl_temp)),$(call __gmsl_r,$(__gmsl_temp)),$2)
|
||||
__gmsl_dec2base_ = $(if $1,$(call __gmsl_dec2base,$(subst X,x,$1),$3))$(call __gmsl_digit,$2)
|
||||
|
||||
ifdef __gmsl_have_eval
|
||||
# ###########################################################################
|
||||
# ASSOCIATIVE ARRAYS
|
||||
# ###########################################################################
|
||||
|
||||
# Magic string that is very unlikely to appear in a key or value
|
||||
|
||||
__gmsl_aa_magic := faf192c8efbc25c27992c5bc5add390393d583c6
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: set
|
||||
# Arguments: 1: Name of associative array
|
||||
# 2: The key value to associate
|
||||
# 3: The value associated with the key
|
||||
# Returns: Nothing
|
||||
# ----------------------------------------------------------------------------
|
||||
set = $(__gmsl_tr3)$(call assert_no_space,$0,$1$2)$(call assert_no_dollar,$0,$1$2$3)$(eval __gmsl_aa_$1_$(__gmsl_aa_magic)_$2_gmsl_aa_$1 := $3)
|
||||
|
||||
# Only used internally by memoize function
|
||||
|
||||
__gmsl_set = $(call set,$1,$2,$3)$3
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: get
|
||||
# Arguments: 1: Name of associative array
|
||||
# 2: The key to retrieve
|
||||
# Returns: The value stored in the array for that key
|
||||
# ----------------------------------------------------------------------------
|
||||
get = $(strip $(__gmsl_tr2)$(call assert_no_space,$0,$1$2)$(call assert_no_dollar,$0,$1$2)$(__gmsl_aa_$1_$(__gmsl_aa_magic)_$2_gmsl_aa_$1))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: keys
|
||||
# Arguments: 1: Name of associative array
|
||||
# Returns: Returns a list of all defined keys in the array
|
||||
# ----------------------------------------------------------------------------
|
||||
keys = $(__gmsl_tr1)$(call assert_no_space,$0,$1)$(call assert_no_dollar,$0,$1)$(sort $(patsubst __gmsl_aa_$1_$(__gmsl_aa_magic)_%_gmsl_aa_$1,%, \
|
||||
$(filter __gmsl_aa_$1_$(__gmsl_aa_magic)_%_gmsl_aa_$1,$(.VARIABLES))))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: defined
|
||||
# Arguments: 1: Name of associative array
|
||||
# 2: The key to test
|
||||
# Returns: Returns true if the key is defined (i.e. not empty)
|
||||
# ----------------------------------------------------------------------------
|
||||
defined = $(__gmsl_tr2)$(call assert_no_space,$0,$1$2)$(call assert_no_dollar,$0,$1$2)$(call sne,$(call get,$1,$2),)
|
||||
|
||||
endif # __gmsl_have_eval
|
||||
|
||||
ifdef __gmsl_have_eval
|
||||
# ###########################################################################
|
||||
# NAMED STACKS
|
||||
# ###########################################################################
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: push
|
||||
# Arguments: 1: Name of stack
|
||||
# 2: Value to push onto the top of the stack (must not contain
|
||||
# a space)
|
||||
# Returns: None
|
||||
# ----------------------------------------------------------------------------
|
||||
push = $(__gmsl_tr2)$(call assert_no_space,$0,$1$2)$(call assert_no_dollar,$0,$1$2)$(eval __gmsl_stack_$1 := $2 $(if $(filter-out undefined,\
|
||||
$(origin __gmsl_stack_$1)),$(__gmsl_stack_$1)))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: pop
|
||||
# Arguments: 1: Name of stack
|
||||
# Returns: Top element from the stack after removing it
|
||||
# ----------------------------------------------------------------------------
|
||||
pop = $(__gmsl_tr1)$(call assert_no_space,$0,$1)$(call assert_no_dollar,$0,$1)$(strip $(if $(filter-out undefined,$(origin __gmsl_stack_$1)), \
|
||||
$(call first,$(__gmsl_stack_$1)) \
|
||||
$(eval __gmsl_stack_$1 := $(call rest,$(__gmsl_stack_$1)))))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: peek
|
||||
# Arguments: 1: Name of stack
|
||||
# Returns: Top element from the stack without removing it
|
||||
# ----------------------------------------------------------------------------
|
||||
peek = $(__gmsl_tr1)$(call assert_no_space,$0,$1)$(call assert_no_dollar,$0,$1)$(call first,$(__gmsl_stack_$1))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: depth
|
||||
# Arguments: 1: Name of stack
|
||||
# Returns: Number of items on the stack
|
||||
# ----------------------------------------------------------------------------
|
||||
depth = $(__gmsl_tr1)$(call assert_no_space,$0,$1)$(call assert_no_dollar,$0,$1)$(words $(__gmsl_stack_$1))
|
||||
|
||||
endif # __gmsl_have_eval
|
||||
|
||||
ifdef __gmsl_have_eval
|
||||
# ###########################################################################
|
||||
# STRING CACHE
|
||||
# ###########################################################################
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: memoize
|
||||
# Arguments: 1. Name of the function to be called if the string
|
||||
# has not been previously seen
|
||||
# 2. A string
|
||||
# Returns: Returns the result of a memo function (which the user must
|
||||
# define) on the passed in string and remembers the result.
|
||||
#
|
||||
# Example: Set memo = $(shell echo "$1" | md5sum) to make a cache
|
||||
# of MD5 hashes of strings. $(call memoize,memo,foo bar baz)
|
||||
# ----------------------------------------------------------------------------
|
||||
__gmsl_memoize = $(subst $(__gmsl_space),<2C>,$1)cc2af1bb7c4482f2ba75e338b963d3e7$(subst $(__gmsl_space),<2C>,$2)
|
||||
memoize = $(__gmsl_tr2)$(strip $(if $(call defined,__gmsl_m,$(__gmsl_memoize)),\
|
||||
$(call get,__gmsl_m,$(__gmsl_memoize)), \
|
||||
$(call __gmsl_set,__gmsl_m,$(__gmsl_memoize),$(call $1,$2))))
|
||||
|
||||
endif # __gmsl_have_eval
|
||||
|
||||
# ###########################################################################
|
||||
# DEBUGGING FACILITIES
|
||||
# ###########################################################################
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Target: gmsl-print-%
|
||||
# Arguments: The % should be replaced by the name of a variable that you
|
||||
# wish to print out.
|
||||
# Action: Echos the name of the variable that matches the % and its value.
|
||||
# For example, 'make gmsl-print-SHELL' will output the value of
|
||||
# the SHELL variable
|
||||
# ----------------------------------------------------------------------------
|
||||
gmsl-print-%: ; @echo $* = $($*)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: assert
|
||||
# Arguments: 1: A boolean that must be true or the assertion will fail
|
||||
# 2: The message to print with the assertion
|
||||
# Returns: None
|
||||
# ----------------------------------------------------------------------------
|
||||
assert = $(if $2,$(if $1,,$(call __gmsl_error,Assertion failure: $2)))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: assert_exists
|
||||
# Arguments: 1: Name of file that must exist, if it is missing an assertion
|
||||
# will be generated
|
||||
# Returns: None
|
||||
# ----------------------------------------------------------------------------
|
||||
assert_exists = $(if $0,$(call assert,$(wildcard $1),file '$1' missing))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: assert_no_dollar
|
||||
# Arguments: 1: Name of a function being executd
|
||||
# 2: Arguments to check
|
||||
# Returns: None
|
||||
# ----------------------------------------------------------------------------
|
||||
assert_no_dollar = $(call __gmsl_tr2)$(call assert,$(call not,$(findstring $(__gmsl_dollar),$2)),$1 called with a dollar sign in argument)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: assert_no_space
|
||||
# Arguments: 1: Name of a function being executd
|
||||
# 2: Arguments to check
|
||||
# Returns: None
|
||||
# ----------------------------------------------------------------------------
|
||||
ifeq ($(__gmsl_spaced_vars),$(false))
|
||||
assert_no_space = $(call assert,$(call not,$(findstring $(__gmsl_aa_magic),$(subst $(__gmsl_space),$(__gmsl_aa_magic),$2))),$1 called with a space in argument)
|
||||
else
|
||||
assert_no_space =
|
||||
endif
|
||||
85
vendor/github.com/vmware/vic/infra/util/gsml/gmsl
generated
vendored
Normal file
85
vendor/github.com/vmware/vic/infra/util/gsml/gmsl
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
#
|
||||
# GNU Make Standard Library (GMSL)
|
||||
#
|
||||
# A library of functions to be used with GNU Make's $(call) that
|
||||
# provides functionality not available in standard GNU Make.
|
||||
#
|
||||
# Copyright (c) 2005-2014 John Graham-Cumming
|
||||
#
|
||||
# This file is part of GMSL
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# Neither the name of the John Graham-Cumming nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# Determine if the library has already been included and if so don't
|
||||
# bother including it again
|
||||
|
||||
ifndef __gmsl_included
|
||||
|
||||
# Standard definitions for true and false. true is any non-empty
|
||||
# string, false is an empty string. These are intended for use with
|
||||
# $(if).
|
||||
|
||||
true := T
|
||||
false :=
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Function: not
|
||||
# Arguments: 1: A boolean value
|
||||
# Returns: Returns the opposite of the arg. (true -> false, false -> true)
|
||||
# ----------------------------------------------------------------------------
|
||||
not = $(if $1,$(false),$(true))
|
||||
|
||||
# Prevent reinclusion of the library
|
||||
|
||||
__gmsl_included := $(true)
|
||||
|
||||
# Try to determine where this file is located. If the caller did
|
||||
# include /foo/gmsl then extract the /foo/ so that __gmsl gets
|
||||
# included transparently
|
||||
|
||||
__gmsl_root :=
|
||||
|
||||
ifneq ($(MAKEFILE_LIST),)
|
||||
__gmsl_root := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
||||
|
||||
# If there are any spaces in the path in __gmsl_root then give up
|
||||
|
||||
ifeq (1,$(words $(__gmsl_root)))
|
||||
__gmsl_root := $(patsubst %gmsl,%,$(__gmsl_root))
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
include $(__gmsl_root)__gmsl
|
||||
|
||||
endif # __gmsl_included
|
||||
|
||||
30
vendor/github.com/vmware/vic/infra/util/vendor-manifest-parser/README.md
generated
vendored
Normal file
30
vendor/github.com/vmware/vic/infra/util/vendor-manifest-parser/README.md
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
### Dependency parsing tool
|
||||
|
||||
This tool is here to simplify checking the vendor manifest for consistency and for which tags are being used
|
||||
|
||||
It queries GitHub and takes into account any specific exceptions and produces a human-readable report on what our dependencies are
|
||||
|
||||
#### Building
|
||||
|
||||
There's no point building this tool all the time. It will be used sporadically for auditing purposes.
|
||||
Simply use go build <sourcefile> to create the binaries when needed
|
||||
|
||||
#### Running
|
||||
|
||||
The binaries are designed to be piped together to take each others output. This way, any intermediate json can be fed into a spreadsheet or likewise
|
||||
|
||||
Example usage:
|
||||
|
||||
```
|
||||
cat ../../manifest | gettags --uid "bcorrie@vmware.com" --pwd "foobedoo" > 1.json
|
||||
cat 1.json | groupbyrepo > 2.json
|
||||
cat 2.json | report --exceptionFile=../../exceptions
|
||||
|
||||
cat ../../manifest | gettags --uid "bcorrie@vmware.com" --pwd "foobedoo" | groupbyrepo | report --exceptionFile=../../exceptions
|
||||
```
|
||||
|
||||
#### Exceptions
|
||||
|
||||
It would be good practice for us to document cases in which a specific revision must be used, either because of a critical patch or equivalent. See exceptions file co-located with the manifest for examples.
|
||||
|
||||
Exceptions are outputted in the report and ensure that no-one attempts to modify a revision to a later tag without considering the exception
|
||||
138
vendor/github.com/vmware/vic/infra/util/vendor-manifest-parser/tool/gettags.go
generated
vendored
Normal file
138
vendor/github.com/vmware/vic/infra/util/vendor-manifest-parser/tool/gettags.go
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
// Copyright 2016 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"parser"
|
||||
)
|
||||
|
||||
var client *http.Client
|
||||
|
||||
var uid = flag.String("uid", "", "valid Github userid")
|
||||
var pwd = flag.String("pwd", "", "valid Github password")
|
||||
|
||||
func init() {
|
||||
flag.Usage = func() {
|
||||
fmt.Println("Usage: Queries Github for tags for each dependency sha in manifest input. Takes input via stdin. Eg: cat manifest | gettags")
|
||||
fmt.Println(" Uses basic auth, specified by --uid=<uid> and --pwd=<pwd>. Failure to specify will likely hit Github API limits")
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func findTagForSha(data []parser.TagData, sha string) string {
|
||||
for _, tag := range data {
|
||||
if tag.Commit.Sha == sha {
|
||||
return tag.Name
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func queryGit(u *url.URL) ([]byte, error) {
|
||||
getPath := "https://api.github.com/repos" + u.Path + "/tags"
|
||||
req, _ := http.NewRequest("GET", getPath, nil)
|
||||
if *uid != "" && *pwd != "" {
|
||||
req.SetBasicAuth(*uid, *pwd)
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unexpected error attempting HTTP GET to %v: %v", u, err)
|
||||
}
|
||||
return ioutil.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
// Currently only works for Github URLs as this is the vast majority. Rest will have HasTags == false
|
||||
func findTag(entry *parser.ManifestEntry) (*parser.ManifestEntry, error) {
|
||||
u, err := url.Parse(entry.Repository)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Malformed repository URL: %v", err)
|
||||
}
|
||||
if u.Host == "github.com" {
|
||||
tagdata, err := queryGit(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
td := []parser.TagData{}
|
||||
err = json.Unmarshal(tagdata, &td)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unparsable output: %s: %v", string(tagdata), err)
|
||||
}
|
||||
entry.HasTags = (len(td) == 0)
|
||||
if len(td) == 0 {
|
||||
entry.HasTags = false
|
||||
} else {
|
||||
entry.HasTags = true
|
||||
foundTag := findTagForSha(td, entry.Revision)
|
||||
if foundTag != "" {
|
||||
entry.RevisionTag = foundTag
|
||||
} else {
|
||||
entry.SuggestedTag = td[0].Name
|
||||
entry.SuggestedRev = td[0].Commit.Sha
|
||||
}
|
||||
}
|
||||
}
|
||||
return entry, err
|
||||
}
|
||||
|
||||
// Take the vendor manifest file and uses the Github APIs to retrieve the tag data for each Revision
|
||||
// Outputted data can be consumed by other parsers, or can be input to groupbyrepo
|
||||
func main() {
|
||||
|
||||
// Load the json from stdin (designed to support piping between binaries)
|
||||
input, err := parser.ReadFromStdin()
|
||||
if err != nil {
|
||||
fmt.Fprint(os.Stderr, err)
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
client = &http.Client{}
|
||||
|
||||
// Parse the data into useful types
|
||||
m, err := parser.ParseManifest(input)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to parse input json: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Find the tag for each repository. This is done serially.
|
||||
var foundTag *parser.ManifestEntry
|
||||
if err == nil {
|
||||
for i, me := range m.Dependencies {
|
||||
foundTag, err = findTag(&me)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
m.Dependencies[i] = *foundTag
|
||||
}
|
||||
}
|
||||
|
||||
// Output the original manifest data with new fields added (see ManifestEntry)
|
||||
if err == nil {
|
||||
output, _ := json.MarshalIndent(m, "", " ")
|
||||
fmt.Println(string(output))
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
}
|
||||
}
|
||||
82
vendor/github.com/vmware/vic/infra/util/vendor-manifest-parser/tool/groupbyrepo.go
generated
vendored
Normal file
82
vendor/github.com/vmware/vic/infra/util/vendor-manifest-parser/tool/groupbyrepo.go
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright 2016 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"parser"
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.Usage = func() {
|
||||
fmt.Println("Usage: Groups the json output of gettags by repository. Takes input via stdin. Eg: gettags | groupbyrepo")
|
||||
}
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func groupByRepo(m parser.Manifest) []*parser.ManifestByRepo {
|
||||
var repoMap = make(map[string]*parser.ManifestByRepo)
|
||||
|
||||
for _, me := range m.Dependencies {
|
||||
u, _ := url.Parse(me.Repository)
|
||||
repo := u.Path
|
||||
mapEntry := repoMap[repo]
|
||||
if mapEntry == nil {
|
||||
mapEntry = &parser.ManifestByRepo{Repository: repo}
|
||||
}
|
||||
mapEntry.Dependencies = append(mapEntry.Dependencies, me)
|
||||
repoMap[repo] = mapEntry
|
||||
}
|
||||
|
||||
values := make([]*parser.ManifestByRepo, len(repoMap))
|
||||
i := 0
|
||||
for _, k := range repoMap {
|
||||
values[i] = k
|
||||
i++
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
// Takes json output from gettags and groups it by repository. Output is in json format and can be further parsed by report
|
||||
func main() {
|
||||
|
||||
// Read json data from stdin (designed to support piping between binaries)
|
||||
input, err := parser.ReadFromStdin()
|
||||
if err != nil {
|
||||
fmt.Fprint(os.Stderr, err)
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Parse the data into useful types
|
||||
m, err := parser.ParseManifest(input)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing input json: %v", err)
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Group the data into a slice of repo->dependencies
|
||||
values := groupByRepo(m)
|
||||
|
||||
// Format the output to stdout
|
||||
output, err := json.MarshalIndent(values, "", " ")
|
||||
fmt.Println(string(output))
|
||||
}
|
||||
115
vendor/github.com/vmware/vic/infra/util/vendor-manifest-parser/tool/report.go
generated
vendored
Normal file
115
vendor/github.com/vmware/vic/infra/util/vendor-manifest-parser/tool/report.go
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright 2016 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"parser"
|
||||
)
|
||||
|
||||
var exceptionFile = flag.String("exceptionFile", "", "json file containing documented exceptions to using tagged releases")
|
||||
|
||||
func init() {
|
||||
flag.Usage = func() {
|
||||
fmt.Println("Usage: Formats the json output of groupbyrepo and considers json exceptions. Takes input via stdin. Eg: gettags | groupbyrepo | report")
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func printOutput(out io.Writer, repos parser.SortedManifestByRepo, exceptions map[string]string) {
|
||||
for _, repo := range repos {
|
||||
fmt.Fprintf(out, "\n%s\n", repo.Repository)
|
||||
for _, dep := range repo.Dependencies {
|
||||
fmt.Fprintf(out, "\t%s", dep.Importpath)
|
||||
if exceptions[dep.Revision] == "" {
|
||||
if dep.HasTags {
|
||||
if dep.RevisionTag != "" {
|
||||
fmt.Fprintf(out, " is tagged as "+dep.RevisionTag)
|
||||
} else {
|
||||
fmt.Fprintf(out, " "+dep.Revision+" is an untagged version. Most recent tag is %s for sha %s", dep.SuggestedTag, dep.SuggestedRev)
|
||||
}
|
||||
} else {
|
||||
if strings.Index(dep.Repository, "github.com") == -1 {
|
||||
fmt.Fprintf(out, " "+dep.Revision+" sha is from non-Github repo")
|
||||
} else {
|
||||
fmt.Fprintf(out, " "+dep.Revision+" sha is from a repo with no tags")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(out, " "+dep.Revision+" MUST BE THIS REVISION because %s", exceptions[dep.Revision])
|
||||
}
|
||||
fmt.Fprintf(out, "\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func loadAndParseExceptions() (map[string]string, error) {
|
||||
var exceptions map[string]string
|
||||
var err error
|
||||
|
||||
if *exceptionFile != "" {
|
||||
exceptions = make(map[string]string)
|
||||
data, err := ioutil.ReadFile(*exceptionFile)
|
||||
if err == nil {
|
||||
e := []parser.UntaggedException{}
|
||||
err := json.Unmarshal(data, &e)
|
||||
if err == nil {
|
||||
for _, v := range e {
|
||||
exceptions[v.Revision] = v.Reason
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return exceptions, err
|
||||
}
|
||||
|
||||
// Takes the output from groupbyrepo, plus exception data from a file, and produces a human-parsable report
|
||||
func main() {
|
||||
|
||||
// Load the json from stdin (designed to support piping between binaries)
|
||||
input, err := parser.ReadFromStdin()
|
||||
if err != nil {
|
||||
fmt.Fprint(os.Stderr, err)
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Parse the data into useful types
|
||||
repos, err := parser.ParseManifestByRepo(input)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to parse input json: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Load the exception file into useful types
|
||||
exceptions, err := loadAndParseExceptions()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error loading exceptions file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Write the report to stdout
|
||||
sort.Sort(parser.SortedManifestByRepo(repos))
|
||||
printOutput(os.Stdout, repos, exceptions)
|
||||
}
|
||||
105
vendor/github.com/vmware/vic/infra/util/vendor-manifest-parser/types.go
generated
vendored
Normal file
105
vendor/github.com/vmware/vic/infra/util/vendor-manifest-parser/types.go
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
// Copyright 2016 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package parser
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Manifest is a golang representation of the manifest json
|
||||
type Manifest struct {
|
||||
Version int
|
||||
Dependencies []ManifestEntry
|
||||
}
|
||||
|
||||
func ParseManifest(input []byte) (Manifest, error) {
|
||||
m := Manifest{}
|
||||
err := json.Unmarshal(input, &m)
|
||||
return m, err
|
||||
}
|
||||
|
||||
// ManifestByRepo is like Manifest, except that only the Dependencies for a specific repo are included
|
||||
type ManifestByRepo struct {
|
||||
Repository string
|
||||
Dependencies []ManifestEntry
|
||||
}
|
||||
|
||||
func ParseManifestByRepo(input []byte) ([]ManifestByRepo, error) {
|
||||
m := []ManifestByRepo{}
|
||||
err := json.Unmarshal(input, &m)
|
||||
return m, err
|
||||
}
|
||||
|
||||
type SortedManifestByRepo []ManifestByRepo
|
||||
|
||||
func (slice SortedManifestByRepo) Len() int {
|
||||
return len(slice)
|
||||
}
|
||||
|
||||
func (slice SortedManifestByRepo) Less(i, j int) bool {
|
||||
return slice[i].Repository < slice[j].Repository
|
||||
}
|
||||
|
||||
func (slice SortedManifestByRepo) Swap(i, j int) {
|
||||
slice[i], slice[j] = slice[j], slice[i]
|
||||
}
|
||||
|
||||
// ManifestEntry includes the fields from the original manifest plus some additional fields:
|
||||
// HasTags - does the repository have tags
|
||||
// RevisionTag - is there a tag corresponding to this revision
|
||||
// SuggestedTag - if there is no tag, the most recent tag is listed
|
||||
// SuggestedRev - if a tag is suggested, the revision is also suggested
|
||||
type ManifestEntry struct {
|
||||
Importpath string
|
||||
Repository string
|
||||
Vcs string
|
||||
Revision string
|
||||
HasTags bool
|
||||
RevisionTag string
|
||||
SuggestedTag string
|
||||
SuggestedRev string
|
||||
Branch string
|
||||
}
|
||||
|
||||
// TagData is the golang representation of the json returned from Github
|
||||
type TagData struct {
|
||||
Name string
|
||||
Commit TagDataCommit
|
||||
}
|
||||
|
||||
// TagDataCommit is the golang representation of the json returned from Github
|
||||
type TagDataCommit struct {
|
||||
Sha string
|
||||
Url string
|
||||
}
|
||||
|
||||
// UntaggedException is the golang representation of a documented exception to revision not being tagged
|
||||
type UntaggedException struct {
|
||||
Revision string
|
||||
Reason string
|
||||
}
|
||||
|
||||
func ReadFromStdin() ([]byte, error) {
|
||||
bio := bufio.NewReader(os.Stdin)
|
||||
input, err := bio.ReadBytes(127) // Read all input to EOF
|
||||
if err != io.EOF {
|
||||
return nil, fmt.Errorf("Failed to read input: %v\n", err)
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
Reference in New Issue
Block a user