diff --git a/Makefile b/Makefile index 06b6400be4523665c4c994f11443c4eaf7299a65..ed6c3e2b598c6fb9d57349fd519b507a01da92b4 100644 --- a/Makefile +++ b/Makefile @@ -67,12 +67,6 @@ install_vendor: go get github.com/Masterminds/glide glide install -# hell runs utility tool hell to selectively update glide dependencies -.PHONY: hell -hell: - go build -o ${REPO}/target/hell ./util/hell/cmd/hell/main.go - ./target/hell $(filter-out $@,$(MAKECMDGOALS)) - # Dumps Solidity interface contracts for SNatives .PHONY: snatives snatives: diff --git a/glide.lock b/glide.lock index a53f4588b335dad4e7f2f03a87a25404f4f4456b..06751273920eb8330b61c0977473165a13f40648 100644 --- a/glide.lock +++ b/glide.lock @@ -82,8 +82,6 @@ imports: version: c265cfa48dda6474e208715ca93e987829f572f8 - name: github.com/manucorporat/sse version: ee05b128a739a0fb76c7ebd3ae4810c1de808d6d -- name: github.com/Masterminds/glide - version: 869001d1571ce5f03fd0078bff188b9d3f272807 - name: github.com/mattn/go-colorable version: ded68f7a9561c023e790de24279db7ebf473ea80 - name: github.com/mattn/go-isatty diff --git a/glide.yaml b/glide.yaml index cb5cf944ec45eed78f58c29376ce050e8b4f65ef..85811a5eee3739a4fa9382e5c8e3ae5958131471 100644 --- a/glide.yaml +++ b/glide.yaml @@ -28,8 +28,6 @@ import: - package: github.com/Sirupsen/logrus version: ^0.11.0 - package: github.com/streadway/simpleuuid -- package: github.com/Masterminds/glide - version: ~0.12.3 - package: github.com/Graylog2/go-gelf - package: github.com/tendermint/tendermint version: ~0.9.2 diff --git a/util/hell/README.md b/util/hell/README.md deleted file mode 100644 index 715cb5522ca5a98143a45edf7e9ec49517b6778d..0000000000000000000000000000000000000000 --- a/util/hell/README.md +++ /dev/null @@ -1,11 +0,0 @@ -> Hell is other people's packages - -While we wait for working package management in go we need a way to make -maintaining the glide.lock by hand less painful. - -To interactively add a package run from the root: - -```bash -go run ./util/hell/cmd/hell/main.go get --interactive github.com/tendermint/tendermint -``` - diff --git a/util/hell/cmd/hell/main.go b/util/hell/cmd/hell/main.go deleted file mode 100644 index 5caa04ac071d3d4fb34a080da15a18dfbcbca2cb..0000000000000000000000000000000000000000 --- a/util/hell/cmd/hell/main.go +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2017 Monax Industries Limited -// -// 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 ( - "fmt" - "os" - "path/filepath" - - "github.com/hyperledger/burrow/util/hell" - - "github.com/Masterminds/glide/action" - "github.com/Masterminds/glide/cache" - "github.com/Masterminds/glide/cfg" - "github.com/Masterminds/glide/msg" - "github.com/Masterminds/glide/path" - "github.com/Masterminds/glide/repo" - "github.com/Masterminds/glide/util" - "github.com/spf13/cobra" -) - -func main() { - hellCmd := &cobra.Command{ - Use: "hell", - Short: "Hell makes the most of it being warm", - Long: "", - Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, - } - - // Lock merge command - var baseGlideLockFile, depGlideLockFile string - lockMergeCmd := &cobra.Command{ - Use: "lock-merge", - Short: "Merge glide.lock files together", - Long: "This command merges two glide.lock files into a single one by copying all dependencies " + - "from a base glide.lock and an override glide.lock to an output glide.lock with dependencies " + - "from override taking precedence over those from base.", - Run: func(cmd *cobra.Command, args []string) { - baseLockFile, err := cfg.ReadLockFile(baseGlideLockFile) - if err != nil { - fmt.Printf("Could not read file: %s\n", err) - os.Exit(1) - } - overrideLockFile, err := cfg.ReadLockFile(depGlideLockFile) - if err != nil { - fmt.Printf("Could not read file: %s\n", err) - os.Exit(1) - } - mergedLockFile, err := hell.MergeGlideLockFiles(baseLockFile, overrideLockFile) - if err != nil { - fmt.Printf("Could not merge lock files: %s\n", err) - os.Exit(1) - } - mergedBytes, err := mergedLockFile.Marshal() - if err != nil { - fmt.Printf("Could not marshal lock file: %s\n", err) - os.Exit(1) - } - os.Stdout.Write(mergedBytes) - }, - } - lockMergeCmd.PersistentFlags().StringVarP(&baseGlideLockFile, "base", "b", "", "base lock file") - lockMergeCmd.PersistentFlags().StringVarP(&depGlideLockFile, "override", "o", "", "override lock file") - - // Lock update - interactive := false - getTransitiveCmd := &cobra.Command{ - Use: "get", - Short: "gets a remote dependency to this project along with its transtive dependencies.", - Long: "Gets a remote dependency and its transitive dependencies by adding the remote " + - "depednency to this project's glide.yaml and merging the remote dependency's " + - "glide.lock into this project's glide.lock", - Run: func(cmd *cobra.Command, args []string) { - if len(args) != 1 { - msg.Die("%s requires a single argument of the remote dependency\n", cmd.Name()) - } - rootPackage, _ := util.NormalizeName(args[0]) - // Add dependency to glide - installer := repo.NewInstaller() - action.Get(args, installer, false, true, false, !interactive, false) - // Now hunt down the repo cache - dep := action.EnsureConfig().Imports.Get(rootPackage) - - key, err := cache.Key(dep.Remote()) - if err != nil { - msg.Die("%s requires a single argument of the remote dependency\n", cmd.Name()) - } - cacheDir := filepath.Join(cache.Location(), "src", key) - repos, err := dep.GetRepo(cacheDir) - if err != nil { - msg.Die("Could not get repo: %s", err) - } - version, err := repos.Version() - if err != nil { - msg.Die("Could not get version: %s", err) - } - dep.Pin = version - lockPath := filepath.Join(".", path.LockFile) - baseLockFile, err := cfg.ReadLockFile(lockPath) - if err != nil { - msg.Die("Could not read base lock file: %s", err) - } - overrideLockFile := &cfg.Lockfile{} - if path.HasLock(cacheDir) { - msg.Info("Found dependency lock file so merging into project lock file") - overrideLockFile, err = cfg.ReadLockFile(filepath.Join(cacheDir, path.LockFile)) - if err != nil { - msg.Die("Could not read dependency lock file: %s", err) - } - } - // Add the package to glide lock too! - overrideLockFile.Imports = append(overrideLockFile.Imports, cfg.LockFromDependency(dep)) - - mergedLockFile, err := hell.MergeGlideLockFiles(baseLockFile, overrideLockFile) - if err != nil { - msg.Die("Could not merge lock files: %s\n", err) - } - err = mergedLockFile.WriteFile(lockPath) - if err != nil { - msg.Die("Could not write merged lock file: %s", err) - } - - action.Install(installer, false) - }, - } - - getTransitiveCmd.PersistentFlags().BoolVarP(&interactive, "interactive", "i", false, - "set dependency verion interactively") - - hellCmd.AddCommand(lockMergeCmd) - hellCmd.AddCommand(getTransitiveCmd) - lockMergeCmd.Execute() -} diff --git a/util/hell/merge.go b/util/hell/merge.go deleted file mode 100644 index 130a80065b9ba82b70a0cbe24ebac439dd79b974..0000000000000000000000000000000000000000 --- a/util/hell/merge.go +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2017 Monax Industries Limited -// -// 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 hell - -import ( - "crypto/sha256" - "fmt" - "sort" - - "github.com/Masterminds/glide/cfg" -) - -// Merges two glide lock files together, letting dependencies from 'base' be overwritten -// by those from 'override'. Returns the resultant glide lock file bytes -func MergeGlideLockFiles(baseLockFile, overrideLockFile *cfg.Lockfile) (*cfg.Lockfile, error) { - imports := make(map[string]*cfg.Lock, len(baseLockFile.Imports)) - devImports := make(map[string]*cfg.Lock, len(baseLockFile.DevImports)) - // Copy the base dependencies into a map - for _, lock := range baseLockFile.Imports { - imports[lock.Name] = lock - } - for _, lock := range baseLockFile.DevImports { - devImports[lock.Name] = lock - } - // Override base dependencies and add any extra ones - for _, lock := range overrideLockFile.Imports { - imports[lock.Name] = mergeLocks(imports[lock.Name], lock) - } - for _, lock := range overrideLockFile.DevImports { - devImports[lock.Name] = mergeLocks(imports[lock.Name], lock) - } - - deps := make([]*cfg.Dependency, 0, len(imports)) - devDeps := make([]*cfg.Dependency, 0, len(devImports)) - - // Flatten to Dependencies - for _, lock := range imports { - deps = append(deps, pinnedDependencyFromLock(lock)) - } - - for _, lock := range devImports { - devDeps = append(devDeps, pinnedDependencyFromLock(lock)) - } - - hasher := sha256.New() - hasher.Write(([]byte)(baseLockFile.Hash)) - hasher.Write(([]byte)(overrideLockFile.Hash)) - - return cfg.NewLockfile(deps, devDeps, fmt.Sprintf("%x", hasher.Sum(nil))) -} - -func mergeLocks(baseLock, overrideLock *cfg.Lock) *cfg.Lock { - lock := overrideLock.Clone() - if baseLock == nil { - return lock - } - - // Merge and dedupe subpackages - subpackages := make([]string, 0, len(lock.Subpackages)+len(baseLock.Subpackages)) - for _, sp := range lock.Subpackages { - subpackages = append(subpackages, sp) - } - for _, sp := range baseLock.Subpackages { - subpackages = append(subpackages, sp) - } - - sort.Stable(sort.StringSlice(subpackages)) - - dedupeSubpackages := make([]string, 0, len(subpackages)) - - lastSp := "" - elided := 0 - for _, sp := range subpackages { - if lastSp == sp { - elided++ - } else { - dedupeSubpackages = append(dedupeSubpackages, sp) - lastSp = sp - } - } - lock.Subpackages = dedupeSubpackages[:len(dedupeSubpackages)-elided] - return lock -} - -func pinnedDependencyFromLock(lock *cfg.Lock) *cfg.Dependency { - dep := cfg.DependencyFromLock(lock) - dep.Pin = lock.Version - return dep -} diff --git a/util/hell/merge_test.go b/util/hell/merge_test.go deleted file mode 100644 index 5fffedb9c93d01cc24782a657a09282d408933a9..0000000000000000000000000000000000000000 --- a/util/hell/merge_test.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2017 Monax Industries Limited -// -// 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 hell - -import ( - "strings" - "testing" - - "github.com/Masterminds/glide/cfg" - "github.com/stretchr/testify/assert" -) - -const baseLockYml = `imports: -- name: github.com/gogo/protobuf - version: 82d16f734d6d871204a3feb1a73cb220cc92574c -- name: github.com/tendermint/tendermint - version: aaea0c5d2e3ecfbf29f2608f9d43649ec7f07f50 - subpackages: - - node - - proxy - - types - - version - - consensus - - rpc/core/types - - blockchain - - mempool - - rpc/core - - state -` -const overrideLockYml = `imports: -- name: github.com/tendermint/tendermint - version: 764091dfbb035f1b28da4b067526e04c6a849966 - subpackages: - - benchmarks - - proxy - - types - - version -` -const expectedLockYml = `imports: -- name: github.com/gogo/protobuf - version: 82d16f734d6d871204a3feb1a73cb220cc92574c -- name: github.com/tendermint/tendermint - version: 764091dfbb035f1b28da4b067526e04c6a849966 - subpackages: - - benchmarks - - blockchain - - consensus - - mempool - - node - - proxy - - rpc/core - - rpc/core/types -testImports: [] -` - -func TestMergeGlideLockFiles(t *testing.T) { - baseLockFile, err := cfg.LockfileFromYaml(([]byte)(baseLockYml)) - assert.NoError(t, err, "Lockfile should parse") - - overrideLockFile, err := cfg.LockfileFromYaml(([]byte)(overrideLockYml)) - assert.NoError(t, err, "Lockfile should parse") - - mergedLockFile, err := MergeGlideLockFiles(baseLockFile, overrideLockFile) - assert.NoError(t, err, "Lockfiles should merge") - - mergedYmlBytes, err := mergedLockFile.Marshal() - assert.NoError(t, err, "Lockfile should marshal") - - ymlLines := strings.Split(string(mergedYmlBytes), "\n") - // Drop the updated and hash lines - actualYml := strings.Join(ymlLines[2:], "\n") - assert.Equal(t, expectedLockYml, actualYml) -}