aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Han-Wen Nienhuys <hanwen@google.com>2015-03-25 17:01:15 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-03-25 20:04:41 +0000
commit847764103294b4f61afc50b06bfe19284ac7b7e4 (patch)
tree6c991b9924583edc67f34faf6a988341527e80b5 /tools
parentbb3bde1628b6c555f4caf52179fdd669bcfc1c21 (diff)
Remove experimental Go support until we have a solution which fits the 'go' tool conventions better.
-- MOS_MIGRATED_REVID=89510837
Diffstat (limited to 'tools')
-rw-r--r--tools/BUILD1
-rw-r--r--tools/build_rules/go_rules.bzl282
-rw-r--r--tools/go/BUILD19
-rw-r--r--tools/go/generate_test_main.go91
4 files changed, 0 insertions, 393 deletions
diff --git a/tools/BUILD b/tools/BUILD
index df3abae3ae..41b4e23d5e 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -8,7 +8,6 @@ filegroup(
name = "srcs",
srcs = glob(["**"]) + [
"//tools/jdk:srcs",
- "//tools/go:srcs",
"//tools/genrule:srcs",
"//tools/cpp:srcs",
"//tools/objc:srcs",
diff --git a/tools/build_rules/go_rules.bzl b/tools/build_rules/go_rules.bzl
deleted file mode 100644
index e586671ee9..0000000000
--- a/tools/build_rules/go_rules.bzl
+++ /dev/null
@@ -1,282 +0,0 @@
-# Copyright 2014 Google Inc. 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.
-
-"""These are bare-bones Go rules.
-
-Several issues:
-
-- Currently hardcoded to 6g from the GC suite. We should be able to
- extract the CPU type from ctx.configuration instead.
-
-- It would be nice to be able to create a full-fledged Go
- configuration in Skylark.
-
-- Almost supports checked in compilers (should use a filegroup under
- tools/go instead of symlink).
-
-- No C++ interop.
-
-- deps must be populated by hand.
-
-- no test sharding or test XML.
-
-"""
-
-go_filetype = FileType([".go"])
-
-# TODO(bazel-team): it would be nice if Bazel had this built-in.
-def symlink_tree_commands(dest_dir, artifact_dict):
- """Symlink_tree_commands returns a list of commands to create the
- dest_dir, and populate it according to the given dict.
-
- Args:
- dest_dir: The destination directory, a string.
- artifact_dict: The mapping of exec-path => path in the dest_dir.
-
- Returns:
- A list of commands that will setup the symlink tree.
- """
- cmds = [
- "rm -rf " + dest_dir,
- "mkdir -p " + dest_dir,
- ]
-
- for item in artifact_dict.items():
- old_path = item[0]
- new_path = item[1]
- new_dir = new_path[:new_path.rfind('/')]
- up = (new_dir.count('/') + 1 +
- dest_dir.count('/') + 1)
- cmds += [
- "mkdir -p %s/%s" % (dest_dir, new_dir),
- "ln -s %s%s %s/%s" % ('../' * up, old_path, dest_dir, new_path),
- ]
- return cmds
-
-
-def emit_go_compile_action(ctx, sources, deps, out_lib):
- """Construct the command line for compiling Go code.
- Constructs a symlink tree to accomodate for workspace name.
-
- Args:
- ctx: The skylark Context.
- sources: an iterable of source code artifacts (or CTs? or labels?)
- deps: an iterable of dependencies. Each dependency d should have an
- artifact in d.go_library_object representing an imported library.
- out_lib: the artifact (configured target?) that should be produced
- """
-
- config_strip = len(ctx.configuration.bin_dir.path) + 1
-
- out_dir = out_lib.path + ".dir"
- out_depth = out_dir.count('/') + 1
- prefix = ""
- if ctx.workspace_name:
- ctx.workspace_name + "/"
-
- tree_layout = {}
- inputs = []
- for d in deps:
- library_artifact_path = d.go_library_object.path[config_strip:]
- tree_layout[d.go_library_object.path] = prefix + library_artifact_path
- inputs += [d.go_library_object]
-
- inputs += list(sources)
- for s in sources:
- tree_layout[s.path] = s.path
-
- cmds = symlink_tree_commands(out_dir, tree_layout)
- args = [
- "cd ", out_dir, "&&",
- ('../' * out_depth) + ctx.files.go_root[0].path + "/bin/go",
- "tool", "6g",
- "-o", ('../' * out_depth) + out_lib.path, "-pack",
-
- # Import path.
- "-I", "."]
-
- # Set -p to the import path of the library, ie.
- # (ctx.label.package + "/" ctx.label.name) for now.
- cmds += [ "export GOROOT=$(pwd)/" + ctx.files.go_root[0].path,
- ' '.join(args + cmd_helper.template(sources, "%{path}"))]
-
- ctx.action(
- inputs = inputs,
- outputs = [out_lib],
- mnemonic = "GoCompile",
- command = " && ".join(cmds))
-
-
-def go_library_impl(ctx):
- """Implements the go_library() rule."""
-
- sources = set(ctx.files.srcs)
- deps = ctx.targets.deps
- if ctx.targets.library:
- sources += ctx.target.library.go_sources
- deps += ctx.target.library.direct_deps
-
- if not sources:
- fail("may not be empty", "srcs")
-
- out_lib = ctx.outputs.lib
- emit_go_compile_action(ctx, set(sources), deps, out_lib)
-
- transitive_libs = set([out_lib])
- for dep in ctx.targets.deps:
- transitive_libs += dep.transitive_go_library_object
-
- return struct(
- files = set([out_lib]),
- direct_deps = deps,
- go_sources = sources,
- go_library_object = out_lib,
- transitive_go_library_object = transitive_libs)
-
-
-def emit_go_link_action(ctx, transitive_libs, lib, executable):
- """Sets up a symlink tree to libraries to link together."""
- out_dir = executable.path + ".dir"
- out_depth = out_dir.count('/') + 1
- tree_layout = {}
-
- config_strip = len(ctx.configuration.bin_dir.path) + 1
- prefix = ""
- if ctx.workspace_name:
- prefix = ctx.workspace_name + "/"
-
- for l in transitive_libs:
- library_artifact_path = l.path[config_strip:]
- tree_layout[l.path] = prefix + library_artifact_path
-
- tree_layout[lib.path] = prefix + lib.path[config_strip:]
- tree_layout[executable.path] = prefix + executable.path[config_strip:]
-
- cmds = symlink_tree_commands(out_dir, tree_layout)
- cmds += [
- "export GOROOT=$(pwd)/" + ctx.files.go_root[0].path,
- "cd " + out_dir,
- ' '.join([
- ('../' * out_depth) + ctx.files.go_root[0].path + "/bin/go",
- "tool", "6l", "-L", ".",
- "-o", prefix + executable.path[config_strip:],
- prefix + lib.path[config_strip:]])]
-
- ctx.action(
- inputs = list(transitive_libs) + [lib],
- outputs = [executable],
- command = ' && '.join(cmds),
- mnemonic = "GoLink")
-
-
-def go_binary_impl(ctx):
- """go_binary_impl emits the link action for a go executable."""
- lib_result = go_library_impl(ctx)
- executable = ctx.outputs.executable
- lib_out = ctx.outputs.lib
-
- emit_go_link_action(
- ctx, lib_result.transitive_go_library_object, lib_out, executable)
- return struct(files = set([executable]) + lib_result.files)
-
-
-def go_test_impl(ctx):
- """go_test_impl implements go testing.
-
- It emits an action to run the test generator, and then compile the
- test."""
-
- lib_result = go_library_impl(ctx)
- main_go = ctx.outputs.main_go
- prefix = ""
- if ctx.workspace_name:
- prefix = ctx.workspace_name + "/"
-
- go_import = prefix + ctx.label.package + "/" + ctx.label.name
-
- args = (["--package", go_import, "--output", ctx.outputs.main_go.path] +
- cmd_helper.template(lib_result.go_sources, "%{path}"))
- ctx.action(
- inputs = list(lib_result.go_sources),
- executable = ctx.executable.test_generator,
- outputs = [main_go],
- mnemonic = "GoTestGenTest",
- arguments = args)
-
- emit_go_compile_action(
- ctx, set([main_go]), ctx.targets.deps + [lib_result], ctx.outputs.main_lib)
-
- emit_go_link_action(
- ctx, lib_result.transitive_go_library_object,
- ctx.outputs.main_lib, ctx.outputs.executable)
-
- # TODO(bazel-team): the Go tests should do a chdir to the directory
- # holding the data files, so open-source go tests continue to work
- # without code changes.
- runfiles = ctx.runfiles(collect_data = True, files = [ctx.outputs.executable])
- return struct(runfiles=runfiles)
-
-
-go_library_attrs = {
- "data": attr.label_list(allow_files=True, cfg=DATA_CFG),
- "srcs": attr.label_list(allow_files=go_filetype),
- "deps": attr.label_list(
- providers=[
- "direct_deps",
- "go_library_object",
- "transitive_go_library_object",
- ]),
- "go_root": attr.label(
- default=Label("//tools/go:go_root"),
- allow_files=True,
- cfg=HOST_CFG),
- "library": attr.label(
- providers=["go_sources"]),
- }
-
-go_library_outputs = {
- "lib": "%{name}.a",
- }
-
-go_library = rule(
- go_library_impl,
- attrs = go_library_attrs,
- outputs =go_library_outputs)
-
-go_binary = rule(
- go_binary_impl,
- executable = True,
- attrs = go_library_attrs + {
- "stamp": attr.bool(default=False),
- },
- outputs = go_library_outputs)
-
-go_test = rule(
- go_test_impl,
- executable = True,
- test = True,
- attrs = go_library_attrs + {
- "test_generator": attr.label(
- default=Label("//tools/go:generate_test_main"),
- cfg=HOST_CFG, flags=["EXECUTABLE"]),
- # TODO(bazel-team): implement support for args and defines_main.
- "args": attr.string_list(),
- "defines_main": attr.bool(default=False),
- "stamp": attr.bool(default=False),
- },
- outputs = {
- "lib" : "%{name}.a",
- "main_lib": "%{name}_main_test.a",
- "main_go": "%{name}_main_test.go",
-})
diff --git a/tools/go/BUILD b/tools/go/BUILD
deleted file mode 100644
index dd9e0d707f..0000000000
--- a/tools/go/BUILD
+++ /dev/null
@@ -1,19 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-load("/tools/build_rules/go_rules", "go_binary", "go_library")
-
-# This should be a symlink to a GOROOT holding bin/ and pkg/
-exports_files(srcs = ["go_root"])
-
-go_binary(
- name = "generate_test_main",
- srcs = ["generate_test_main.go"],
-)
-
-filegroup(
- name = "srcs",
- srcs = [
- "BUILD",
- "generate_test_main.go",
- ],
-)
diff --git a/tools/go/generate_test_main.go b/tools/go/generate_test_main.go
deleted file mode 100644
index 6316802dde..0000000000
--- a/tools/go/generate_test_main.go
+++ /dev/null
@@ -1,91 +0,0 @@
-// Bare bones Go testing support for Bazel.
-
-package main
-
-import (
- "flag"
- "go/ast"
- "go/parser"
- "go/token"
- "log"
- "os"
- "strings"
- "text/template"
-)
-
-// Cases holds template data.
-type Cases struct {
- Package string
- Names []string
-}
-
-func main() {
- pkg := flag.String("package", "", "package from which to import test methods.")
- out := flag.String("output", "", "output file to write. Defaults to stdout.")
- flag.Parse()
-
- if *pkg == "" {
- log.Fatal("must set --package.")
- }
-
- outFile := os.Stdout
- if *out != "" {
- var err error
- outFile, err = os.Create(*out)
- if err != nil {
- log.Fatalf("os.Create(%q): %v", *out, err)
- }
- defer outFile.Close()
- }
-
- cases := Cases{
- Package: *pkg,
- }
- testFileSet := token.NewFileSet()
- for _, f := range flag.Args() {
- parse, err := parser.ParseFile(testFileSet, f, nil, parser.ParseComments)
- if err != nil {
- log.Fatalf("ParseFile(%q): %v", f, err)
- }
-
- for _, d := range parse.Decls {
- fn, ok := d.(*ast.FuncDecl)
- if !ok {
- continue
- }
- if fn.Recv != nil {
- continue
- }
- if !strings.HasPrefix(fn.Name.Name, "Test") {
- continue
- }
- cases.Names = append(cases.Names, fn.Name.Name)
- }
- }
-
- tpl := template.Must(template.New("source").Parse(`
-package main
-import (
- "testing"
-
- undertest "{{.Package}}"
-)
-
-func everything(pat, str string) (bool, error) {
- return true, nil
-}
-
-var tests = []testing.InternalTest{
-{{range .Names}}
- {"{{.}}", undertest.{{.}} },
-{{end}}
-}
-
-func main() {
- testing.Main(everything, tests, nil, nil)
-}
-`))
- if err := tpl.Execute(outFile, &cases); err != nil {
- log.Fatalf("template.Execute(%v): %v", cases, err)
- }
-}