aboutsummaryrefslogtreecommitdiffhomepage
path: root/base_workspace/examples/go
diff options
context:
space:
mode:
authorGravatar Damien Martin-Guillerez <dmarting@google.com>2015-03-24 09:05:08 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-03-24 16:41:48 +0000
commitadeef73a97cf191301a7b563883a075caed733b7 (patch)
treec06734cbffa4160b156779da7c87dbf5cc2b6f94 /base_workspace/examples/go
parent5247ff53465afc6ad9db889d1ec3f106ec09a3d6 (diff)
Move all examples into Bazel workspace
Those examples will be used for Bazel integration tests and their sources should be available directly to the Bazel workspace itself. -- MOS_MIGRATED_REVID=89380736
Diffstat (limited to 'base_workspace/examples/go')
-rw-r--r--base_workspace/examples/go/BUILD14
-rw-r--r--base_workspace/examples/go/README.md121
-rw-r--r--base_workspace/examples/go/fib.go11
-rw-r--r--base_workspace/examples/go/lib1/BUILD24
-rw-r--r--base_workspace/examples/go/lib1/fail_test.go9
-rw-r--r--base_workspace/examples/go/lib1/lib1.go9
-rw-r--r--base_workspace/examples/go/lib1/lib1_test.go14
7 files changed, 0 insertions, 202 deletions
diff --git a/base_workspace/examples/go/BUILD b/base_workspace/examples/go/BUILD
deleted file mode 100644
index dd0846110c..0000000000
--- a/base_workspace/examples/go/BUILD
+++ /dev/null
@@ -1,14 +0,0 @@
-# See README.md for instructions on how to use these rules.
-
-package(default_visibility = ["//visibility:public"])
-
-load("/tools/build_rules/go_rules", "go_library", "go_binary")
-
-go_binary(
- name = "fib",
- srcs = glob(
- ["*.go"],
- exclude = ["*_test.go"],
- ),
- deps = ["//examples/go/lib1"],
-)
diff --git a/base_workspace/examples/go/README.md b/base_workspace/examples/go/README.md
deleted file mode 100644
index 69bcc4c664..0000000000
--- a/base_workspace/examples/go/README.md
+++ /dev/null
@@ -1,121 +0,0 @@
-
-Go rules
---------
-
-The files here demonstrate how to use the rules for Go supplied under
-`//tools/build_rules:go_rules.bzl`. The rules should be considered
-experimental. They support:
-
- * libraries
- * binaries
- * tests
-
-They currently do not support:
-
- * coverage
- * race detector
- * multiple target configurations
- * //+build tags
- * C/C++ interoperation (cgo, swig etc.)
-
-
-Testing
--------
-
-Setup a symlink to the Go installation you wish to use,
-
- ln -s /usr/lib/golang/ tools/go/go_root
-
-or
-
- ln -s $(go env GOROOT) tools/go/go_root
-
-To build something, run
-
- bazel build examples/go/...
-
-To run a test, run
-
- bazel test --test_arg=--test.v examples/go/lib1:lib1_test
-
-
-Writing BUILD rules
--------------------
-
-In the bazel model of compiling Go, each directory can hold multiple
-packages, rather than just one in the standard "go" tool. Suppose you
-have
-
- dir/f.go:
-
- package p
- func F() {}
-
-then in the BUILD file could say
-
- go_library(
- name = "q",
- srcs = ["f.go"])
-
-and you import it with its Bazel name,
-
- import "dir/p/q"
-
-this add the declared package name as namespace, i.e., it is
-equivalent to
-
- import p "dir/p/q"
-
-so you use it as follows
-
- import "dir/p/q"
- main() {
- p.F()
- }
-
-
-Writing tests
--------------
-
-For tests, you should create a separate target,
-
- go_test(
- name = "q_test",
- srcs = [ "f_test.go" ],
- deps = [ ":q" ])
-
-if the test code is in the same package as the library under test
-(e.g., because you are testing private parts of the library), you should
-use the `library` attribute,
-
- go_test(
- name = "q_test",
- srcs = [ "f_test.go" ],
- library = ":q" )
-
-This causes the test and the library under test to be compiled
-together.
-
-
-FAQ
----
-
-# Why does this not follow the external Go conventions?
-
-These rules were inspired on Google's internal Go rules, which work
-like this. For Bazel, these make more sense, because directories in
-Bazel do not correspond to single targets.
-
-
-# Do I have to specify dependencies twice?
-
-Yes, once in the BUILD file, once in the source file. Bazel does not
-examine file contents, so it cannot infer the dependencies. It is
-possible to generate the BUILD file from the Go sources through a
-separate program, though.
-
-
-Disclaimer
-----------
-
-These rules are not supported by Google's Go team.
diff --git a/base_workspace/examples/go/fib.go b/base_workspace/examples/go/fib.go
deleted file mode 100644
index 43d8a499ba..0000000000
--- a/base_workspace/examples/go/fib.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package main
-
-import (
- "fmt"
-
- "examples/go/lib1/lib1"
-)
-
-func main() {
- fmt.Println("Fib(5):", lib1.Fib(5))
-}
diff --git a/base_workspace/examples/go/lib1/BUILD b/base_workspace/examples/go/lib1/BUILD
deleted file mode 100644
index fb400772ef..0000000000
--- a/base_workspace/examples/go/lib1/BUILD
+++ /dev/null
@@ -1,24 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-load("/tools/build_rules/go_rules", "go_library", "go_binary", "go_test")
-
-go_library(
- name = "lib1",
- srcs = glob(
- ["*.go"],
- exclude = ["*_test.go"],
- ),
-)
-
-go_test(
- name = "lib1_test",
- srcs = [
- "lib1_test.go",
- ],
- library = ":lib1",
-)
-
-go_test(
- name = "fail_test",
- srcs = ["fail_test.go"],
-)
diff --git a/base_workspace/examples/go/lib1/fail_test.go b/base_workspace/examples/go/lib1/fail_test.go
deleted file mode 100644
index 5ef41a3b4d..0000000000
--- a/base_workspace/examples/go/lib1/fail_test.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package fail
-
-import (
- "testing"
-)
-
-func TestFail(t *testing.T) {
- t.Fatal("I am failing.")
-}
diff --git a/base_workspace/examples/go/lib1/lib1.go b/base_workspace/examples/go/lib1/lib1.go
deleted file mode 100644
index f42494770d..0000000000
--- a/base_workspace/examples/go/lib1/lib1.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package lib1
-
-func Fib(n int) int {
- if n < 2 {
- return 1
- }
-
- return Fib(n-1) + Fib(n-2)
-}
diff --git a/base_workspace/examples/go/lib1/lib1_test.go b/base_workspace/examples/go/lib1/lib1_test.go
deleted file mode 100644
index 8eb88a0aca..0000000000
--- a/base_workspace/examples/go/lib1/lib1_test.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package lib1
-
-import (
- "testing"
-)
-
-func TestFib(t *testing.T) {
- got := Fib(5)
- want := 8
-
- if got != want {
- t.Fatalf("got %d want %d", got, want)
- }
-}