Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure go_binary.embed libraries' importpath is main #2135

Merged
merged 2 commits into from Jul 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions go/private/actions/archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def emit_archive(go, source = None):
cxxopts = [f for fs in source.cxxopts for f in fs.split(" ")]
clinkopts = [f for fs in source.clinkopts for f in fs.split(" ")]

importpath, _ = effective_importpath_pkgpath(source.library)
importmap = "main" if source.library.is_main else source.library.importmap
if source.cgo and not go.mode.pure:
cgo = cgo_configure(
go,
Expand All @@ -103,8 +105,8 @@ def emit_archive(go, source = None):
go,
sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
cover = source.cover,
importpath = effective_importpath_pkgpath(source.library)[0],
importmap = source.library.importmap,
importpath = importpath,
importmap = importmap,
archives = direct,
out_lib = out_lib,
out_export = out_export,
Expand All @@ -127,8 +129,8 @@ def emit_archive(go, source = None):
go,
sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
cover = source.cover,
importpath = effective_importpath_pkgpath(source.library)[0],
importmap = source.library.importmap,
importpath = importpath,
importmap = importmap,
archives = direct,
out_lib = out_lib,
out_export = out_export,
Expand All @@ -152,7 +154,7 @@ def emit_archive(go, source = None):
go.compile(
go,
sources = split.go,
importpath = source.library.importmap,
importpath = importmap,
archives = direct,
out_lib = out_lib,
out_export = out_export,
Expand All @@ -169,7 +171,7 @@ def emit_archive(go, source = None):
go.compile(
go,
sources = split.go + split.asm + split.headers,
importpath = source.library.importmap,
importpath = importmap,
archives = direct,
out_lib = partial_lib,
out_export = out_export,
Expand Down
3 changes: 2 additions & 1 deletion go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _tool_args(go):
args.set_param_file_format("multiline")
return args

def _new_library(go, name = None, importpath = None, resolver = None, importable = True, testfilter = None, **kwargs):
def _new_library(go, name = None, importpath = None, resolver = None, importable = True, testfilter = None, is_main = False, **kwargs):
if not importpath:
importpath = go.importpath
importmap = go.importmap
Expand All @@ -164,6 +164,7 @@ def _new_library(go, name = None, importpath = None, resolver = None, importable
pathtype = pathtype,
resolve = resolver,
testfilter = testfilter,
is_main = is_main,
**kwargs
)

Expand Down
2 changes: 1 addition & 1 deletion go/private/rules/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _go_binary_impl(ctx):
"""go_binary_impl emits actions for compiling and linking a go executable."""
go = go_context(ctx)

library = go.new_library(go, importable = False)
library = go.new_library(go, importable = False, is_main = True)
source = go.library_to_source(go, ctx.attr, library, ctx.coverage_instrumented())
name = ctx.attr.basename
if not name:
Expand Down
1 change: 1 addition & 0 deletions go/private/rules/nogo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def _nogo_impl(ctx):
importmap = "nogomain",
importpath_aliases = (),
pathtype = EXPORT_PATH,
is_main = True,
resolve = None,
)

Expand Down
1 change: 1 addition & 0 deletions go/private/rules/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def _go_test_impl(ctx):
importmap = "testmain",
importpath_aliases = (),
pathtype = INFERRED_PATH,
is_main = True,
resolve = None,
)
test_deps = external_archive.direct + [external_archive]
Expand Down
6 changes: 6 additions & 0 deletions go/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ an input to the `library_to_source`_ helper method, which produces GoSource_.
| A function called by `library_to_source`_ that can be used to resolve this |
| library to a mode-specific GoSource_. |
+--------------------------------+-----------------------------------------------------------------+
| :param:`is_main` | :type:`bool` |
+--------------------------------+-----------------------------------------------------------------+
| Indicates whether the library should be compiled as a `main` package. |
| `main` packages may have arbitrary `importpath` and `importmap` values, |
| but the compiler and linker must see them as `main`. |
+--------------------------------+-----------------------------------------------------------------+

GoSource
~~~~~~~~
Expand Down