diff --git a/go/private/BUILD.bazel b/go/private/BUILD.bazel index 411412cea..005bd14e3 100644 --- a/go/private/BUILD.bazel +++ b/go/private/BUILD.bazel @@ -63,11 +63,8 @@ bzl_library( "//go/private:platforms", "//go/private:providers", "//go/private/actions:archive", - "//go/private/actions:asm", "//go/private/actions:binary", - "//go/private/actions:compile", "//go/private/actions:link", - "//go/private/actions:pack", "//go/private/actions:stdlib", ], ) diff --git a/go/private/actions/BUILD.bazel b/go/private/actions/BUILD.bazel index 82f43ffc0..348e76252 100644 --- a/go/private/actions/BUILD.bazel +++ b/go/private/actions/BUILD.bazel @@ -26,16 +26,6 @@ bzl_library( ], ) -bzl_library( - name = "asm", - srcs = ["asm.bzl"], - visibility = ["//go:__subpackages__"], - deps = [ - "//go/private:mode", - "//go/private/actions:deprecation", - ], -) - bzl_library( name = "binary", srcs = ["binary.bzl"], @@ -46,16 +36,6 @@ bzl_library( ], ) -bzl_library( - name = "compile", - srcs = ["compile.bzl"], - visibility = ["//go:__subpackages__"], - deps = [ - "//go/private:mode", - "//go/private/actions:deprecation", - ], -) - bzl_library( name = "compilepkg", srcs = ["compilepkg.bzl"], @@ -66,12 +46,6 @@ bzl_library( ], ) -bzl_library( - name = "deprecation", - srcs = ["deprecation.bzl"], - visibility = ["//go:__subpackages__"], -) - bzl_library( name = "link", srcs = ["link.bzl"], @@ -84,13 +58,6 @@ bzl_library( ], ) -bzl_library( - name = "pack", - srcs = ["pack.bzl"], - visibility = ["//go:__subpackages__"], - deps = ["//go/private/actions:deprecation"], -) - bzl_library( name = "stdlib", srcs = ["stdlib.bzl"], diff --git a/go/private/actions/asm.bzl b/go/private/actions/asm.bzl deleted file mode 100644 index 683ffa7ea..000000000 --- a/go/private/actions/asm.bzl +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2014 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. - -load( - "//go/private:mode.bzl", - "link_mode_args", -) -load( - "//go/private/actions:deprecation.bzl", - "LEGACY_ACTIONS_DEPRECATION_NOTICE", -) - -def emit_asm( - go, - source = None, - hdrs = []): - """See go/toolchains.rst#asm for full documentation.""" - - print(LEGACY_ACTIONS_DEPRECATION_NOTICE.format( - old = "go_context.asm", - new = "go_context.archive", - )) - - if source == None: - fail("source is a required parameter") - - out_obj = go.declare_file(go, path = source.basename[:-2], ext = ".o") - inputs = hdrs + go.sdk.tools + go.sdk.headers + go.stdlib.libs + [source] - - builder_args = go.builder_args(go, "asm") - builder_args.add("-o", out_obj) - builder_args.add(source) - - # TODO(#1463): use uniquify=True when available. - tool_args = go.tool_args(go) - includes = ([go.sdk.root_file.dirname + "/pkg/include"] + - [f.dirname for f in hdrs]) - includes = sorted({i: None for i in includes}.keys()) - tool_args.add_all(includes, before_each = "-I") - tool_args.add_all(link_mode_args(go.mode)) - go.actions.run( - inputs = inputs, - outputs = [out_obj], - mnemonic = "GoAsm", - executable = go.toolchain._builder, - arguments = [builder_args, "--", tool_args], - env = go.env, - ) - return out_obj diff --git a/go/private/actions/compile.bzl b/go/private/actions/compile.bzl deleted file mode 100644 index 18aea2224..000000000 --- a/go/private/actions/compile.bzl +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright 2014 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. - -load( - "//go/private:mode.bzl", - "link_mode_args", -) -load( - "//go/private/actions:deprecation.bzl", - "LEGACY_ACTIONS_DEPRECATION_NOTICE", -) - -def _archive(v): - importpaths = [v.data.importpath] - importpaths.extend(v.data.importpath_aliases) - return "{}={}={}".format( - ":".join(importpaths), - v.data.importmap, - v.data.export_file.path if v.data.export_file else v.data.file.path, - ) - -def emit_compile( - go, - sources = None, - importpath = "", # actually importmap, left as importpath for compatibility - archives = [], - out_lib = None, - out_export = None, - gc_goopts = [], - testfilter = None, - asmhdr = None): - """See go/toolchains.rst#compile for full documentation.""" - - print(LEGACY_ACTIONS_DEPRECATION_NOTICE.format( - old = "go_context.compile", - new = "go_context.archive", - )) - - if sources == None: - fail("sources is a required parameter") - if out_lib == None: - fail("out_lib is a required parameter") - - inputs = (sources + [go.package_list] + - [archive.data.export_file for archive in archives] + - go.sdk.tools + go.sdk.headers + go.stdlib.libs) - outputs = [out_lib, out_export] - - builder_args = go.builder_args(go, "compile") - builder_args.add_all(sources, before_each = "-src") - builder_args.add_all(archives, before_each = "-arc", map_each = _archive) - builder_args.add("-o", out_lib) - builder_args.add("-x", out_export) - builder_args.add("-package_list", go.package_list) - if testfilter: - builder_args.add("-testfilter", testfilter) - if go.nogo: - builder_args.add("-nogo", go.nogo) - inputs.append(go.nogo) - - tool_args = go.tool_args(go) - if asmhdr: - builder_args.add("-asmhdr", asmhdr) - outputs.append(asmhdr) - tool_args.add("-trimpath", ".") - - #TODO: Check if we really need this expand make variables in here - #TODO: If we really do then it needs to be moved all the way back out to the rule - gc_goopts = [go._ctx.expand_make_variables("gc_goopts", f, {}) for f in gc_goopts] - tool_args.add_all(gc_goopts) - if go.mode.race: - tool_args.add("-race") - if go.mode.msan: - tool_args.add("-msan") - tool_args.add_all(link_mode_args(go.mode)) - if importpath: - builder_args.add("-p", importpath) - if go.mode.debug: - tool_args.add_all(["-N", "-l"]) - tool_args.add_all(go.toolchain.flags.compile) - go.actions.run( - inputs = inputs, - outputs = outputs, - mnemonic = "GoCompile", - executable = go.toolchain._builder, - arguments = [builder_args, "--", tool_args], - env = go.env, - ) diff --git a/go/private/actions/deprecation.bzl b/go/private/actions/deprecation.bzl deleted file mode 100644 index d72573173..000000000 --- a/go/private/actions/deprecation.bzl +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2022 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. - -LEGACY_ACTIONS_DEPRECATION_NOTICE = "The rules_go team intends to remove '{old}' in version 0.36.0 as it is no longer used by the ruleset itself and entirely untested. Consider using '{new}' instead. If that should not be possible for you, please comment on https://github.com/bazelbuild/rules_go/issues/3168." diff --git a/go/private/actions/pack.bzl b/go/private/actions/pack.bzl deleted file mode 100644 index a75192efc..000000000 --- a/go/private/actions/pack.bzl +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2014 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. - -load( - "//go/private/actions:deprecation.bzl", - "LEGACY_ACTIONS_DEPRECATION_NOTICE", -) - -def emit_pack( - go, - in_lib = None, - out_lib = None, - objects = [], - archives = []): - """See go/toolchains.rst#pack for full documentation.""" - - print(LEGACY_ACTIONS_DEPRECATION_NOTICE.format( - old = "go_context.pack", - new = "go_context.link", - )) - - if in_lib == None: - fail("in_lib is a required parameter") - if out_lib == None: - fail("out_lib is a required parameter") - - inputs = [in_lib] + go.sdk.tools + objects + archives - - args = go.builder_args(go, "pack") - args.add("-in", in_lib) - args.add("-out", out_lib) - args.add_all(objects, before_each = "-obj") - args.add_all(archives, before_each = "-arc") - - go.actions.run( - inputs = inputs, - outputs = [out_lib], - mnemonic = "GoPack", - executable = go.toolchain._builder, - arguments = [args], - env = go.env, - ) diff --git a/go/private/context.bzl b/go/private/context.bzl index ac4f22f47..460972d07 100644 --- a/go/private/context.bzl +++ b/go/private/context.bzl @@ -518,11 +518,8 @@ def go_context(ctx, attr = None): cover_format = mode.cover_format, # Action generators archive = toolchain.actions.archive, - asm = toolchain.actions.asm, binary = toolchain.actions.binary, - compile = toolchain.actions.compile, link = toolchain.actions.link, - pack = toolchain.actions.pack, # Helpers args = _new_args, # deprecated diff --git a/go/private/go_toolchain.bzl b/go/private/go_toolchain.bzl index f85f1ab26..5e9df39c2 100644 --- a/go/private/go_toolchain.bzl +++ b/go/private/go_toolchain.bzl @@ -18,11 +18,8 @@ Toolchain rules used by go. load("//go/private:platforms.bzl", "PLATFORMS") load("//go/private:providers.bzl", "GoSDK") load("//go/private/actions:archive.bzl", "emit_archive") -load("//go/private/actions:asm.bzl", "emit_asm") load("//go/private/actions:binary.bzl", "emit_binary") -load("//go/private/actions:compile.bzl", "emit_compile") load("//go/private/actions:link.bzl", "emit_link") -load("//go/private/actions:pack.bzl", "emit_pack") load("//go/private/actions:stdlib.bzl", "emit_stdlib") GO_TOOLCHAIN = "@io_bazel_rules_go//go:toolchain" @@ -38,11 +35,8 @@ def _go_toolchain_impl(ctx): default_goarch = ctx.attr.goarch, actions = struct( archive = emit_archive, - asm = emit_asm, binary = emit_binary, - compile = emit_compile, link = emit_link, - pack = emit_pack, stdlib = emit_stdlib, ), flags = struct( diff --git a/go/toolchains.rst b/go/toolchains.rst index 1a77b234e..cc705b5df 100644 --- a/go/toolchains.rst +++ b/go/toolchains.rst @@ -605,12 +605,8 @@ Methods * Action generators * archive_ - * asm_ * binary_ - * compile_ - * cover_ * link_ - * pack_ * Helpers @@ -641,33 +637,6 @@ It returns a GoArchive_. +--------------------------------+-----------------------------+-----------------------------------+ -asm -+++ - -**Deprecated:** Planned to be removed in rules_go version 0.36.0. Please use `archive` instead and -comment on https://github.com/bazelbuild/rules_go/issues/3168 if should not be possible. - -The asm function adds an action that runs ``go tool asm`` on a source file to -produce an object, and returns the File of that object. - -+--------------------------------+-----------------------------+-----------------------------------+ -| **Name** | **Type** | **Default value** | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`go` | :type:`GoContext` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| This must be the same GoContext object you got this function from. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`source` | :type:`File` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| A source code artifact to assemble. | -| This must be a ``.s`` file that contains code in the platform neutral `go assembly`_ language. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`hdrs` | :type:`File iterable` | :value:`[]` | -+--------------------------------+-----------------------------+-----------------------------------+ -| The list of .h files that may be included by the source. | -+--------------------------------+-----------------------------+-----------------------------------+ - - binary ++++++ @@ -714,96 +683,6 @@ a ``runfiles`` object. | file name based on ``name``, the target platform, and the link mode. | +--------------------------------+-----------------------------+-----------------------------------+ -compile -+++++++ - -**Deprecated:** Planned to be removed in rules_go version 0.36.0. Please use `archive` instead and -comment on https://github.com/bazelbuild/rules_go/issues/3168 if should not be possible. - -The compile function adds an action that compiles a list of source files into -a package archive (.a file). - -It does not return anything. - -+--------------------------------+-----------------------------+-----------------------------------+ -| **Name** | **Type** | **Default value** | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`go` | :type:`GoContext` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| This must be the same GoContext object you got this function from. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`sources` | :type:`File iterable` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| An iterable of source code artifacts. | -| These must be pure .go files, no assembly or cgo is allowed. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`importpath` | :type:`string` | :value:`""` | -+--------------------------------+-----------------------------+-----------------------------------+ -| The import path this package represents. This is passed to the -p flag. When the actual import | -| path is different than the source import path (i.e., when ``importmap`` is set in a | -| ``go_library`` rule), this should be the actual import path. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`archives` | :type:`GoArchive iterable` | :value:`[]` | -+--------------------------------+-----------------------------+-----------------------------------+ -| An iterable of all directly imported libraries. | -| The action will verify that all directly imported libraries were supplied, not allowing | -| transitive dependencies to satisfy imports. It will not check that all supplied libraries were | -| used though. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`out_lib` | :type:`File` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| The archive file that should be produced. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`out_export` | :type:`File` | :value:`None` | -+--------------------------------+-----------------------------+-----------------------------------+ -| File where extra information about the package may be stored. This is used | -| by nogo to store serialized facts about definitions. In the future, it may | -| be used to store export data (instead of the .a file). | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`gc_goopts` | :type:`string_list` | :value:`[]` | -+--------------------------------+-----------------------------+-----------------------------------+ -| Additional flags to pass to the compiler. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`testfilter` | :type:`string` | :value:`"off"` | -+--------------------------------+-----------------------------+-----------------------------------+ -| Controls how files with a ``_test`` suffix are filtered. | -| | -| * ``"off"`` - files with and without a ``_test`` suffix are compiled. | -| * ``"only"`` - only files with a ``_test`` suffix are compiled. | -| * ``"exclude"`` - only files without a ``_test`` suffix are compiled. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`asmhdr` | :type:`File` | :value:`None` | -+--------------------------------+-----------------------------+-----------------------------------+ -| If provided, the compiler will write an assembly header to this file. | -+--------------------------------+-----------------------------+-----------------------------------+ - - -cover -+++++ - -**Removed in rules_go 0.32.0:** Please comment on https://github.com/bazelbuild/rules_go/issues/3168 -if you still use this feature and cannot rely on `archive` instead. - -The cover function adds an action that runs ``go tool cover`` on a set of source -files to produce copies with cover instrumentation. - -Returns a covered GoSource_ with the required source files process for coverage. - -Note that this removes most comments, including cgo comments. - -+--------------------------------+-----------------------------+-----------------------------------+ -| **Name** | **Type** | **Default value** | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`go` | :type:`GoContext` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| This must be the same GoContext object you got this function from. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`source` | :type:`GoSource` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| The source object to process. Any source files in the object that have been marked as needing | -| coverage will be processed and substiuted in the returned GoSource. | -+--------------------------------+-----------------------------+-----------------------------------+ - link ++++ @@ -847,43 +726,6 @@ It does not return anything. | Info file used for link stamping. | +--------------------------------+-----------------------------+-----------------------------------+ -pack -++++ - -**Deprecated:** Planned to be removed in rules_go version 0.36.0. Please use `archive` instead and -comment on https://github.com/bazelbuild/rules_go/issues/3168 if should not be possible. - -The pack function adds an action that produces an archive from a base archive -and a collection of additional object files. - -It does not return anything. - -+--------------------------------+-----------------------------+-----------------------------------+ -| **Name** | **Type** | **Default value** | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`go` | :type:`GoContext` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| This must be the same GoContext object you got this function from. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`in_lib` | :type:`File` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| The archive that should be copied and appended to. | -| This must always be an archive in the common ar form (like that produced by the go compiler). | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`out_lib` | :type:`File` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| The archive that should be produced. | -| This will always be an archive in the common ar form (like that produced by the go compiler). | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`objects` | :type:`File iterable` | :value:`()` | -+--------------------------------+-----------------------------+-----------------------------------+ -| An iterable of object files to be added to the output archive file. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`archives` | :type:`list of File` | :value:`[]` | -+--------------------------------+-----------------------------+-----------------------------------+ -| Additional archives whose objects will be appended to the output. | -| These can be ar files in either common form or either the bsd or sysv variations. | -+--------------------------------+-----------------------------+-----------------------------------+ args ++++ diff --git a/go/tools/builders/BUILD.bazel b/go/tools/builders/BUILD.bazel index 40500a49f..ce5182cdf 100644 --- a/go/tools/builders/BUILD.bazel +++ b/go/tools/builders/BUILD.bazel @@ -44,7 +44,6 @@ filegroup( "asm.go", "builder.go", "cgo2.go", - "compile.go", "compilepkg.go", "cover.go", "edit.go", diff --git a/go/tools/builders/asm.go b/go/tools/builders/asm.go index bc9891dba..133e950fd 100644 --- a/go/tools/builders/asm.go +++ b/go/tools/builders/asm.go @@ -15,9 +15,6 @@ package main import ( - "flag" - "fmt" - "go/build" "io/ioutil" "os" "path/filepath" @@ -27,46 +24,6 @@ import ( "strings" ) -// asm builds a single .s file with "go tool asm". It is invoked by the -// Go rules as an action. -func asm(args []string) error { - // Parse arguments. - args, _, err := expandParamsFiles(args) - if err != nil { - return err - } - builderArgs, asmFlags := splitArgs(args) - var outPath string - flags := flag.NewFlagSet("GoAsm", flag.ExitOnError) - flags.StringVar(&outPath, "o", "", "The output archive file to write") - goenv := envFlags(flags) - if err := flags.Parse(builderArgs); err != nil { - return err - } - if err := goenv.checkFlags(); err != nil { - return err - } - if flags.NArg() != 1 { - return fmt.Errorf("wanted exactly 1 source file; got %d", flags.NArg()) - } - source := flags.Args()[0] - - // Filter the input file. - metadata, err := readFileInfo(build.Default, source) - if err != nil { - return err - } - if !metadata.matched { - source = os.DevNull - } - - // Build source with the assembler. - // Note: As of Go 1.19, this would require a valid package path to work. - // But since this functionality is only used by the deprecated action API, - // we won't fix this. - return asmFile(goenv, source, "", asmFlags, outPath) -} - // buildSymabisFile generates a file from assembly files that is consumed // by the compiler. This is only needed in go1.12+ when there is at least one // .s file. If the symabis file is not needed, no file will be generated, diff --git a/go/tools/builders/builder.go b/go/tools/builders/builder.go index a0ff0dcd6..5d691839c 100644 --- a/go/tools/builders/builder.go +++ b/go/tools/builders/builder.go @@ -39,14 +39,8 @@ func main() { var action func(args []string) error switch verb { - case "asm": - action = asm - case "compile": - action = compile case "compilepkg": action = compilePkg - case "cover": - action = cover case "filterbuildid": action = filterBuildID case "gentestmain": @@ -55,8 +49,6 @@ func main() { action = link case "gennogomain": action = genNogoMain - case "pack": - action = pack case "stdlib": action = stdlib case "stdliblist": diff --git a/go/tools/builders/compile.go b/go/tools/builders/compile.go deleted file mode 100644 index b83c9a775..000000000 --- a/go/tools/builders/compile.go +++ /dev/null @@ -1,230 +0,0 @@ -// 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. - -// compile compiles .go files with "go tool compile". It is invoked by the -// Go rules as an action. -package main - -import ( - "bytes" - "flag" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" -) - -func compile(args []string) error { - // Parse arguments. - args, _, err := expandParamsFiles(args) - if err != nil { - return err - } - builderArgs, toolArgs := splitArgs(args) - flags := flag.NewFlagSet("GoCompile", flag.ExitOnError) - unfiltered := multiFlag{} - archives := archiveMultiFlag{} - goenv := envFlags(flags) - packagePath := flags.String("p", "", "The package path (importmap) of the package being compiled") - flags.Var(&unfiltered, "src", "A source file to be filtered and compiled") - flags.Var(&archives, "arc", "Import path, package path, and file name of a direct dependency, separated by '='") - nogo := flags.String("nogo", "", "The nogo binary") - outExport := flags.String("x", "", "The output archive file to write export data and nogo facts") - output := flags.String("o", "", "The output archive file to write compiled code") - asmhdr := flags.String("asmhdr", "", "Path to assembly header file to write") - packageList := flags.String("package_list", "", "The file containing the list of standard library packages") - testfilter := flags.String("testfilter", "off", "Controls test package filtering") - if err := flags.Parse(builderArgs); err != nil { - return err - } - if err := goenv.checkFlags(); err != nil { - return err - } - *output = abs(*output) - if *asmhdr != "" { - *asmhdr = abs(*asmhdr) - } - - // Filter sources using build constraints. - all, err := filterAndSplitFiles(unfiltered) - if err != nil { - return err - } - goFiles, sFiles, hFiles := all.goSrcs, all.sSrcs, all.hSrcs - if len(all.cSrcs) > 0 { - return fmt.Errorf("unexpected C file: %s", all.cSrcs[0].filename) - } - if len(all.cxxSrcs) > 0 { - return fmt.Errorf("unexpected C++ file: %s", all.cxxSrcs[0].filename) - } - switch *testfilter { - case "off": - case "only": - testFiles := make([]fileInfo, 0, len(goFiles)) - for _, f := range goFiles { - if strings.HasSuffix(f.pkg, "_test") { - testFiles = append(testFiles, f) - } - } - goFiles = testFiles - case "exclude": - libFiles := make([]fileInfo, 0, len(goFiles)) - for _, f := range goFiles { - if !strings.HasSuffix(f.pkg, "_test") { - libFiles = append(libFiles, f) - } - } - goFiles = libFiles - default: - return fmt.Errorf("invalid test filter %q", *testfilter) - } - if len(goFiles) == 0 { - // We need to run the compiler to create a valid archive, even if there's - // nothing in it. GoPack will complain if we try to add assembly or cgo - // objects. - emptyPath := filepath.Join(filepath.Dir(*output), "_empty.go") - if err := ioutil.WriteFile(emptyPath, []byte("package empty\n"), 0666); err != nil { - return err - } - goFiles = append(goFiles, fileInfo{filename: emptyPath, pkg: "empty"}) - } - - if *packagePath == "" { - *packagePath = goFiles[0].pkg - } - - // Check that the filtered sources don't import anything outside of - // the standard library and the direct dependencies. - imports, err := checkImports(goFiles, archives, *packageList) - if err != nil { - return err - } - - // Build an importcfg file for the compiler. - importcfgName, err := buildImportcfgFileForCompile(imports, goenv.installSuffix, filepath.Dir(*output)) - if err != nil { - return err - } - defer os.Remove(importcfgName) - - // If there are assembly files, and this is go1.12+, generate symbol ABIs. - symabisName, err := buildSymabisFile(goenv, sFiles, hFiles, *asmhdr) - if symabisName != "" { - defer os.Remove(symabisName) - } - if err != nil { - return err - } - - // Compile the filtered files. - goargs := goenv.goTool("compile") - goargs = append(goargs, "-p", *packagePath) - goargs = append(goargs, "-importcfg", importcfgName) - goargs = append(goargs, "-pack", "-o", *output) - if symabisName != "" { - goargs = append(goargs, "-symabis", symabisName) - } - if *asmhdr != "" { - goargs = append(goargs, "-asmhdr", *asmhdr) - } - goargs = append(goargs, toolArgs...) - goargs = append(goargs, "--") - filenames := make([]string, 0, len(goFiles)) - for _, f := range goFiles { - filenames = append(filenames, f.filename) - } - goargs = append(goargs, filenames...) - absArgs(goargs, []string{"-I", "-o", "-trimpath", "-importcfg"}) - cmd := exec.Command(goargs[0], goargs[1:]...) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - if err := cmd.Start(); err != nil { - return fmt.Errorf("error starting compiler: %v", err) - } - - // tempdir to store nogo facts and pkgdef for packaging later - xTempDir, err := ioutil.TempDir(filepath.Dir(*outExport), "x_files") - if err != nil { - return err - } - defer os.RemoveAll(xTempDir) - // Run nogo concurrently. - var nogoOutput bytes.Buffer - nogoStatus := nogoNotRun - outFact := filepath.Join(xTempDir, nogoFact) - if *nogo != "" { - var nogoargs []string - nogoargs = append(nogoargs, "-p", *packagePath) - nogoargs = append(nogoargs, "-importcfg", importcfgName) - for _, arc := range archives { - nogoargs = append(nogoargs, "-fact", fmt.Sprintf("%s=%s", arc.importPath, arc.file)) - } - nogoargs = append(nogoargs, "-x", outFact) - nogoargs = append(nogoargs, filenames...) - nogoCmd := exec.Command(*nogo, nogoargs...) - nogoCmd.Stdout, nogoCmd.Stderr = &nogoOutput, &nogoOutput - if err := nogoCmd.Run(); err != nil { - if _, ok := err.(*exec.ExitError); ok { - // Only fail the build if nogo runs and finds errors in source code. - nogoStatus = nogoFailed - } else { - // All errors related to running nogo will merely be printed. - nogoOutput.WriteString(fmt.Sprintf("error running nogo: %v\n", err)) - nogoStatus = nogoError - } - } else { - nogoStatus = nogoSucceeded - } - } - if err := cmd.Wait(); err != nil { - return fmt.Errorf("error running compiler: %v", err) - } - - // Only print the output of nogo if compilation succeeds. - if nogoStatus == nogoFailed { - return fmt.Errorf("%s", nogoOutput.String()) - } - if nogoOutput.Len() != 0 { - fmt.Fprintln(os.Stderr, nogoOutput.String()) - } - - // Extract the export data file and pack it in an .x archive together with the - // nogo facts file (if there is one). This allows compile actions to depend - // on .x files only, so we don't need to recompile a package when one of its - // imports changes in a way that doesn't affect export data. - // TODO(golang/go#33820): Ideally, we would use -linkobj to tell the compiler - // to create separate .a and .x files for compiled code and export data, then - // copy the nogo facts into the .x file. Unfortunately, when building a plugin, - // the linker needs export data in the .a file. To work around this, we copy - // the export data into the .x file ourselves. - if err = extractFileFromArchive(*output, xTempDir, pkgDef); err != nil { - return err - } - pkgDefPath := filepath.Join(xTempDir, pkgDef) - if nogoStatus == nogoSucceeded { - return appendFiles(goenv, *outExport, []string{pkgDefPath, outFact}) - } - return appendFiles(goenv, *outExport, []string{pkgDefPath}) -} - -type nogoResult int - -const ( - nogoNotRun nogoResult = iota - nogoError - nogoFailed - nogoSucceeded -) diff --git a/go/tools/builders/compilepkg.go b/go/tools/builders/compilepkg.go index bc2fc2954..aaf70b06f 100644 --- a/go/tools/builders/compilepkg.go +++ b/go/tools/builders/compilepkg.go @@ -31,6 +31,15 @@ import ( "strings" ) +type nogoResult int + +const ( + nogoNotRun nogoResult = iota + nogoError + nogoFailed + nogoSucceeded +) + func compilePkg(args []string) error { // Parse arguments. args, _, err := expandParamsFiles(args) diff --git a/go/tools/builders/cover.go b/go/tools/builders/cover.go index d387a1860..fadc4fd7d 100644 --- a/go/tools/builders/cover.go +++ b/go/tools/builders/cover.go @@ -16,7 +16,6 @@ package main import ( "bytes" - "flag" "fmt" "go/parser" "go/token" @@ -25,43 +24,6 @@ import ( "strconv" ) -// cover transforms a source file with "go tool cover". It is invoked by the -// Go rules as an action. -func cover(args []string) error { - args, _, err := expandParamsFiles(args) - if err != nil { - return err - } - flags := flag.NewFlagSet("cover", flag.ExitOnError) - var coverSrc, coverVar, origSrc, srcName, mode string - flags.StringVar(&coverSrc, "o", "", "coverage output file") - flags.StringVar(&coverVar, "var", "", "name of cover variable") - flags.StringVar(&origSrc, "src", "", "original source file") - flags.StringVar(&srcName, "srcname", "", "source name printed in coverage data") - flags.StringVar(&mode, "mode", "set", "coverage mode to use") - goenv := envFlags(flags) - if err := flags.Parse(args); err != nil { - return err - } - if err := goenv.checkFlags(); err != nil { - return err - } - if coverSrc == "" { - return fmt.Errorf("-o was not set") - } - if coverVar == "" { - return fmt.Errorf("-var was not set") - } - if origSrc == "" { - return fmt.Errorf("-src was not set") - } - if srcName == "" { - srcName = origSrc - } - - return instrumentForCoverage(goenv, origSrc, srcName, coverVar, mode, coverSrc) -} - // instrumentForCoverage runs "go tool cover" on a source file to produce // a coverage-instrumented version of the file. It also registers the file // with the coverdata package. diff --git a/go/tools/builders/pack.go b/go/tools/builders/pack.go index 14d39766f..ddbb1930b 100644 --- a/go/tools/builders/pack.go +++ b/go/tools/builders/pack.go @@ -18,7 +18,6 @@ import ( "bufio" "bytes" "errors" - "flag" "fmt" "io" "io/ioutil" @@ -29,56 +28,6 @@ import ( "strings" ) -// pack copies an .a file and appends a list of .o files to the copy using -// go tool pack. It is invoked by the Go rules as an action. -// -// pack can also append .o files contained in a static library passed in -// with the -arc option. That archive may be in BSD or SysV / GNU format. -// pack has a primitive parser for these formats, since cmd/pack can't -// handle them, and ar may not be available (cpp.ar_executable is libtool -// on darwin). -func pack(args []string) error { - args, _, err := expandParamsFiles(args) - if err != nil { - return err - } - flags := flag.NewFlagSet("GoPack", flag.ExitOnError) - goenv := envFlags(flags) - inArchive := flags.String("in", "", "Path to input archive") - outArchive := flags.String("out", "", "Path to output archive") - objects := multiFlag{} - flags.Var(&objects, "obj", "Object to append (may be repeated)") - archives := multiFlag{} - flags.Var(&archives, "arc", "Archives to append") - if err := flags.Parse(args); err != nil { - return err - } - if err := goenv.checkFlags(); err != nil { - return err - } - - if err := copyFile(abs(*inArchive), abs(*outArchive)); err != nil { - return err - } - - dir, err := ioutil.TempDir("", "go-pack") - if err != nil { - return err - } - defer os.RemoveAll(dir) - - names := map[string]struct{}{} - for _, archive := range archives { - archiveObjects, err := extractFiles(archive, dir, names) - if err != nil { - return err - } - objects = append(objects, archiveObjects...) - } - - return appendFiles(goenv, abs(*outArchive), objects) -} - func copyFile(inPath, outPath string) error { inFile, err := os.Open(inPath) if err != nil {