github.com/georgethebeatle/containerd@v0.2.5/hack/.vendor-helpers.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  PROJECT=github.com/docker/containerd
     4  
     5  # Downloads dependencies into vendor/ directory
     6  mkdir -p vendor
     7  
     8  export GOPATH="$GOPATH:${PWD}/vendor"
     9  
    10  find='find'
    11  if [ "$(go env GOHOSTOS)" = 'windows' ]; then
    12  	find='/usr/bin/find'
    13  fi
    14  
    15  clone() {
    16  	local vcs="$1"
    17  	local pkg="$2"
    18  	local rev="$3"
    19  	local url="$4"
    20  
    21  	: ${url:=https://$pkg}
    22  	local target="vendor/src/$pkg"
    23  
    24  	echo -n "$pkg @ $rev: "
    25  
    26  	if [ -d "$target" ]; then
    27  		echo -n 'rm old, '
    28  		rm -rf "$target"
    29  	fi
    30  
    31  	echo -n 'clone, '
    32  	case "$vcs" in
    33  		git)
    34  			git clone --quiet --no-checkout "$url" "$target"
    35  			( cd "$target" && git checkout --quiet "$rev" && git reset --quiet --hard "$rev" )
    36  			;;
    37  		hg)
    38  			hg clone --quiet --updaterev "$rev" "$url" "$target"
    39  			;;
    40  	esac
    41  
    42  	echo -n 'rm VCS, '
    43  	( cd "$target" && rm -rf .{git,hg} )
    44  
    45  	echo -n 'rm vendor, '
    46  	( cd "$target" && rm -rf vendor Godeps/_workspace )
    47  
    48  	echo done
    49  }
    50  
    51  clean() {
    52  	local packages=(
    53  		"${PROJECT}/containerd" # package main
    54  		"${PROJECT}/ctr" # package main
    55  		"${PROJECT}/containerd-shim" # package main
    56  		"${PROJECT}/integration-test" # package main
    57  	)
    58  	local platforms=( linux/amd64 linux/386 windows/amd64 windows/386 darwin/amd64 )
    59  	local buildTagCombos=(
    60  		'libcontainer runc seccomp'
    61  	)
    62  
    63  	echo
    64  
    65  	echo -n 'collecting import graph, '
    66  	local IFS=$'\n'
    67  	local imports=( $(
    68  		for platform in "${platforms[@]}"; do
    69  			export GOOS="${platform%/*}";
    70  			export GOARCH="${platform##*/}";
    71  			for buildTags in "${buildTagCombos[@]}"; do
    72  				go list -e -tags "$buildTags" -f '{{join .Deps "\n"}}' "${packages[@]}"
    73  				go list -e -tags "$buildTags" -f '{{join .TestImports "\n"}}' "${packages[@]}"
    74  			done
    75  		done | grep -vE "^${PROJECT}" | sort -u
    76  	) )
    77  	imports=( $(go list -e -f '{{if not .Standard}}{{.ImportPath}}{{end}}' "${imports[@]}") )
    78  	unset IFS
    79  
    80  	echo -n 'pruning unused packages, '
    81  	findArgs=(
    82  		# for some reason go list doesn't detect this as a dependency
    83  		-path vendor/src/github.com/vdemeester/shakers
    84  	)
    85  	for import in "${imports[@]}"; do
    86  		[ "${#findArgs[@]}" -eq 0 ] || findArgs+=( -or )
    87  		findArgs+=( -path "vendor/src/$import" )
    88  	done
    89  	local IFS=$'\n'
    90  	local prune=( $($find vendor -depth -type d -not '(' "${findArgs[@]}" ')') )
    91  	unset IFS
    92  	for dir in "${prune[@]}"; do
    93  		$find "$dir" -maxdepth 1 -not -type d -not -name 'LICENSE*' -not -name 'COPYING*' -exec rm -v -f '{}' ';'
    94  		rmdir "$dir" 2>/dev/null || true
    95  	done
    96  
    97  	echo -n 'pruning unused files, '
    98  	$find vendor -type f -name '*_test.go' -exec rm -v '{}' ';'
    99  
   100  	echo done
   101  }
   102  
   103  # Fix up hard-coded imports that refer to Godeps paths so they'll work with our vendoring
   104  fix_rewritten_imports () {
   105         local pkg="$1"
   106         local remove="${pkg}/Godeps/_workspace/src/"
   107         local target="vendor/src/$pkg"
   108  
   109         echo "$pkg: fixing rewritten imports"
   110         $find "$target" -name \*.go -exec sed -i -e "s|\"${remove}|\"|g" {} \;
   111  }