Skip to content

Commit

Permalink
Merge pull request #2688 from tamird/snappy-cleanup
Browse files Browse the repository at this point in the history
sql/driver: break dependency on cgo-compiled packages
  • Loading branch information
tamird committed Sep 28, 2015
2 parents 047c7a1 + 2d2cacd commit 2450974
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 5 deletions.
1 change: 1 addition & 0 deletions GLOCKFILE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ github.com/docker/docker 2ed0739c7a47f5accfbae0c8cce2a7e6463dbdc6
github.com/elazarl/go-bindata-assetfs d5cac425555ca5cf00694df246e04f05e6a55150
github.com/gogo/protobuf 2093b57e5ca2ccbee4626814100bc1aada691b18
github.com/golang/lint 7b7f4364ff76043e6c3610281525fabc0d90f0e4
github.com/golang/snappy 723cc1e459b8eea2dea4583200fd60757d40097a
github.com/google/btree cc6329d4279e3f025a53a83c397d2339b5705c45
github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
github.com/jteeuwen/go-bindata bfe36d3254337b7cc18024805dfab2106613abdf
Expand Down
2 changes: 1 addition & 1 deletion cli/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestNoLinkTesting(t *testing.T) {
}

for _, imp := range pkg.Imports {
// https: //github.com/golang/tools/blob/master/refactor/importgraph/graph.go#L115
// https://github.com/golang/tools/blob/master/refactor/importgraph/graph.go#L115
if imp == "C" {
continue // "C" is fake
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/codec/snappy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"strconv"
"unsafe"

// Link against the snappy library. This is explicit because this Go
// library does not export any Go symbols.
// Link against the snappy library. This is explicit because we are
// not using any Go symbols from this library.
_ "github.com/cockroachdb/c-snappy"
"github.com/gogo/protobuf/proto"
)
Expand Down
2 changes: 1 addition & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"testing"
"time"

snappy "github.com/cockroachdb/c-snappy"
"github.com/cockroachdb/c-snappy"
"github.com/cockroachdb/cockroach/client"
"github.com/cockroachdb/cockroach/config"
"github.com/cockroachdb/cockroach/gossip"
Expand Down
3 changes: 2 additions & 1 deletion sql/driver/http_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
"net/http"
"time"

snappy "github.com/cockroachdb/c-snappy"
"github.com/golang/snappy"

"github.com/cockroachdb/cockroach/base"
"github.com/cockroachdb/cockroach/util"
"github.com/cockroachdb/cockroach/util/log"
Expand Down
70 changes: 70 additions & 0 deletions sql/driver/link_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2015 The Cockroach Authors.
//
// 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. See the AUTHORS file
// for names of contributors.
//
// Author: Tamir Duberstein ([email protected])

package driver

import (
"go/build"
"testing"

"github.com/cockroachdb/cockroach/util/leaktest"
)

func TestNoLinkForbidden(t *testing.T) {
defer leaktest.AfterTest(t)

context := build.Default
// We only care about the cgo disabled case. If it's enabled, cgo
// dependencies are obviously OK.
context.CgoEnabled = false

if context.GOPATH == "" {
t.Skip("GOPATH isn't set")
}

imports := make(map[string]struct{})

var addImports func(string)
addImports = func(root string) {
pkg, err := context.Import(root, context.GOPATH, 0)
if err != nil {
t.Fatal(err)
}

for _, imp := range pkg.Imports {
// https://github.com/golang/tools/blob/master/refactor/importgraph/graph.go#L115
if imp == "C" {
t.Errorf("sql/driver depends on cgo via %s", pkg.ImportPath)
continue // "C" is fake
}
if _, ok := imports[imp]; !ok {
imports[imp] = struct{}{}
addImports(imp)
}
}
}

addImports("github.com/cockroachdb/cockroach/sql/driver")

for _, forbidden := range []string{
"testing",
} {
if _, ok := imports[forbidden]; ok {
t.Errorf("sql/driver includes %s, which defines flags", forbidden)
}
}
}

0 comments on commit 2450974

Please sign in to comment.