Skip to content

Commit

Permalink
go_library()'s import path can now be customized.
Browse files Browse the repository at this point in the history
Addresses bazel-contrib#16.
  • Loading branch information
ivucica committed May 1, 2016
1 parent 79d4eba commit f32a39c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ go_binary(
"//examples/vendor/github_com/user/vendored:go_default_library",
],
)

go_binary(
name = "bin_with_rename",
srcs = ["bin.go"],
deps = [
"//examples/lib:go_default_library",
"//examples/vendor/github_com/user:vendored",
],
)
13 changes: 13 additions & 0 deletions examples/vendor/github_com/user/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package(
default_visibility = ["//visibility:public"],
)

load("//go:def.bzl", "go_library")

go_library(
name = "vendored",
srcs = [
"vendored_without_buildfile/vendored.go",
],
source_import = "github_com/user/vendored",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* 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 vendored

// Vendored returns a string.
func Vendored() string {
return "I was vendored"
}
5 changes: 5 additions & 0 deletions go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def emit_go_compile_action(ctx, sources, deps, out_lib, cgo_object=None):
if source_import.rfind(_VENDOR_PREFIX) != -1:
source_import = source_import[len(_VENDOR_PREFIX) + source_import.rfind(_VENDOR_PREFIX):]

if len(d.source_import):
source_import = d.source_import

if source_import != actual_import:
if source_import in import_map:
fail("duplicate import %s: adding %s and have %s"
Expand Down Expand Up @@ -252,6 +255,7 @@ def go_library_impl(ctx):
transitive_go_library_object = transitive_libs,
cgo_object = cgo_object,
transitive_cgo_deps = transitive_cgo_deps,
source_import = ctx.attr.source_import,
)

def _c_linker_options(ctx, blacklist=[]):
Expand Down Expand Up @@ -443,6 +447,7 @@ go_library_attrs = go_env_attrs + {
"library": attr.label(
providers = ["go_sources", "cgo_object"],
),
"source_import": attr.string(),
}

go_library_outputs = {
Expand Down

0 comments on commit f32a39c

Please sign in to comment.