Move checkdeps to buildscripts/, additionally add patch.sh

patch.sh patches any source codepath with the patch provided,
for now the patch file included is a way to Hide flags for
codegangsta until it is merged upstream.

Not part of the build yet.
This commit is contained in:
Harshavardhana
2015-03-18 11:20:26 -07:00
parent 635507453e
commit ac8a0e109f
4 changed files with 293 additions and 1 deletions
+201
View File
@@ -0,0 +1,201 @@
#!/usr/bin/env bash
#
# Minio Commander, (C) 2015 Minio, Inc.
#
# 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.
#
_init() {
## Minimum required versions for build dependencies
GCC_VERSION="4.0"
CLANG_VERSION="3.5"
YASM_VERSION="1.2.0"
GIT_VERSION="1.0"
GO_VERSION="1.4"
OSX_VERSION="10.8"
UNAME=$(uname -sm)
## Check all dependencies are present
MISSING=""
}
###
#
# Takes two arguments
# arg1: version number in `x.x.x` format
# arg2: version number in `x.x.x` format
#
# example: check_version "$version1" "$version2"
#
# returns:
# 0 - Installed version is equal to required
# 1 - Installed version is greater than required
# 2 - Installed version is lesser than required
# 3 - If args have length zero
#
####
check_version () {
## validate args
[[ -z "$1" ]] && return 3
[[ -z "$2" ]] && return 3
if [[ $1 == $2 ]]; then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++)); do
if [[ -z ${ver2[i]} ]]; then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]})); then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]})); then
## Installed version is lesser than required - Bad condition
return 2
fi
done
return 0
}
check_golang_env() {
echo ${GOROOT:?} 2>&1 >/dev/null
if [ $? -eq 1 ]; then
echo "ERROR"
echo "GOROOT environment variable missing, please refer to Go installation document"
echo "https://github.com/Minio-io/minio/blob/master/BUILDDEPS.md#install-go-13"
exit 1
fi
echo ${GOPATH:?} 2>&1 >/dev/null
if [ $? -eq 1 ]; then
echo "ERROR"
echo "GOPATH environment variable missing, please refer to Go installation document"
echo "https://github.com/Minio-io/minio/blob/master/BUILDDEPS.md#install-go-13"
exit 1
fi
}
is_supported_os() {
case ${UNAME%% *} in
"Linux")
os="linux"
;;
"Darwin")
osx_host_version=$(env sw_vers -productVersion)
check_version "${osx_host_version}" "${OSX_VERSION}"
[[ $? -ge 2 ]] && die "Minimum OSX version supported is ${OSX_VERSION}"
;;
"*")
echo "Exiting.. unsupported operating system found"
exit 1;
esac
}
is_supported_arch() {
local supported
case ${UNAME##* } in
"x86_64")
supported=1
;;
*)
supported=0
;;
esac
if [ $supported -eq 0 ]; then
echo "Invalid arch: ${UNAME} not supported, please use x86_64/amd64"
exit 1;
fi
}
check_deps() {
check_version "$(env go version 2>/dev/null | sed 's/^.* go\([0-9.]*\).*$/\1/')" "${GO_VERSION}"
if [ $? -ge 2 ]; then
MISSING="${MISSING} golang(1.4)"
fi
check_version "$(env git --version 2>/dev/null | sed -e 's/^.* \([0-9.\].*\).*$/\1/' -e 's/^\([0-9.\]*\).*/\1/g')" "${GIT_VERSION}"
if [ $? -ge 2 ]; then
MISSING="${MISSING} git"
fi
case ${UNAME%% *} in
"Linux")
check_version "$(env gcc --version 2>/dev/null | sed 's/^.* \([0-9.]*\).*$/\1/' | head -1)" "${GCC_VERSION}"
if [ $? -ge 2 ]; then
MISSING="${MISSING} build-essential"
fi
;;
"Darwin")
check_version "$(env gcc --version 2>/dev/null | sed 's/^.* \([0-9.]*\).*$/\1/' | head -1)" "${CLANG_VERSION}"
if [ $? -ge 2 ]; then
MISSING="${MISSING} xcode-cli"
fi
;;
"*")
;;
esac
check_version "$(env yasm --version 2>/dev/null | sed 's/^.* \([0-9.]*\).*$/\1/' | head -1)" "${YASM_VERSION}"
if [ $? -ge 2 ]; then
MISSING="${MISSING} yasm(1.2.0)"
fi
env mkdocs help >/dev/null 2>&1
if [ $? -ne 0 ]; then
MISSING="${MISSING} mkdocs"
fi
}
main() {
echo -n "Check for supported arch.. "
is_supported_arch
echo -n "Check for supported os.. "
is_supported_os
echo -n "Checking if proper environment variables are set.. "
check_golang_env
echo "Done"
echo "Using GOPATH=${GOPATH} and GOROOT=${GOROOT}"
echo -n "Checking dependencies for Minio.. "
check_deps
## If dependencies are missing, warn the user and abort
if [ "x${MISSING}" != "x" ]; then
echo "ERROR"
echo
echo "The following build tools are missing:"
echo
echo "** ${MISSING} **"
echo
echo "Please install them "
echo "${MISSING}"
echo
echo "Follow https://github.com/Minio-io/minio/blob/master/BUILDDEPS.md for further instructions"
exit 1
fi
echo "Done"
}
_init && main "$@"
+43
View File
@@ -0,0 +1,43 @@
#!/bin/bash
usage() {
echo "Invalid arguments needs a <patch> <directory> "
exit 1
}
_init() {
if [ $# -lt 2 ]; then
usage;
fi
if [ ! -f $1 ]; then
usage;
fi
if [ ! -d $2 ]; then
usage;
fi
CODEPATH=$2
PATCH=$1
CP="/bin/cp"
P="/usr/bin/patch"
B="/usr/bin/basename"
R="/bin/rm"
}
main () {
echo ${PWD}
echo "Copying ${PATCH} to ${CODEPATH}"
${CP} -f ${PATCH} ${CODEPATH}
_pwd=${PWD}
cd ${CODEPATH}
patch=$(${B} ${PATCH})
${P} -p1 -R < ${patch}
${R} -f ${patch}
cd ${_pwd}
}
_init "$@" && main "$@"
@@ -0,0 +1,249 @@
diff -pruN cli-h/flag.go cli/flag.go
--- cli-h/flag.go 2015-03-18 10:57:04.100914754 -0700
+++ cli/flag.go 2015-03-18 10:54:31.284907675 -0700
@@ -12,6 +12,7 @@ import (
// This flag enables bash-completion for all commands and subcommands
var BashCompletionFlag = BoolFlag{
Name: "generate-bash-completion",
+ Hide: true,
}
// This flag prints the version for the application
@@ -36,6 +37,7 @@ type Flag interface {
// Apply Flag settings to the given flag set
Apply(*flag.FlagSet)
getName() string
+ isNotHidden() bool
}
func flagSet(name string, flags []Flag) *flag.FlagSet {
@@ -67,6 +69,7 @@ type GenericFlag struct {
Value Generic
Usage string
EnvVar string
+ Hide bool
}
// String returns the string representation of the generic flag to display the
@@ -99,6 +102,10 @@ func (f GenericFlag) getName() string {
return f.Name
}
+func (f GenericFlag) isNotHidden() bool {
+ return !f.Hide
+}
+
type StringSlice []string
func (f *StringSlice) Set(value string) error {
@@ -119,6 +126,7 @@ type StringSliceFlag struct {
Value *StringSlice
Usage string
EnvVar string
+ Hide bool
}
func (f StringSliceFlag) String() string {
@@ -152,6 +160,10 @@ func (f StringSliceFlag) getName() strin
return f.Name
}
+func (f StringSliceFlag) isNotHidden() bool {
+ return !f.Hide
+}
+
type IntSlice []int
func (f *IntSlice) Set(value string) error {
@@ -178,6 +190,7 @@ type IntSliceFlag struct {
Value *IntSlice
Usage string
EnvVar string
+ Hide bool
}
func (f IntSliceFlag) String() string {
@@ -214,10 +227,15 @@ func (f IntSliceFlag) getName() string {
return f.Name
}
+func (f IntSliceFlag) isNotHidden() bool {
+ return !f.Hide
+}
+
type BoolFlag struct {
Name string
Usage string
EnvVar string
+ Hide bool
}
func (f BoolFlag) String() string {
@@ -248,10 +266,15 @@ func (f BoolFlag) getName() string {
return f.Name
}
+func (f BoolFlag) isNotHidden() bool {
+ return !f.Hide
+}
+
type BoolTFlag struct {
Name string
Usage string
EnvVar string
+ Hide bool
}
func (f BoolTFlag) String() string {
@@ -282,11 +305,16 @@ func (f BoolTFlag) getName() string {
return f.Name
}
+func (f BoolTFlag) isNotHidden() bool {
+ return !f.Hide
+}
+
type StringFlag struct {
Name string
Value string
Usage string
EnvVar string
+ Hide bool
}
func (f StringFlag) String() string {
@@ -298,7 +326,6 @@ func (f StringFlag) String() string {
} else {
fmtString = "%s %v\t%v"
}
-
return withEnvHint(f.EnvVar, fmt.Sprintf(fmtString, prefixedNames(f.Name), f.Value, f.Usage))
}
@@ -322,11 +349,16 @@ func (f StringFlag) getName() string {
return f.Name
}
+func (f StringFlag) isNotHidden() bool {
+ return !f.Hide
+}
+
type IntFlag struct {
Name string
Value int
Usage string
EnvVar string
+ Hide bool
}
func (f IntFlag) String() string {
@@ -356,11 +388,16 @@ func (f IntFlag) getName() string {
return f.Name
}
+func (f IntFlag) isNotHidden() bool {
+ return !f.Hide
+}
+
type DurationFlag struct {
Name string
Value time.Duration
Usage string
EnvVar string
+ Hide bool
}
func (f DurationFlag) String() string {
@@ -390,11 +427,16 @@ func (f DurationFlag) getName() string {
return f.Name
}
+func (f DurationFlag) isNotHidden() bool {
+ return !f.Hide
+}
+
type Float64Flag struct {
Name string
Value float64
Usage string
EnvVar string
+ Hide bool
}
func (f Float64Flag) String() string {
@@ -423,6 +465,10 @@ func (f Float64Flag) getName() string {
return f.Name
}
+func (f Float64Flag) isNotHidden() bool {
+ return !f.Hide
+}
+
func prefixFor(name string) (prefix string) {
if len(name) == 1 {
prefix = "-"
diff -pruN cli-h/help.go cli/help.go
--- cli-h/help.go 2015-03-18 10:57:04.100914754 -0700
+++ cli/help.go 2015-03-18 10:54:31.284907675 -0700
@@ -14,9 +14,9 @@ USAGE:
VERSION:
{{.Version}}
-AUTHOR(S):
- {{range .Authors}}{{ . }}
- {{end}}
+AUTHOR(S):
+ {{range .Authors}}{{ . }} {{end}}
+
COMMANDS:
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
{{end}}{{if .Flags}}
@@ -96,7 +96,15 @@ var HelpPrinter helpPrinter = nil
var VersionPrinter = printVersion
func ShowAppHelp(c *Context) {
- HelpPrinter(AppHelpTemplate, c.App)
+ // Make a copy of c.App context
+ app := *c.App
+ app.Flags = make([]Flag, 0)
+ for _, flag := range c.App.Flags {
+ if flag.isNotHidden() {
+ app.Flags = append(app.Flags, flag)
+ }
+ }
+ HelpPrinter(AppHelpTemplate, app)
}
// Prints the list of subcommands as the default app completion method
@@ -112,13 +120,29 @@ func DefaultAppComplete(c *Context) {
func ShowCommandHelp(c *Context, command string) {
// show the subcommand help for a command with subcommands
if command == "" {
- HelpPrinter(SubcommandHelpTemplate, c.App)
+ // Make a copy of c.App context
+ app := *c.App
+ app.Flags = make([]Flag, 0)
+ for _, flag := range c.App.Flags {
+ if flag.isNotHidden() {
+ app.Flags = append(app.Flags, flag)
+ }
+ }
+ HelpPrinter(SubcommandHelpTemplate, app)
return
}
for _, c := range c.App.Commands {
if c.HasName(command) {
- HelpPrinter(CommandHelpTemplate, c)
+ // Make a copy of command context
+ c0 := c
+ c0.Flags = make([]Flag, 0)
+ for _, flag := range c.Flags {
+ if flag.isNotHidden() {
+ c0.Flags = append(c0.Flags, flag)
+ }
+ }
+ HelpPrinter(CommandHelpTemplate, c0)
return
}
}