Skip to content

Commit

Permalink
Update and re-run import script
Browse files Browse the repository at this point in the history
Also:
* Fix URL in README.rst
* Consolidate .patch files
  • Loading branch information
Jay Conrod committed Nov 13, 2017
1 parent 7c706d2 commit 9989aca
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Gazelle build file generator
============================

.. All external links are here
.. _go_repository: go/workspace.rst#go_repository
.. _go_repository: https://github.com/bazelbuild/rules_go/blob/master/go/workspace.rst#go-repository

.. role:: flag(code)
.. role:: cmd(code)
Expand Down
13 changes: 0 additions & 13 deletions fix-testdata.patch

This file was deleted.

26 changes: 26 additions & 0 deletions fix-resolve-genrule.patch → import-fixes.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
diff --git a/README.rst b/README.rst
index 0ed5ec8..f301c84 100644
--- a/README.rst
+++ b/README.rst
@@ -2,7 +2,7 @@ Gazelle build file generator
============================

.. All external links are here
-.. _go_repository: go/workspace.rst#go_repository
+.. _go_repository: https://github.com/bazelbuild/rules_go/blob/master/go/workspace.rst#go-repository

.. role:: flag(code)
.. role:: cmd(code)
diff --git a/resolve/BUILD.bazel b/resolve/BUILD.bazel
index d23c6ee..d619a52 100644
--- a/resolve/BUILD.bazel
Expand All @@ -24,3 +37,16 @@ index d96795e..aa39b03 100644
)

go_library(
diff --git a/rules/BUILD.bazel b/rules/BUILD.bazel
index 7cc150e..861e240 100644
--- a/rules/BUILD.bazel
+++ b/rules/BUILD.bazel
@@ -23,7 +23,7 @@ go_test(
name = "go_default_xtest",
size = "small",
srcs = ["generator_test.go"],
- data = ["//go/tools/gazelle:testdata"],
+ data = ["//:testdata"],
importpath = "github.com/bazelbuild/bazel-gazelle/rules_test",
deps = [
":go_default_library",
3 changes: 1 addition & 2 deletions import-from-rules-go.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ find . -name '*.go' \

# Fix build files.
gazelle -go_prefix github.com/bazelbuild/bazel-gazelle
patch -Nsp1 -i fix-resolve-genrule.patch
patch -Nsp1 -i fix-testdata.patch
patch -Nsp1 -i import-fixes.patch

# Run tests
go test github.com/bazelbuild/bazel-gazelle/...
Expand Down
15 changes: 15 additions & 0 deletions merger/merger_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/* Copyright 2016 The Bazel Authors. All rights reserved.
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 merger

import (
Expand Down
10 changes: 9 additions & 1 deletion resolve/resolve_external.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package resolve
import (
"fmt"
"path"
"regexp"
"strings"

"golang.org/x/tools/go/vcs"
Expand Down Expand Up @@ -50,7 +51,6 @@ func newExternalResolver(l Labeler, extraKnownImports []string) *externalResolve
{prefix: "google.golang.org", missing: 1},
{prefix: "cloud.google.com", missing: 1},
{prefix: "github.com", missing: 2},
{prefix: "gopkg.in", missing: 1},
} {
cache[e.prefix] = e
}
Expand Down Expand Up @@ -86,6 +86,8 @@ func (r *externalResolver) resolve(importpath string) (Label, error) {
return label, nil
}

var gopkginPattern = regexp.MustCompile("^(gopkg.in/(?:[^/]+/)?[^/]+\\.v\\d+)(?:/|$)")

// lookupPrefix determines the prefix of "importpath" that corresponds to
// the root of the repository. Results are cached.
func (r *externalResolver) lookupPrefix(importpath string) (string, error) {
Expand Down Expand Up @@ -117,6 +119,12 @@ func (r *externalResolver) lookupPrefix(importpath string) (string, error) {
subpaths = append(subpaths, prefix)
}

// gopkg.in is special, and might have either one or two levels of
// missing paths. See http://labix.org/gopkg.in for URL patterns.
if match := gopkginPattern.FindStringSubmatch(importpath); len(match) > 0 {
return match[1], nil
}

// Look up the import path using vcs.
root, err := r.repoRootForImportPath(importpath, false)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions resolve/resolve_external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestSpecialCases(t *testing.T) {
{in: "github.com/foo/bar", want: "github.com/foo/bar"},
{in: "github.com/foo/bar/baz", want: "github.com/foo/bar"},
{in: "gopkg.in/yaml.v2", want: "gopkg.in/yaml.v2"},
{in: "gopkg.in/src-d/go-git.v4", want: "gopkg.in/src-d/go-git.v4"},
{in: "unsupported.org/x/net/context", wantError: true},
{
in: "private.com/my/repo/package/path",
Expand Down
15 changes: 15 additions & 0 deletions rules/sort_labels.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/* Copyright 2017 The Bazel Authors. All rights reserved.
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 rules

import (
Expand Down

0 comments on commit 9989aca

Please sign in to comment.