From a4e257e198424f5ec4d6fcb55517f83d37b1bd0a Mon Sep 17 00:00:00 2001 From: Nick Miyake Date: Sat, 16 Nov 2019 21:48:48 -0800 Subject: [PATCH] Use Go modules for gofiles (#12) Set up gofiles package to use modules. --- gofiles/Gopkg.lock | 56 ----- gofiles/Gopkg.toml | 38 --- gofiles/go.mod | 8 + gofiles/go.sum | 13 + gofiles/godel/config/godel.yml | 9 +- gofiles/gofiles_test.go | 33 +++ .../vendor/github.com/davecgh/go-spew/LICENSE | 2 +- .../github.com/davecgh/go-spew/spew/bypass.go | 187 +++++++------- .../davecgh/go-spew/spew/bypasssafe.go | 2 +- .../github.com/davecgh/go-spew/spew/common.go | 2 +- .../github.com/davecgh/go-spew/spew/dump.go | 10 +- .../github.com/davecgh/go-spew/spew/format.go | 4 +- .../github.com/nmiyake/pkg/{ => dirs}/LICENSE | 0 .../vendor/github.com/nmiyake/pkg/dirs/go.mod | 3 + .../vendor/github.com/nmiyake/pkg/dirs/godelw | 230 ++++++++++++++++++ .../pkg/godel/config/license-plugin.yml | 22 -- gofiles/vendor/gopkg.in/yaml.v2/decode.go | 48 +--- gofiles/vendor/gopkg.in/yaml.v2/resolve.go | 2 +- gofiles/vendor/gopkg.in/yaml.v2/scannerc.go | 16 -- gofiles/vendor/modules.txt | 11 + 20 files changed, 416 insertions(+), 280 deletions(-) delete mode 100644 gofiles/Gopkg.lock delete mode 100644 gofiles/Gopkg.toml create mode 100644 gofiles/go.mod create mode 100644 gofiles/go.sum rename gofiles/vendor/github.com/nmiyake/pkg/{ => dirs}/LICENSE (100%) create mode 100644 gofiles/vendor/github.com/nmiyake/pkg/dirs/go.mod create mode 100644 gofiles/vendor/github.com/nmiyake/pkg/dirs/godelw delete mode 100644 gofiles/vendor/github.com/nmiyake/pkg/godel/config/license-plugin.yml create mode 100644 gofiles/vendor/modules.txt diff --git a/gofiles/Gopkg.lock b/gofiles/Gopkg.lock deleted file mode 100644 index 65b7799..0000000 --- a/gofiles/Gopkg.lock +++ /dev/null @@ -1,56 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" - name = "github.com/davecgh/go-spew" - packages = ["spew"] - pruneopts = "UT" - revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" - version = "v1.1.1" - -[[projects]] - branch = "develop" - digest = "1:f9ca56453aa02d1c7799790f2b3bd8192396ddbe5ee8002208be30dca420bdc8" - name = "github.com/nmiyake/pkg" - packages = ["dirs"] - pruneopts = "UT" - revision = "ae0375219445def9b33b6fcbf5eb8f4dd68ea561" - -[[projects]] - digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - pruneopts = "UT" - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - digest = "1:99d32780e5238c2621fff621123997c3e3cca96db8be13179013aea77dfab551" - name = "github.com/stretchr/testify" - packages = [ - "assert", - "require", - ] - pruneopts = "UT" - revision = "221dbe5ed46703ee255b1da0dec05086f5035f62" - version = "v1.4.0" - -[[projects]] - digest = "1:f26a5d382387e03a40d1471dddfba85dfff9bf05352d7e42d37612677c4d3c5c" - name = "gopkg.in/yaml.v2" - packages = ["."] - pruneopts = "UT" - revision = "f90ceb4f409096b60e2e9076b38b304b8246e5fa" - version = "v2.2.5" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/nmiyake/pkg/dirs", - "github.com/stretchr/testify/assert", - "github.com/stretchr/testify/require", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/gofiles/Gopkg.toml b/gofiles/Gopkg.toml deleted file mode 100644 index 5098015..0000000 --- a/gofiles/Gopkg.toml +++ /dev/null @@ -1,38 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - -[[constraint]] - branch = "develop" - name = "github.com/nmiyake/pkg" - -[[constraint]] - name = "github.com/stretchr/testify" - version = "1.4.0" - -[prune] - go-tests = true - unused-packages = true diff --git a/gofiles/go.mod b/gofiles/go.mod new file mode 100644 index 0000000..956a200 --- /dev/null +++ b/gofiles/go.mod @@ -0,0 +1,8 @@ +module github.com/nmiyake/pkg/gofiles + +go 1.13 + +require ( + github.com/nmiyake/pkg/dirs v1.0.0 + github.com/stretchr/testify v1.4.0 +) diff --git a/gofiles/go.sum b/gofiles/go.sum new file mode 100644 index 0000000..2a33174 --- /dev/null +++ b/gofiles/go.sum @@ -0,0 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/nmiyake/pkg/dirs v1.0.0 h1:pYeIw1wH7jh5/ew8naGE4Q56byJG7Uyi8PwwhVe/MTg= +github.com/nmiyake/pkg/dirs v1.0.0/go.mod h1:r6/PkZ3CA1szGfQkxcHheEjBWi6Zu6jLb+lQmRXEyvM= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/gofiles/godel/config/godel.yml b/gofiles/godel/config/godel.yml index ae74f87..da1440d 100644 --- a/gofiles/godel/config/godel.yml +++ b/gofiles/godel/config/godel.yml @@ -3,10 +3,13 @@ plugins: - https://palantir.bintray.com/releases/{{GroupPath}}/{{Product}}/{{Version}}/{{Product}}-{{Version}}-{{OS}}-{{Arch}}.tgz plugins: - locator: - id: com.palantir.godel-dep-plugin:dep-plugin:1.1.0 + id: com.palantir.godel-mod-plugin:mod-plugin:1.0.1 checksums: - darwin-amd64: 946b0def510a7e94b46bb635a67f00c05243505e2a2ef9b0b7dab45b0437be1f - linux-amd64: cc2729e7f25c0121f841e237238c11514ee4c1376c458a1c4997ee86de17b209 + darwin-amd64: df22922bacfe4e4e7c255607a0aace176205f04ae001f3746276fcfab1780e01 + linux-amd64: a2697b3d504bb37c2fd8831a66c7014927a6d94e4dfb9765b4764354370a1ab6 +environment: + GO111MODULE: "on" + GOFLAGS: "-mod=vendor" exclude: names: - "\\..+" diff --git a/gofiles/gofiles_test.go b/gofiles/gofiles_test.go index 6ee65eb..4b6b78f 100644 --- a/gofiles/gofiles_test.go +++ b/gofiles/gofiles_test.go @@ -23,6 +23,7 @@ package gofiles_test import ( + "os" "os/exec" "testing" @@ -33,6 +34,12 @@ import ( ) func TestWriteGoFiles(t *testing.T) { + restoreEnvVars := setEnvVars(map[string]string{ + "GO111MODULE": "off", + "GOFLAGS": "", + }) + defer restoreEnvVars() + dir, cleanup, err := dirs.TempDir(".", "") require.NoError(t, err) defer cleanup() @@ -72,3 +79,29 @@ func Baz() string { assert.Equal(t, "bar baz\n", string(output)) } + +func setEnvVars(envVars map[string]string) func() { + origVars := make(map[string]string) + var unsetVars []string + for k := range envVars { + val, ok := os.LookupEnv(k) + if !ok { + unsetVars = append(unsetVars, k) + continue + } + origVars[k] = val + } + + for k, v := range envVars { + _ = os.Setenv(k, v) + } + + return func() { + for _, k := range unsetVars { + _ = os.Unsetenv(k) + } + for k, v := range origVars { + _ = os.Setenv(k, v) + } + } +} diff --git a/gofiles/vendor/github.com/davecgh/go-spew/LICENSE b/gofiles/vendor/github.com/davecgh/go-spew/LICENSE index bc52e96..c836416 100644 --- a/gofiles/vendor/github.com/davecgh/go-spew/LICENSE +++ b/gofiles/vendor/github.com/davecgh/go-spew/LICENSE @@ -2,7 +2,7 @@ ISC License Copyright (c) 2012-2016 Dave Collins -Permission to use, copy, modify, and/or distribute this software for any +Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. diff --git a/gofiles/vendor/github.com/davecgh/go-spew/spew/bypass.go b/gofiles/vendor/github.com/davecgh/go-spew/spew/bypass.go index 7929947..8a4a658 100644 --- a/gofiles/vendor/github.com/davecgh/go-spew/spew/bypass.go +++ b/gofiles/vendor/github.com/davecgh/go-spew/spew/bypass.go @@ -16,9 +16,7 @@ // when the code is not running on Google App Engine, compiled by GopherJS, and // "-tags safe" is not added to the go build command line. The "disableunsafe" // tag is deprecated and thus should not be used. -// Go versions prior to 1.4 are disabled because they use a different layout -// for interfaces which make the implementation of unsafeReflectValue more complex. -// +build !js,!appengine,!safe,!disableunsafe,go1.4 +// +build !js,!appengine,!safe,!disableunsafe package spew @@ -36,49 +34,80 @@ const ( ptrSize = unsafe.Sizeof((*byte)(nil)) ) -type flag uintptr - var ( - // flagRO indicates whether the value field of a reflect.Value - // is read-only. - flagRO flag - - // flagAddr indicates whether the address of the reflect.Value's - // value may be taken. - flagAddr flag + // offsetPtr, offsetScalar, and offsetFlag are the offsets for the + // internal reflect.Value fields. These values are valid before golang + // commit ecccf07e7f9d which changed the format. The are also valid + // after commit 82f48826c6c7 which changed the format again to mirror + // the original format. Code in the init function updates these offsets + // as necessary. + offsetPtr = uintptr(ptrSize) + offsetScalar = uintptr(0) + offsetFlag = uintptr(ptrSize * 2) + + // flagKindWidth and flagKindShift indicate various bits that the + // reflect package uses internally to track kind information. + // + // flagRO indicates whether or not the value field of a reflect.Value is + // read-only. + // + // flagIndir indicates whether the value field of a reflect.Value is + // the actual data or a pointer to the data. + // + // These values are valid before golang commit 90a7c3c86944 which + // changed their positions. Code in the init function updates these + // flags as necessary. + flagKindWidth = uintptr(5) + flagKindShift = uintptr(flagKindWidth - 1) + flagRO = uintptr(1 << 0) + flagIndir = uintptr(1 << 1) ) -// flagKindMask holds the bits that make up the kind -// part of the flags field. In all the supported versions, -// it is in the lower 5 bits. -const flagKindMask = flag(0x1f) - -// Different versions of Go have used different -// bit layouts for the flags type. This table -// records the known combinations. -var okFlags = []struct { - ro, addr flag -}{{ - // From Go 1.4 to 1.5 - ro: 1 << 5, - addr: 1 << 7, -}, { - // Up to Go tip. - ro: 1<<5 | 1<<6, - addr: 1 << 8, -}} - -var flagValOffset = func() uintptr { - field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") - if !ok { - panic("reflect.Value has no flag field") +func init() { + // Older versions of reflect.Value stored small integers directly in the + // ptr field (which is named val in the older versions). Versions + // between commits ecccf07e7f9d and 82f48826c6c7 added a new field named + // scalar for this purpose which unfortunately came before the flag + // field, so the offset of the flag field is different for those + // versions. + // + // This code constructs a new reflect.Value from a known small integer + // and checks if the size of the reflect.Value struct indicates it has + // the scalar field. When it does, the offsets are updated accordingly. + vv := reflect.ValueOf(0xf00) + if unsafe.Sizeof(vv) == (ptrSize * 4) { + offsetScalar = ptrSize * 2 + offsetFlag = ptrSize * 3 } - return field.Offset -}() -// flagField returns a pointer to the flag field of a reflect.Value. -func flagField(v *reflect.Value) *flag { - return (*flag)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + flagValOffset)) + // Commit 90a7c3c86944 changed the flag positions such that the low + // order bits are the kind. This code extracts the kind from the flags + // field and ensures it's the correct type. When it's not, the flag + // order has been changed to the newer format, so the flags are updated + // accordingly. + upf := unsafe.Pointer(uintptr(unsafe.Pointer(&vv)) + offsetFlag) + upfv := *(*uintptr)(upf) + flagKindMask := uintptr((1<>flagKindShift != uintptr(reflect.Int) { + flagKindShift = 0 + flagRO = 1 << 5 + flagIndir = 1 << 6 + + // Commit adf9b30e5594 modified the flags to separate the + // flagRO flag into two bits which specifies whether or not the + // field is embedded. This causes flagIndir to move over a bit + // and means that flagRO is the combination of either of the + // original flagRO bit and the new bit. + // + // This code detects the change by extracting what used to be + // the indirect bit to ensure it's set. When it's not, the flag + // order has been changed to the newer format, so the flags are + // updated accordingly. + if upfv&flagIndir == 0 { + flagRO = 3 << 5 + flagIndir = 1 << 7 + } + } } // unsafeReflectValue converts the passed reflect.Value into a one that bypasses @@ -90,56 +119,34 @@ func flagField(v *reflect.Value) *flag { // This allows us to check for implementations of the Stringer and error // interfaces to be used for pretty printing ordinarily unaddressable and // inaccessible values such as unexported struct fields. -func unsafeReflectValue(v reflect.Value) reflect.Value { - if !v.IsValid() || (v.CanInterface() && v.CanAddr()) { - return v - } - flagFieldPtr := flagField(&v) - *flagFieldPtr &^= flagRO - *flagFieldPtr |= flagAddr - return v -} - -// Sanity checks against future reflect package changes -// to the type or semantics of the Value.flag field. -func init() { - field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") - if !ok { - panic("reflect.Value has no flag field") - } - if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() { - panic("reflect.Value flag field has changed kind") - } - type t0 int - var t struct { - A t0 - // t0 will have flagEmbedRO set. - t0 - // a will have flagStickyRO set - a t0 +func unsafeReflectValue(v reflect.Value) (rv reflect.Value) { + indirects := 1 + vt := v.Type() + upv := unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetPtr) + rvf := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetFlag)) + if rvf&flagIndir != 0 { + vt = reflect.PtrTo(v.Type()) + indirects++ + } else if offsetScalar != 0 { + // The value is in the scalar field when it's not one of the + // reference types. + switch vt.Kind() { + case reflect.Uintptr: + case reflect.Chan: + case reflect.Func: + case reflect.Map: + case reflect.Ptr: + case reflect.UnsafePointer: + default: + upv = unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + + offsetScalar) + } } - vA := reflect.ValueOf(t).FieldByName("A") - va := reflect.ValueOf(t).FieldByName("a") - vt0 := reflect.ValueOf(t).FieldByName("t0") - - // Infer flagRO from the difference between the flags - // for the (otherwise identical) fields in t. - flagPublic := *flagField(&vA) - flagWithRO := *flagField(&va) | *flagField(&vt0) - flagRO = flagPublic ^ flagWithRO - // Infer flagAddr from the difference between a value - // taken from a pointer and not. - vPtrA := reflect.ValueOf(&t).Elem().FieldByName("A") - flagNoPtr := *flagField(&vA) - flagPtr := *flagField(&vPtrA) - flagAddr = flagNoPtr ^ flagPtr - - // Check that the inferred flags tally with one of the known versions. - for _, f := range okFlags { - if flagRO == f.ro && flagAddr == f.addr { - return - } + pv := reflect.NewAt(vt, upv) + rv = pv + for i := 0; i < indirects; i++ { + rv = rv.Elem() } - panic("reflect.Value read-only flag has changed semantics") + return rv } diff --git a/gofiles/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go b/gofiles/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go index 205c28d..1fe3cf3 100644 --- a/gofiles/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go +++ b/gofiles/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go @@ -16,7 +16,7 @@ // when the code is running on Google App Engine, compiled by GopherJS, or // "-tags safe" is added to the go build command line. The "disableunsafe" // tag is deprecated and thus should not be used. -// +build js appengine safe disableunsafe !go1.4 +// +build js appengine safe disableunsafe package spew diff --git a/gofiles/vendor/github.com/davecgh/go-spew/spew/common.go b/gofiles/vendor/github.com/davecgh/go-spew/spew/common.go index 1be8ce9..7c519ff 100644 --- a/gofiles/vendor/github.com/davecgh/go-spew/spew/common.go +++ b/gofiles/vendor/github.com/davecgh/go-spew/spew/common.go @@ -180,7 +180,7 @@ func printComplex(w io.Writer, c complex128, floatPrecision int) { w.Write(closeParenBytes) } -// printHexPtr outputs a uintptr formatted as hexadecimal with a leading '0x' +// printHexPtr outputs a uintptr formatted as hexidecimal with a leading '0x' // prefix to Writer w. func printHexPtr(w io.Writer, p uintptr) { // Null pointer. diff --git a/gofiles/vendor/github.com/davecgh/go-spew/spew/dump.go b/gofiles/vendor/github.com/davecgh/go-spew/spew/dump.go index f78d89f..df1d582 100644 --- a/gofiles/vendor/github.com/davecgh/go-spew/spew/dump.go +++ b/gofiles/vendor/github.com/davecgh/go-spew/spew/dump.go @@ -35,16 +35,16 @@ var ( // cCharRE is a regular expression that matches a cgo char. // It is used to detect character arrays to hexdump them. - cCharRE = regexp.MustCompile(`^.*\._Ctype_char$`) + cCharRE = regexp.MustCompile("^.*\\._Ctype_char$") // cUnsignedCharRE is a regular expression that matches a cgo unsigned // char. It is used to detect unsigned character arrays to hexdump // them. - cUnsignedCharRE = regexp.MustCompile(`^.*\._Ctype_unsignedchar$`) + cUnsignedCharRE = regexp.MustCompile("^.*\\._Ctype_unsignedchar$") // cUint8tCharRE is a regular expression that matches a cgo uint8_t. // It is used to detect uint8_t arrays to hexdump them. - cUint8tCharRE = regexp.MustCompile(`^.*\._Ctype_uint8_t$`) + cUint8tCharRE = regexp.MustCompile("^.*\\._Ctype_uint8_t$") ) // dumpState contains information about the state of a dump operation. @@ -143,10 +143,10 @@ func (d *dumpState) dumpPtr(v reflect.Value) { // Display dereferenced value. d.w.Write(openParenBytes) switch { - case nilFound: + case nilFound == true: d.w.Write(nilAngleBytes) - case cycleFound: + case cycleFound == true: d.w.Write(circularBytes) default: diff --git a/gofiles/vendor/github.com/davecgh/go-spew/spew/format.go b/gofiles/vendor/github.com/davecgh/go-spew/spew/format.go index b04edb7..c49875b 100644 --- a/gofiles/vendor/github.com/davecgh/go-spew/spew/format.go +++ b/gofiles/vendor/github.com/davecgh/go-spew/spew/format.go @@ -182,10 +182,10 @@ func (f *formatState) formatPtr(v reflect.Value) { // Display dereferenced value. switch { - case nilFound: + case nilFound == true: f.fs.Write(nilAngleBytes) - case cycleFound: + case cycleFound == true: f.fs.Write(circularShortBytes) default: diff --git a/gofiles/vendor/github.com/nmiyake/pkg/LICENSE b/gofiles/vendor/github.com/nmiyake/pkg/dirs/LICENSE similarity index 100% rename from gofiles/vendor/github.com/nmiyake/pkg/LICENSE rename to gofiles/vendor/github.com/nmiyake/pkg/dirs/LICENSE diff --git a/gofiles/vendor/github.com/nmiyake/pkg/dirs/go.mod b/gofiles/vendor/github.com/nmiyake/pkg/dirs/go.mod new file mode 100644 index 0000000..7ad46d3 --- /dev/null +++ b/gofiles/vendor/github.com/nmiyake/pkg/dirs/go.mod @@ -0,0 +1,3 @@ +module github.com/nmiyake/pkg/dirs + +go 1.13 diff --git a/gofiles/vendor/github.com/nmiyake/pkg/dirs/godelw b/gofiles/vendor/github.com/nmiyake/pkg/dirs/godelw new file mode 100644 index 0000000..72cad1d --- /dev/null +++ b/gofiles/vendor/github.com/nmiyake/pkg/dirs/godelw @@ -0,0 +1,230 @@ +#!/bin/bash + +set -euo pipefail + +# Version and checksums for godel. Values are populated by the godel "dist" task. +VERSION=2.22.0 +DARWIN_CHECKSUM=b2bedf340419d79187643bf9a9dbdd0c4c46bccdcb597717b71dd165ac7129a7 +LINUX_CHECKSUM=25d36a20d33cba39d05f8a3c2c3768b3a02a3297f129308f3e2bc8c0951ba388 + +# Downloads file at URL to destination path using wget or curl. Prints an error and exits if wget or curl is not present. +function download { + local url=$1 + local dst=$2 + + # determine whether wget, curl or both are present + set +e + command -v wget >/dev/null 2>&1 + local wget_exists=$? + command -v curl >/dev/null 2>&1 + local curl_exists=$? + set -e + + # if one of wget or curl is not present, exit with error + if [ "$wget_exists" -ne 0 -a "$curl_exists" -ne 0 ]; then + echo "wget or curl must be present to download distribution. Install one of these programs and try again or install the distribution manually." + exit 1 + fi + + if [ "$wget_exists" -eq 0 ]; then + # attempt download using wget + echo "Downloading $url to $dst..." + local progress_opt="" + if wget --help | grep -q '\--show-progress'; then + progress_opt="-q --show-progress" + fi + set +e + wget -O "$dst" $progress_opt "$url" + rv=$? + set -e + if [ "$rv" -eq 0 ]; then + # success + return + fi + + echo "Download failed using command: wget -O $dst $progress_opt $url" + + # curl does not exist, so nothing more to try: exit + if [ "$curl_exists" -ne 0 ]; then + echo "Download failed using wget and curl was not found. Verify that the distribution URL is correct and try again or install the distribution manually." + exit 1 + fi + # curl exists, notify that download will be attempted using curl + echo "Attempting download using curl..." + fi + + # attempt download using curl + echo "Downloading $url to $dst..." + set +e + curl -f -L -o "$dst" "$url" + rv=$? + set -e + if [ "$rv" -ne 0 ]; then + echo "Download failed using command: curl -f -L -o $dst $url" + if [ "$wget_exists" -eq 0 ]; then + echo "Download failed using wget and curl. Verify that the distribution URL is correct and try again or install the distribution manually." + else + echo "Download failed using curl and wget was not found. Verify that the distribution URL is correct and try again or install the distribution manually." + fi + exit 1 + fi +} + +# verifies that the provided checksum matches the computed SHA-256 checksum of the specified file. If not, echoes an +# error and exits. +function verify_checksum { + local file=$1 + local expected_checksum=$2 + local computed_checksum=$(compute_sha256 $file) + if [ "$expected_checksum" != "$computed_checksum" ]; then + echo "SHA-256 checksum for $file did not match expected value." + echo "Expected: $expected_checksum" + echo "Actual: $computed_checksum" + exit 1 + fi +} + +# computes the SHA-256 hash of the provided file. Uses openssl, shasum or sha1sum program. +function compute_sha256 { + local file=$1 + if command -v openssl >/dev/null 2>&1; then + # print SHA-256 hash using openssl + openssl dgst -sha256 "$file" | sed -E 's/SHA256\(.*\)= //' + elif command -v shasum >/dev/null 2>&1; then + # Darwin systems ship with "shasum" utility + shasum -a 256 "$file" | sed -E 's/[[:space:]]+.+//' + elif command -v sha256sum >/dev/null 2>&1; then + # Most Linux systems ship with sha256sum utility + sha256sum "$file" | sed -E 's/[[:space:]]+.+//' + else + echo "Could not find program to calculate SHA-256 checksum for file" + exit 1 + fi +} + +# Verifies that the tgz file at the provided path contains the paths/files that would be expected in a valid gödel +# distribution with the provided version. +function verify_dist_tgz_valid { + local tgz_path=$1 + local version=$2 + + local expected_paths=("godel-$version/" "godel-$version/bin/darwin-amd64/godel" "godel-$version/bin/linux-amd64/godel" "godel-$version/wrapper/godelw" "godel-$version/wrapper/godel/config/") + local files=($(tar -tf "$tgz_path")) + + # this is a double-for loop, but fine since $expected_paths is small and bash doesn't have good primitives for set/map/list manipulation + for curr_line in "${files[@]}"; do + # if all expected paths have been found, terminate + if [[ ${#expected_paths[*]} == 0 ]]; then + break + fi + + # check for expected path and splice out if match is found + idx=0 + for curr_expected in "${expected_paths[@]}"; do + if [ "$curr_expected" = "$curr_line" ]; then + expected_paths=(${expected_paths[@]:0:idx} ${expected_paths[@]:$(($idx + 1))}) + break + fi + idx=$idx+1 + done + done + + # if any expected paths still remain, raise error and exit + if [[ ${#expected_paths[*]} > 0 ]]; then + echo "Required paths were not present in $tgz_path: ${expected_paths[@]}" + exit 1 + fi +} + +# Verifies that the gödel binary in the distribution reports the expected version when called with the "version" +# argument. Assumes that a valid gödel distribution directory for the given version exists in the provided directory. +function verify_godel_version { + local base_dir=$1 + local version=$2 + local os=$3 + + local expected_output="godel version $version" + local version_output=$($base_dir/godel-$version/bin/$os-amd64/godel version) + + if [ "$expected_output" != "$version_output" ]; then + echo "Version reported by godel executable did not match expected version: expected \"$expected_output\", was \"$version_output\"" + exit 1 + fi +} + +# directory of godelw script +SCRIPT_HOME=$(cd "$(dirname "$0")" && pwd) + +# use $GODEL_HOME or default value +GODEL_BASE_DIR=${GODEL_HOME:-$HOME/.godel} + +# determine OS +OS="" +EXPECTED_CHECKSUM="" +case "$(uname)" in + Darwin*) + OS=darwin + EXPECTED_CHECKSUM=$DARWIN_CHECKSUM + ;; + Linux*) + OS=linux + EXPECTED_CHECKSUM=$LINUX_CHECKSUM + ;; + *) + echo "Unsupported operating system: $(uname)" + exit 1 + ;; +esac + +# path to godel binary +CMD=$GODEL_BASE_DIR/dists/godel-$VERSION/bin/$OS-amd64/godel + +# godel binary is not present -- download distribution +if [ ! -f "$CMD" ]; then + # get download URL + PROPERTIES_FILE=$SCRIPT_HOME/godel/config/godel.properties + if [ ! -f "$PROPERTIES_FILE" ]; then + echo "Properties file must exist at $PROPERTIES_FILE" + exit 1 + fi + DOWNLOAD_URL=$(cat "$PROPERTIES_FILE" | sed -E -n "s/^distributionURL=//p") + if [ -z "$DOWNLOAD_URL" ]; then + echo "Value for property \"distributionURL\" was empty in $PROPERTIES_FILE" + exit 1 + fi + DOWNLOAD_CHECKSUM=$(cat "$PROPERTIES_FILE" | sed -E -n "s/^distributionSHA256=//p") + + # create downloads directory if it does not already exist + mkdir -p "$GODEL_BASE_DIR/downloads" + + # download tgz and verify its contents + DOWNLOAD_DST=$GODEL_BASE_DIR/downloads/godel-$VERSION.tgz + download "$DOWNLOAD_URL" "$DOWNLOAD_DST" + if [ -n "$DOWNLOAD_CHECKSUM" ]; then + verify_checksum "$DOWNLOAD_DST" "$DOWNLOAD_CHECKSUM" + fi + verify_dist_tgz_valid "$DOWNLOAD_DST" "$VERSION" + + # create temporary directory for unarchiving, unarchive downloaded file and verify directory + TMP_DIST_DIR=$(mktemp -d "$GODEL_BASE_DIR/tmp_XXXXXX" 2>/dev/null || mktemp -d -t "$GODEL_BASE_DIR/tmp_XXXXXX") + trap 'rm -rf "$TMP_DIST_DIR"' EXIT + tar zxvf "$DOWNLOAD_DST" -C "$TMP_DIST_DIR" >/dev/null 2>&1 + verify_godel_version "$TMP_DIST_DIR" "$VERSION" "$OS" + + # if destination directory for distribution already exists, remove it + if [ -d "$GODEL_BASE_DIR/dists/godel-$VERSION" ]; then + rm -rf "$GODEL_BASE_DIR/dists/godel-$VERSION" + fi + + # ensure that parent directory of destination exists + mkdir -p "$GODEL_BASE_DIR/dists" + + # move expanded distribution directory to destination location. The location of the unarchived directory is known to + # be in the same directory tree as the destination, so "mv" should always work. + mv "$TMP_DIST_DIR/godel-$VERSION" "$GODEL_BASE_DIR/dists/godel-$VERSION" +fi + +verify_checksum "$CMD" "$EXPECTED_CHECKSUM" + +# execute command +$CMD --wrapper "$SCRIPT_HOME/$(basename "$0")" "$@" diff --git a/gofiles/vendor/github.com/nmiyake/pkg/godel/config/license-plugin.yml b/gofiles/vendor/github.com/nmiyake/pkg/godel/config/license-plugin.yml deleted file mode 100644 index ad64a2a..0000000 --- a/gofiles/vendor/github.com/nmiyake/pkg/godel/config/license-plugin.yml +++ /dev/null @@ -1,22 +0,0 @@ -header: | - // MIT License - // - // Copyright (c) {{YEAR}} Nick Miyake - // - // Permission is hereby granted, free of charge, to any person obtaining a copy - // of this software and associated documentation files (the "Software"), to deal - // in the Software without restriction, including without limitation the rights - // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - // copies of the Software, and to permit persons to whom the Software is - // furnished to do so, subject to the following conditions: - // - // The above copyright notice and this permission notice shall be included in all - // copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - // SOFTWARE. diff --git a/gofiles/vendor/gopkg.in/yaml.v2/decode.go b/gofiles/vendor/gopkg.in/yaml.v2/decode.go index 129bc2a..e4e56e2 100644 --- a/gofiles/vendor/gopkg.in/yaml.v2/decode.go +++ b/gofiles/vendor/gopkg.in/yaml.v2/decode.go @@ -229,10 +229,6 @@ type decoder struct { mapType reflect.Type terrors []string strict bool - - decodeCount int - aliasCount int - aliasDepth int } var ( @@ -318,43 +314,7 @@ func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unm return out, false, false } -const ( - // 400,000 decode operations is ~500kb of dense object declarations, or - // ~5kb of dense object declarations with 10000% alias expansion - alias_ratio_range_low = 400000 - - // 4,000,000 decode operations is ~5MB of dense object declarations, or - // ~4.5MB of dense object declarations with 10% alias expansion - alias_ratio_range_high = 4000000 - - // alias_ratio_range is the range over which we scale allowed alias ratios - alias_ratio_range = float64(alias_ratio_range_high - alias_ratio_range_low) -) - -func allowedAliasRatio(decodeCount int) float64 { - switch { - case decodeCount <= alias_ratio_range_low: - // allow 99% to come from alias expansion for small-to-medium documents - return 0.99 - case decodeCount >= alias_ratio_range_high: - // allow 10% to come from alias expansion for very large documents - return 0.10 - default: - // scale smoothly from 99% down to 10% over the range. - // this maps to 396,000 - 400,000 allowed alias-driven decodes over the range. - // 400,000 decode operations is ~100MB of allocations in worst-case scenarios (single-item maps). - return 0.99 - 0.89*(float64(decodeCount-alias_ratio_range_low)/alias_ratio_range) - } -} - func (d *decoder) unmarshal(n *node, out reflect.Value) (good bool) { - d.decodeCount++ - if d.aliasDepth > 0 { - d.aliasCount++ - } - if d.aliasCount > 100 && d.decodeCount > 1000 && float64(d.aliasCount)/float64(d.decodeCount) > allowedAliasRatio(d.decodeCount) { - failf("document contains excessive aliasing") - } switch n.kind { case documentNode: return d.document(n, out) @@ -393,9 +353,7 @@ func (d *decoder) alias(n *node, out reflect.Value) (good bool) { failf("anchor '%s' value contains itself", n.value) } d.aliases[n] = true - d.aliasDepth++ good = d.unmarshal(n.alias, out) - d.aliasDepth-- delete(d.aliases, n) return good } @@ -788,7 +746,8 @@ func (d *decoder) merge(n *node, out reflect.Value) { case mappingNode: d.unmarshal(n, out) case aliasNode: - if n.alias != nil && n.alias.kind != mappingNode { + an, ok := d.doc.anchors[n.value] + if ok && an.kind != mappingNode { failWantMap() } d.unmarshal(n, out) @@ -797,7 +756,8 @@ func (d *decoder) merge(n *node, out reflect.Value) { for i := len(n.children) - 1; i >= 0; i-- { ni := n.children[i] if ni.kind == aliasNode { - if ni.alias != nil && ni.alias.kind != mappingNode { + an, ok := d.doc.anchors[ni.value] + if ok && an.kind != mappingNode { failWantMap() } } else if ni.kind != mappingNode { diff --git a/gofiles/vendor/gopkg.in/yaml.v2/resolve.go b/gofiles/vendor/gopkg.in/yaml.v2/resolve.go index 4120e0c..6c151db 100644 --- a/gofiles/vendor/gopkg.in/yaml.v2/resolve.go +++ b/gofiles/vendor/gopkg.in/yaml.v2/resolve.go @@ -81,7 +81,7 @@ func resolvableTag(tag string) bool { return false } -var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`) +var yamlStyleFloat = regexp.MustCompile(`^[-+]?[0-9]*\.?[0-9]+([eE][-+][0-9]+)?$`) func resolve(tag string, in string) (rtag string, out interface{}) { if !resolvableTag(tag) { diff --git a/gofiles/vendor/gopkg.in/yaml.v2/scannerc.go b/gofiles/vendor/gopkg.in/yaml.v2/scannerc.go index 570b8ec..077fd1d 100644 --- a/gofiles/vendor/gopkg.in/yaml.v2/scannerc.go +++ b/gofiles/vendor/gopkg.in/yaml.v2/scannerc.go @@ -906,9 +906,6 @@ func yaml_parser_remove_simple_key(parser *yaml_parser_t) bool { return true } -// max_flow_level limits the flow_level -const max_flow_level = 10000 - // Increase the flow level and resize the simple key list if needed. func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool { // Reset the simple key on the next level. @@ -916,11 +913,6 @@ func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool { // Increase the flow level. parser.flow_level++ - if parser.flow_level > max_flow_level { - return yaml_parser_set_scanner_error(parser, - "while increasing flow level", parser.simple_keys[len(parser.simple_keys)-1].mark, - fmt.Sprintf("exceeded max depth of %d", max_flow_level)) - } return true } @@ -933,9 +925,6 @@ func yaml_parser_decrease_flow_level(parser *yaml_parser_t) bool { return true } -// max_indents limits the indents stack size -const max_indents = 10000 - // Push the current indentation level to the stack and set the new level // the current column is greater than the indentation level. In this case, // append or insert the specified token into the token queue. @@ -950,11 +939,6 @@ func yaml_parser_roll_indent(parser *yaml_parser_t, column, number int, typ yaml // indentation level. parser.indents = append(parser.indents, parser.indent) parser.indent = column - if len(parser.indents) > max_indents { - return yaml_parser_set_scanner_error(parser, - "while increasing indent level", parser.simple_keys[len(parser.simple_keys)-1].mark, - fmt.Sprintf("exceeded max depth of %d", max_indents)) - } // Create a token and insert it into the queue. token := yaml_token_t{ diff --git a/gofiles/vendor/modules.txt b/gofiles/vendor/modules.txt new file mode 100644 index 0000000..a42451d --- /dev/null +++ b/gofiles/vendor/modules.txt @@ -0,0 +1,11 @@ +# github.com/davecgh/go-spew v1.1.0 +github.com/davecgh/go-spew/spew +# github.com/nmiyake/pkg/dirs v1.0.0 +github.com/nmiyake/pkg/dirs +# github.com/pmezard/go-difflib v1.0.0 +github.com/pmezard/go-difflib/difflib +# github.com/stretchr/testify v1.4.0 +github.com/stretchr/testify/assert +github.com/stretchr/testify/require +# gopkg.in/yaml.v2 v2.2.2 +gopkg.in/yaml.v2