Skip to content

Commit f32a39c

Browse files
committed
go_library()'s import path can now be customized.
Addresses bazel-contrib#16.
1 parent 79d4eba commit f32a39c

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

examples/bin/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ go_binary(
1212
"//examples/vendor/github.com/user/vendored:go_default_library",
1313
],
1414
)
15+
16+
go_binary(
17+
name = "bin_with_rename",
18+
srcs = ["bin.go"],
19+
deps = [
20+
"//examples/lib:go_default_library",
21+
"//examples/vendor/github.com/user:vendored",
22+
],
23+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package(
2+
default_visibility = ["//visibility:public"],
3+
)
4+
5+
load("//go:def.bzl", "go_library")
6+
7+
go_library(
8+
name = "vendored",
9+
srcs = [
10+
"vendored_without_buildfile/vendored.go",
11+
],
12+
source_import = "github.com/user/vendored",
13+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Copyright 2016 The Bazel Authors. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package vendored
17+
18+
// Vendored returns a string.
19+
func Vendored() string {
20+
return "I was vendored"
21+
}

go/def.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def emit_go_compile_action(ctx, sources, deps, out_lib, cgo_object=None):
160160
if source_import.rfind(_VENDOR_PREFIX) != -1:
161161
source_import = source_import[len(_VENDOR_PREFIX) + source_import.rfind(_VENDOR_PREFIX):]
162162

163+
if len(d.source_import):
164+
source_import = d.source_import
165+
163166
if source_import != actual_import:
164167
if source_import in import_map:
165168
fail("duplicate import %s: adding %s and have %s"
@@ -252,6 +255,7 @@ def go_library_impl(ctx):
252255
transitive_go_library_object = transitive_libs,
253256
cgo_object = cgo_object,
254257
transitive_cgo_deps = transitive_cgo_deps,
258+
source_import = ctx.attr.source_import,
255259
)
256260

257261
def _c_linker_options(ctx, blacklist=[]):
@@ -443,6 +447,7 @@ go_library_attrs = go_env_attrs + {
443447
"library": attr.label(
444448
providers = ["go_sources", "cgo_object"],
445449
),
450+
"source_import": attr.string(),
446451
}
447452

448453
go_library_outputs = {

0 commit comments

Comments
 (0)