From 96df361ac0fe25d908515234bff944bad3269216 Mon Sep 17 00:00:00 2001 From: Kristina Chodorow Date: Wed, 23 Mar 2016 21:20:22 +0000 Subject: Remove deprecated Skylark rules -- MOS_MIGRATED_REVID=117968196 --- BUILD | 4 - WORKSPACE | 8 - examples/d/hello_lib/BUILD | 42 -- examples/d/hello_lib/greeter.d | 51 -- examples/d/hello_lib/greeter_test.d | 22 - examples/d/hello_lib/native-greeter.c | 49 -- examples/d/hello_lib/native-greeter.h | 28 - examples/d/hello_lib/native_greeter.d | 43 -- examples/d/hello_world/BUILD | 17 - examples/d/hello_world/hello_world.d | 26 - examples/dotnet/example_binary/BUILD | 12 - examples/dotnet/example_binary/Program.cs | 14 - .../example_binary/Properties/AssemblyInfo.cs | 27 - examples/dotnet/example_lib/BUILD | 13 - examples/dotnet/example_lib/MyClass.cs | 19 - .../dotnet/example_lib/Properties/AssemblyInfo.cs | 27 - examples/dotnet/example_test/BUILD | 11 - examples/dotnet/example_test/MyTest.cs | 24 - examples/dotnet/example_transitive_lib/BUILD | 10 - .../Properties/AssemblyInfo.cs | 27 - .../example_transitive_lib/TransitiveClass.cs | 14 - examples/go/bin/BUILD | 14 - examples/go/bin/bin.go | 14 - examples/go/lib/BUILD | 20 - examples/go/lib/lib.go | 6 - examples/go/lib/lib_test.go | 11 - examples/go/vendor/github_com/user/vendored/BUILD | 12 - .../go/vendor/github_com/user/vendored/vendored.go | 6 - examples/sass/hello_world/BUILD | 13 - examples/sass/hello_world/main.scss | 13 - examples/sass/shared/BUILD | 15 - examples/sass/shared/_colors.scss | 5 - examples/sass/shared/_fonts.scss | 5 - site/docs/tutorial/backend-server.md | 126 +--- src/test/shell/bazel/BUILD | 13 - src/test/shell/bazel/bazel_go_example_test.sh | 283 --------- tools/BUILD | 9 - tools/build_defs/d/BUILD | 48 -- tools/build_defs/d/README.md | 678 --------------------- tools/build_defs/d/d.bzl | 534 ---------------- tools/build_defs/dotnet/BUILD | 23 - tools/build_defs/dotnet/README.md | 269 -------- tools/build_defs/dotnet/csharp.bzl | 332 ---------- tools/build_defs/groovy/README.md | 588 ------------------ tools/build_defs/groovy/groovy.bzl | 438 ------------- tools/build_defs/sass/BUILD | 12 - tools/build_defs/sass/README.md | 271 -------- tools/build_defs/sass/sass.bzl | 156 ----- tools/build_defs/sass/test/BUILD | 3 - tools/build_defs/sass/test/sass_rule_test.bzl | 45 -- tools/build_rules/appengine/BUILD | 25 - tools/build_rules/appengine/README.md | 231 ------- tools/build_rules/appengine/appengine.bzl | 316 ---------- .../appengine/appengine_deploy.sh.template | 48 -- .../appengine/appengine_runner.sh.template | 52 -- tools/build_rules/deprecation.bzl | 27 - tools/build_rules/go/BUILD | 15 - tools/build_rules/go/DESIGN.md | 61 -- tools/build_rules/go/README.md | 292 --------- tools/build_rules/go/def.bzl | 431 ------------- tools/build_rules/go/toolchain/BUILD | 42 -- tools/build_rules/go/tools/BUILD | 17 - tools/build_rules/go/tools/filter_tags/BUILD | 19 - .../go/tools/filter_tags/filter_tags.go | 51 -- .../go/tools/filter_tags/filter_tags_test.go | 119 ---- tools/build_rules/go/tools/generate_test_main.go | 95 --- 66 files changed, 11 insertions(+), 6280 deletions(-) delete mode 100644 examples/d/hello_lib/BUILD delete mode 100644 examples/d/hello_lib/greeter.d delete mode 100644 examples/d/hello_lib/greeter_test.d delete mode 100644 examples/d/hello_lib/native-greeter.c delete mode 100644 examples/d/hello_lib/native-greeter.h delete mode 100644 examples/d/hello_lib/native_greeter.d delete mode 100644 examples/d/hello_world/BUILD delete mode 100644 examples/d/hello_world/hello_world.d delete mode 100644 examples/dotnet/example_binary/BUILD delete mode 100644 examples/dotnet/example_binary/Program.cs delete mode 100644 examples/dotnet/example_binary/Properties/AssemblyInfo.cs delete mode 100644 examples/dotnet/example_lib/BUILD delete mode 100644 examples/dotnet/example_lib/MyClass.cs delete mode 100644 examples/dotnet/example_lib/Properties/AssemblyInfo.cs delete mode 100644 examples/dotnet/example_test/BUILD delete mode 100644 examples/dotnet/example_test/MyTest.cs delete mode 100644 examples/dotnet/example_transitive_lib/BUILD delete mode 100644 examples/dotnet/example_transitive_lib/Properties/AssemblyInfo.cs delete mode 100644 examples/dotnet/example_transitive_lib/TransitiveClass.cs delete mode 100644 examples/go/bin/BUILD delete mode 100644 examples/go/bin/bin.go delete mode 100644 examples/go/lib/BUILD delete mode 100644 examples/go/lib/lib.go delete mode 100644 examples/go/lib/lib_test.go delete mode 100644 examples/go/vendor/github_com/user/vendored/BUILD delete mode 100644 examples/go/vendor/github_com/user/vendored/vendored.go delete mode 100644 examples/sass/hello_world/BUILD delete mode 100644 examples/sass/hello_world/main.scss delete mode 100644 examples/sass/shared/BUILD delete mode 100644 examples/sass/shared/_colors.scss delete mode 100644 examples/sass/shared/_fonts.scss delete mode 100755 src/test/shell/bazel/bazel_go_example_test.sh delete mode 100644 tools/build_defs/d/BUILD delete mode 100644 tools/build_defs/d/README.md delete mode 100644 tools/build_defs/d/d.bzl delete mode 100644 tools/build_defs/dotnet/BUILD delete mode 100644 tools/build_defs/dotnet/README.md delete mode 100644 tools/build_defs/dotnet/csharp.bzl delete mode 100644 tools/build_defs/groovy/README.md delete mode 100644 tools/build_defs/groovy/groovy.bzl delete mode 100644 tools/build_defs/sass/BUILD delete mode 100644 tools/build_defs/sass/README.md delete mode 100644 tools/build_defs/sass/sass.bzl delete mode 100644 tools/build_defs/sass/test/BUILD delete mode 100644 tools/build_defs/sass/test/sass_rule_test.bzl delete mode 100644 tools/build_rules/appengine/BUILD delete mode 100644 tools/build_rules/appengine/README.md delete mode 100644 tools/build_rules/appengine/appengine.bzl delete mode 100644 tools/build_rules/appengine/appengine_deploy.sh.template delete mode 100644 tools/build_rules/appengine/appengine_runner.sh.template delete mode 100644 tools/build_rules/deprecation.bzl delete mode 100644 tools/build_rules/go/BUILD delete mode 100644 tools/build_rules/go/DESIGN.md delete mode 100644 tools/build_rules/go/README.md delete mode 100644 tools/build_rules/go/def.bzl delete mode 100644 tools/build_rules/go/toolchain/BUILD delete mode 100644 tools/build_rules/go/tools/BUILD delete mode 100644 tools/build_rules/go/tools/filter_tags/BUILD delete mode 100644 tools/build_rules/go/tools/filter_tags/filter_tags.go delete mode 100644 tools/build_rules/go/tools/filter_tags/filter_tags_test.go delete mode 100644 tools/build_rules/go/tools/generate_test_main.go diff --git a/BUILD b/BUILD index 83102412ec..2ff0bc9d79 100644 --- a/BUILD +++ b/BUILD @@ -46,7 +46,3 @@ pkg_tar( # Public but bazel-only visibility. visibility = ["//:__subpackages__"], ) - -load("//tools/build_rules/go:def.bzl", "go_prefix") - -go_prefix("github.com/bazelbuild/bazel") diff --git a/WORKSPACE b/WORKSPACE index fc9a0f7c60..05c5117286 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,16 +1,8 @@ -load("/tools/build_defs/d/d", "d_repositories") -load("/tools/build_defs/dotnet/csharp", "csharp_repositories") load("/tools/build_defs/jsonnet/jsonnet", "jsonnet_repositories") -load("/tools/build_defs/sass/sass", "sass_repositories") -load("/tools/build_rules/go/def", "go_repositories") load("/tools/build_rules/rust/rust", "rust_repositories") -csharp_repositories() -d_repositories() -go_repositories() jsonnet_repositories() rust_repositories() -sass_repositories() # Protobuf expects an //external:python_headers label which would contain the # Python headers if fast Python protos is enabled. Since we are not using fast diff --git a/examples/d/hello_lib/BUILD b/examples/d/hello_lib/BUILD deleted file mode 100644 index 3b4f084737..0000000000 --- a/examples/d/hello_lib/BUILD +++ /dev/null @@ -1,42 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load( - "//tools/build_defs/d:d.bzl", - "d_docs", - "d_library", - "d_source_library", - "d_test", -) - -d_library( - name = "greeter", - srcs = ["greeter.d"], -) - -d_test( - name = "greeter_test", - srcs = ["greeter_test.d"], - deps = [":greeter"], -) - -cc_library( - name = "native_greeter_lib", - srcs = ["native-greeter.c"], - hdrs = ["native-greeter.h"], -) - -d_source_library( - name = "native_greeter", - srcs = ["native_greeter.d"], - deps = [":native_greeter_lib"], -) - -d_docs( - name = "greeter_docs", - dep = ":greeter", -) - -d_docs( - name = "native_greeter_docs", - dep = ":native_greeter", -) diff --git a/examples/d/hello_lib/greeter.d b/examples/d/hello_lib/greeter.d deleted file mode 100644 index a0a3bf8db9..0000000000 --- a/examples/d/hello_lib/greeter.d +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2015 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. - -module greeter; - -import std.stdio; -import std.string; - -/// Displays a greeting. -class Greeter { - private string greeting; - - public: - /// Creates a new greeter. - /// - /// Params: - /// greeting = The greeting to use. - this(in string greeting) { - this.greeting = greeting.dup; - } - - /// Returns the greeting as a string. - /// - /// Params: - /// thing = The thing to greet - /// - /// Returns: - /// A greeting as a string. - string makeGreeting(in immutable string thing) { - return format("%s %s!", this.greeting, thing); - } - - /// Prints a greeting. - /// - /// Params: - /// thing = The thing to greet. - void greet(in immutable string thing) { - writeln(makeGreeting(thing)); - } -} diff --git a/examples/d/hello_lib/greeter_test.d b/examples/d/hello_lib/greeter_test.d deleted file mode 100644 index 4d927c5b01..0000000000 --- a/examples/d/hello_lib/greeter_test.d +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2015 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. - -import examples.d.hello_lib.greeter; - -unittest { - auto greeter = new Greeter("Hello"); - assert(greeter.makeGreeting("world") == "Hello world!"); -} - -void main() {} diff --git a/examples/d/hello_lib/native-greeter.c b/examples/d/hello_lib/native-greeter.c deleted file mode 100644 index 1ce489a941..0000000000 --- a/examples/d/hello_lib/native-greeter.c +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2015 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. - -#include "examples/d/hello_lib/native-greeter.h" - -#include -#include -#include - -NativeGreeter* native_greeter_new(const char* greeting) { - if (greeting == NULL) { - return NULL; - } - NativeGreeter* greeter = NULL; - greeter = (NativeGreeter*)malloc(sizeof(*greeter)); - if (greeter == NULL) { - return NULL; - } - greeter->greeting = strdup(greeting); - return greeter; -} - -void native_greeter_greet(const NativeGreeter* greeter, const char* thing) { - if (greeter == NULL || thing == NULL) { - return; - } - printf("%s %s!\n", greeter->greeting, thing); -} - -void native_greeter_free(NativeGreeter* greeter) { - if (greeter == NULL) { - return; - } - if (greeter->greeting != NULL) { - free(greeter->greeting); - } - free(greeter); -} diff --git a/examples/d/hello_lib/native-greeter.h b/examples/d/hello_lib/native-greeter.h deleted file mode 100644 index c998412c74..0000000000 --- a/examples/d/hello_lib/native-greeter.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2015 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. - -#ifndef EXAMPLES_D_HELLO_LIB_NATIVE_GREETER_H_ -#define EXAMPLES_D_HELLO_LIB_NATIVE_GREETER_H_ - -typedef struct NativeGreeter { - char* greeting; -} NativeGreeter; - -NativeGreeter* native_greeter_new(const char* greeting); - -void native_greeter_greet(const NativeGreeter* greeter, const char* thing); - -void native_greeter_free(NativeGreeter* greeter); - -#endif // EXAMPLES_D_HELLO_LIB_NATIVE_GREETER_H_ diff --git a/examples/d/hello_lib/native_greeter.d b/examples/d/hello_lib/native_greeter.d deleted file mode 100644 index 605fe21ca7..0000000000 --- a/examples/d/hello_lib/native_greeter.d +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015 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. - -module native_greeter; - -extern (C): - -struct NativeGreeter { - char* greeting; -}; - -/// Creates a new NativeGreeter. -/// -/// Params: -/// greeting = The greeting to use. -/// -/// Returns: -/// A pointer to a new NativeGreeting struct. -NativeGreeter* native_greeter_new(const(char)* greeting); - -/// Prints a greeting to stdout. -/// -/// Params: -/// greeter = The pointer to the NativeGreeter object to use. -/// thing = The thing to greet. -void native_greeter_greet(const(NativeGreeter)* greeter, const(char)* thing); - -/// Frees the NativeGreeter. -/// -/// Params: -/// greeter = The pointer to the NativeGreeter object to use. -void native_greeter_free(NativeGreeter* greeter); diff --git a/examples/d/hello_world/BUILD b/examples/d/hello_world/BUILD deleted file mode 100644 index 901f42f735..0000000000 --- a/examples/d/hello_world/BUILD +++ /dev/null @@ -1,17 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools/build_defs/d:d.bzl", "d_binary", "d_docs") - -d_binary( - name = "hello_world", - srcs = ["hello_world.d"], - deps = [ - "//examples/d/hello_lib:greeter", - "//examples/d/hello_lib:native_greeter", - ], -) - -d_docs( - name = "hello_world_docs", - dep = ":hello_world", -) diff --git a/examples/d/hello_world/hello_world.d b/examples/d/hello_world/hello_world.d deleted file mode 100644 index 8017e2442c..0000000000 --- a/examples/d/hello_world/hello_world.d +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 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. - -import std.stdio; -import examples.d.hello_lib.greeter; -import examples.d.hello_lib.native_greeter; - -void main() { - Greeter greeter = new Greeter("Hello"); - greeter.greet("World"); - - NativeGreeter* nativeGreeter = native_greeter_new("Hello"); - native_greeter_greet(nativeGreeter, "World"); - native_greeter_free(nativeGreeter); -} diff --git a/examples/dotnet/example_binary/BUILD b/examples/dotnet/example_binary/BUILD deleted file mode 100644 index 0b9263c5dc..0000000000 --- a/examples/dotnet/example_binary/BUILD +++ /dev/null @@ -1,12 +0,0 @@ -load("//tools/build_defs/dotnet:csharp.bzl", "csharp_binary") - -csharp_binary( - name = "hello", - srcs = [ - "Program.cs", - "Properties/AssemblyInfo.cs", - ], - deps = [ - "//examples/dotnet/example_lib:MyClass", - ], -) diff --git a/examples/dotnet/example_binary/Program.cs b/examples/dotnet/example_binary/Program.cs deleted file mode 100644 index 7780823347..0000000000 --- a/examples/dotnet/example_binary/Program.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using example_lib; - -namespace example_binary -{ - class MainClass - { - public static void Main(string[] args) - { - var mc = new MyClass(); - Console.WriteLine(mc.Message); - } - } -} diff --git a/examples/dotnet/example_binary/Properties/AssemblyInfo.cs b/examples/dotnet/example_binary/Properties/AssemblyInfo.cs deleted file mode 100644 index d7700ef2b3..0000000000 --- a/examples/dotnet/example_binary/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("example_binary")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("VAE Inc")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - diff --git a/examples/dotnet/example_lib/BUILD b/examples/dotnet/example_lib/BUILD deleted file mode 100644 index ad1b2b1466..0000000000 --- a/examples/dotnet/example_lib/BUILD +++ /dev/null @@ -1,13 +0,0 @@ -load("//tools/build_defs/dotnet:csharp.bzl", "csharp_library") - -csharp_library( - name = "MyClass", - srcs = [ - "MyClass.cs", - "Properties/AssemblyInfo.cs", - ], - visibility = ["//visibility:public"], - deps = [ - "//examples/dotnet/example_transitive_lib:TransitiveClass", - ], -) diff --git a/examples/dotnet/example_lib/MyClass.cs b/examples/dotnet/example_lib/MyClass.cs deleted file mode 100644 index 8ff7c18d56..0000000000 --- a/examples/dotnet/example_lib/MyClass.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Runtime.Remoting.Messaging; - -using example_transitive_lib; - -namespace example_lib -{ - public class MyClass - { - public string Message - { - get { return example_transitive_lib.TransitiveClass.Message; } - } - - public MyClass() - { - } - } -} diff --git a/examples/dotnet/example_lib/Properties/AssemblyInfo.cs b/examples/dotnet/example_lib/Properties/AssemblyInfo.cs deleted file mode 100644 index 1e8e2dd20e..0000000000 --- a/examples/dotnet/example_lib/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("example_lib")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - diff --git a/examples/dotnet/example_test/BUILD b/examples/dotnet/example_test/BUILD deleted file mode 100644 index 41613cfb21..0000000000 --- a/examples/dotnet/example_test/BUILD +++ /dev/null @@ -1,11 +0,0 @@ -load("//tools/build_defs/dotnet:csharp.bzl", "csharp_nunit_test") - -csharp_nunit_test( - name = "MyTest", - srcs = [ - "MyTest.cs", - ], - deps = [ - "//examples/dotnet/example_lib:MyClass", - ], -) diff --git a/examples/dotnet/example_test/MyTest.cs b/examples/dotnet/example_test/MyTest.cs deleted file mode 100644 index d5d5d3e5c7..0000000000 --- a/examples/dotnet/example_test/MyTest.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -using NUnit.Framework; - -using example_lib; - -namespace example_test -{ - [TestFixture] - public class MyTest - { - [Test] - public void MyTest1() - { - Assert.That("foo", Is.EqualTo("Foo")); - } - - [Test] - public void MyTest2() - { - Assert.That("bar", Is.EqualTo("bar")); - } - } -} \ No newline at end of file diff --git a/examples/dotnet/example_transitive_lib/BUILD b/examples/dotnet/example_transitive_lib/BUILD deleted file mode 100644 index b210b7ac53..0000000000 --- a/examples/dotnet/example_transitive_lib/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -load("//tools/build_defs/dotnet:csharp.bzl", "csharp_library") - -csharp_library( - name = "TransitiveClass", - srcs = [ - "Properties/AssemblyInfo.cs", - "TransitiveClass.cs", - ], - visibility = ["//visibility:public"], -) diff --git a/examples/dotnet/example_transitive_lib/Properties/AssemblyInfo.cs b/examples/dotnet/example_transitive_lib/Properties/AssemblyInfo.cs deleted file mode 100644 index ebc927a51e..0000000000 --- a/examples/dotnet/example_transitive_lib/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("example_transitive_lib")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - diff --git a/examples/dotnet/example_transitive_lib/TransitiveClass.cs b/examples/dotnet/example_transitive_lib/TransitiveClass.cs deleted file mode 100644 index 948fadb589..0000000000 --- a/examples/dotnet/example_transitive_lib/TransitiveClass.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Runtime.Remoting.Messaging; - -namespace example_transitive_lib -{ - public class TransitiveClass - { - public static string Message - { - get { return "Hello World!"; } - } - } -} - diff --git a/examples/go/bin/BUILD b/examples/go/bin/BUILD deleted file mode 100644 index ee97b92c89..0000000000 --- a/examples/go/bin/BUILD +++ /dev/null @@ -1,14 +0,0 @@ -package( - default_visibility = ["//visibility:public"], -) - -load("//tools/build_rules/go:def.bzl", "go_binary") - -go_binary( - name = "bin", - srcs = ["bin.go"], - deps = [ - "//examples/go/lib:go_default_library", - "//examples/go/vendor/github_com/user/vendored:go_default_library", - ], -) diff --git a/examples/go/bin/bin.go b/examples/go/bin/bin.go deleted file mode 100644 index b0c5917145..0000000000 --- a/examples/go/bin/bin.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import ( - "fmt" - - "github_com/user/vendored" - - "github.com/bazelbuild/bazel/examples/go/lib" -) - -func main() { - fmt.Println("meaning: ", lib.Meaning()) - fmt.Println("vendored: ", vendored.Vendored()) -} diff --git a/examples/go/lib/BUILD b/examples/go/lib/BUILD deleted file mode 100644 index 54d4d4fd94..0000000000 --- a/examples/go/lib/BUILD +++ /dev/null @@ -1,20 +0,0 @@ -package( - default_visibility = ["//visibility:public"], -) - -load("//tools/build_rules/go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "lib.go", - ], -) - -go_test( - name = "lib_test", - srcs = [ - "lib_test.go", - ], - library = ":go_default_library", -) diff --git a/examples/go/lib/lib.go b/examples/go/lib/lib.go deleted file mode 100644 index f97e3aefce..0000000000 --- a/examples/go/lib/lib.go +++ /dev/null @@ -1,6 +0,0 @@ -package lib - -// Meaning calculates the meaning of Life, the Universe and Everything. -func Meaning() int { - return 42 -} diff --git a/examples/go/lib/lib_test.go b/examples/go/lib/lib_test.go deleted file mode 100644 index e8a9f1b707..0000000000 --- a/examples/go/lib/lib_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package lib - -import ( - "testing" -) - -func TestMeaning(t *testing.T) { - if m := Meaning(); m != 42 { - t.Errorf("got %d, want 42", m) - } -} diff --git a/examples/go/vendor/github_com/user/vendored/BUILD b/examples/go/vendor/github_com/user/vendored/BUILD deleted file mode 100644 index a96b4cef95..0000000000 --- a/examples/go/vendor/github_com/user/vendored/BUILD +++ /dev/null @@ -1,12 +0,0 @@ -package( - default_visibility = ["//visibility:public"], -) - -load("//tools/build_rules/go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = [ - "vendored.go", - ], -) diff --git a/examples/go/vendor/github_com/user/vendored/vendored.go b/examples/go/vendor/github_com/user/vendored/vendored.go deleted file mode 100644 index 1e9ee6e785..0000000000 --- a/examples/go/vendor/github_com/user/vendored/vendored.go +++ /dev/null @@ -1,6 +0,0 @@ -package vendored - -// Vendored returns a string. -func Vendored() string { - return "I was vendored" -} diff --git a/examples/sass/hello_world/BUILD b/examples/sass/hello_world/BUILD deleted file mode 100644 index ad42b99244..0000000000 --- a/examples/sass/hello_world/BUILD +++ /dev/null @@ -1,13 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools/build_defs/sass:sass.bzl", "sass_binary") - -# Import our shared colors and fonts so we can generate a CSS file. -sass_binary( - name = "hello_world", - src = "main.scss", - deps = [ - "//examples/sass/shared:colors", - "//examples/sass/shared:fonts", - ], -) diff --git a/examples/sass/hello_world/main.scss b/examples/sass/hello_world/main.scss deleted file mode 100644 index 3b560b7bb6..0000000000 --- a/examples/sass/hello_world/main.scss +++ /dev/null @@ -1,13 +0,0 @@ -@import 'examples/sass/shared/fonts'; -@import 'examples/sass/shared/colors'; - -html { - body { - font-family: $default-font-stack; - - h1 { - color: $example-red; - font-family: $modern-font-stack; - } - } -} diff --git a/examples/sass/shared/BUILD b/examples/sass/shared/BUILD deleted file mode 100644 index bc3f3370d8..0000000000 --- a/examples/sass/shared/BUILD +++ /dev/null @@ -1,15 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools/build_defs/sass:sass.bzl", "sass_library") - -# make a :colors target that any sass_binary rules can depend on. -sass_library( - name = "colors", - srcs = ["_colors.scss"], -) - -# make a :fonts target that any sass_binary rules can depend on. -sass_library( - name = "fonts", - srcs = ["_fonts.scss"], -) diff --git a/examples/sass/shared/_colors.scss b/examples/sass/shared/_colors.scss deleted file mode 100644 index cd1430b0a9..0000000000 --- a/examples/sass/shared/_colors.scss +++ /dev/null @@ -1,5 +0,0 @@ -// Colors that all Sass code can share. - -$example-blue: #00f; -$example-red: #f00; -$example-green: #008000; diff --git a/examples/sass/shared/_fonts.scss b/examples/sass/shared/_fonts.scss deleted file mode 100644 index 6fea9aec8d..0000000000 --- a/examples/sass/shared/_fonts.scss +++ /dev/null @@ -1,5 +0,0 @@ -// Fonts that all Sass code can share. - -$default-font-stack: Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif; - -$modern-font-stack: Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif", "Bitstream Vera Serif", "Liberation Serif", Georgia, serif; diff --git a/site/docs/tutorial/backend-server.md b/site/docs/tutorial/backend-server.md index 542db5d923..dc99522fc5 100644 --- a/site/docs/tutorial/backend-server.md +++ b/site/docs/tutorial/backend-server.md @@ -69,128 +69,24 @@ it from that location as described in the Add the following to your `WORKSPACE` file: ```python -new_http_archive( - name = "com_google_appengine_java", - url = "http://central.maven.org/maven2/com/google/appengine/appengine-java-sdk/1.9.23/appengine-java-sdk-1.9.23.zip", - sha256 = "05e667036e9ef4f999b829fc08f8e5395b33a5a3c30afa9919213088db2b2e89", - build_file = "appengine.BUILD", +git_repository( + name = "io_bazel_rules_appengine", + remote = "https://github.com/bazelbuild/rules_appengine.git", + tag = "0.0.2", ) +load("@io_bazel_rules_appengine//appengine:appengine.bzl", "appengine_repositories") +appengine_repositories() ``` -The [`new_http_archive`](/docs/be/workspace.html#new_http_archive) rule -instructs Bazel to download a remote archive file, uncompress it and add it to -the virtual `external` package by combining the archive contents with -the referenced `BUILD` file, here `appengine.BUILD`. You'll create this file -below after you finish updating your `WORKSPACE` file. - -### Add bind rules - -You also need to add some [`bind`](/docs/be/workspace.html#bind) rules -to the file. These provide aliases to targets in the virtual `external` package -so they can be located either either inside or outside the workspace without -changing the App Engine build rules. - -Add the following to the `WORKSPACE` file: - -```python -bind( - name = "appengine/java/sdk", - actual = "@com_google_appengine_java//:sdk", -) - -bind( - name = "appengine/java/api", - actual = "@com_google_appengine_java//:api", -) - -bind( - name = "appengine/java/jars", - actual = "@com_google_appengine_java//:jars", -) -``` - -### Add maven_jar rules - -Finally, you need to add some -[`maven_jar`](/docs/be/workspace.html#maven_jar) rules to the file. These -tell Bazel to download `.jar` files from the Maven repository and allow Bazel -to use them as Java dependencies. - -Add the following to the `WORKSPACE` file: - -```python -maven_jar( - name = "org_apache_commons_lang", - artifact = "commons-lang:commons-lang:2.6", -) - -maven_jar( - name = "javax_servlet_api", - artifact = "javax.servlet:servlet-api:2.5", -) - -bind( - name = "javax/servlet/api", - actual = "//tools/build_rules/appengine:javax.servlet.api", -) - -maven_jar( - name = "json", - artifact = "org.json:json:20141113", -) -``` +[`git_repository`](/docs/be/workspace.html#git_repository) downloads the +AppEngine rules from GitHub, then the next two lines use the +`appengine_repostories` function defined in these rules to download the +libraries and SDK needed to build AppEngine applications. Now, save and close the file. You can compare your `WORKSPACE` file to the [completed example](https://github.com/bazelbuild/examples//blob/master/tutorial/WORKSPACE) in the `master` branch of the GitHub repo. -## Create the appengine.BUILD file - -When you added the `new_http_archive` to your `WORKSPACE` above, you specified -the filename `appengine.BUILD` in the `build_file` attribute. The -`appengine.BUILD` file is a special build file that allows Bazel to use the -downloaded App Engine SDK libraries as a Bazel package. Here, you'll create -this file in your top-level workspace directory. - -Open your new `appengine.BUILD` file for editing: - -```bash -$ vi $WORKSPACE/appengine.BUILD -``` - -Add the following to the file: - -```python -java_import( - name = "jars", - jars = glob(["**/*.jar"]), - visibility = ["//visibility:public"], -) - -java_import( - name = "api", - jars = ["appengine-java-sdk-1.9.23/lib/impl/appengine-api.jar"], - visibility = ["//visibility:public"], - neverlink = 1, -) - -filegroup( - name = "sdk", - srcs = glob(["appengine-java-sdk-1.9.23/**"]), - visibility = ["//visibility:public"], - path = "appengine-java-sdk-1.9.23", -) -``` - -The [`java_import`](/docs/be/java.html#java_import) rules tell -Bazel how to use the precompiled SDK `.jar` files as libraries. These rules -define the targets that you referenced in the `bind` rules in the `WORKSPACE` -file above. - -Save and close the file. The -[completed example](https://github.com/bazelbuild/examples//blob/master/tutorial/appengine.BUILD) -is in the `master` branch of the GitHub repo. - ## Create a BUILD file Now that you have set up the external dependencies, you can go ahead and create @@ -232,7 +128,7 @@ for the `main_class` attribute. Add the following to your `BUILD` file: ```python -load("@bazel_tools//tools/build_rules/appengine:appengine.bzl", "appengine_war") +load("@io_bazel_rules_appengine//appengine:appengine.bzl", "appengine_war") appengine_war( name = "backend", diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index bb19c0778c..125699a762 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -84,19 +84,6 @@ sh_test( data = [":test-deps"], ) -sh_test( - name = "bazel_go_example_test", - srcs = ["bazel_go_example_test.sh"], - data = [ - ":test-deps", - "//tools/build_rules/go:srcs", - "//tools/build_rules/go/toolchain", - "//tools/build_rules/go/toolchain:go_tool", - "//tools/build_rules/go/toolchain:srcs", - "//tools/build_rules/go/tools:srcs", - ], -) - sh_test( name = "bazel_rules_test", size = "large", diff --git a/src/test/shell/bazel/bazel_go_example_test.sh b/src/test/shell/bazel/bazel_go_example_test.sh deleted file mode 100755 index f4dd395321..0000000000 --- a/src/test/shell/bazel/bazel_go_example_test.sh +++ /dev/null @@ -1,283 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 The Bazel Authors. All arights 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. -# -# Tests the examples provided in Bazel -# - -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } - -function setup_go() { - copy_examples - - GO_REPO=$PWD/tools/build_rules/go/toolchain - - cat < WORKSPACE -new_local_repository( - name = "bazel_tools", - path = __workspace_dir__, - build_file = __workspace_dir__ + "/BUILD", -) -new_local_repository( - name = "golang_linux_amd64", - path = "$GO_REPO", - build_file = "$GO_REPO/BUILD" -) -new_local_repository( - name = "golang_darwin_amd64", - path = "$GO_REPO", - build_file = "$GO_REPO/BUILD" -) -EOF - - # avoid trying to download the SDK from within the test. - rm -rf tools/build_rules/go/toolchain - for p in golang_linux_amd64 golang_darwin_amd64 ; do - d=$TEST_SRCDIR/external/${p} - if [[ -d "${d}" ]]; then - for f in $(cd ${d}; find -L . -type f -print ) ; do - mkdir -p tools/build_rules/go/toolchain/$(dirname $f) - ln -s ${d}/$f tools/build_rules/go/toolchain/$f - done - fi - done - cat <<'EOF' >tools/build_rules/go/toolchain/BUILD -package( - default_visibility = [ "//visibility:public" ]) - -filegroup( - name = "toolchain", - srcs = glob(["go/bin/*", "go/pkg/**", ]), -) - -filegroup( - name = "go_tool", - srcs = [ "go/bin/go" ], -) -EOF - cat < BUILD -load("/tools/build_rules/go/def", "go_prefix") -go_prefix("prefix") -EOF - -} - -function test_basic() { - setup_go - mkdir -p ex/ - cat < ex/m.go -package main -import ( - "fmt" - - "prefix/ex" -) -func main() { - fmt.Println("F", ex.F()) -} - -EOF - cat < ex/l.go -package ex -func F() int { return 42 } -EOF - - cat < ex/BUILD -load("/tools/build_rules/go/def", "go_library", "go_binary") -go_library(name = "go_default_library", - srcs = [ "l.go"]) -go_binary(name = "m", - srcs = [ "m.go" ], - deps = [ ":go_default_library" ]) -EOF - - assert_build //ex:m - test -x ./bazel-bin/ex/m || fail "binary not found" - (./bazel-bin/ex/m > out) || fail "binary does not execute" - grep "F 42" out || fail "binary output suspect" -} - -function test_runfiles() { - setup_go - mkdir -p ex/ - -# Note this binary is also a test (for the correct handling of runfiles by -# Bazel's go_binary rule). - cat < ex/rf.go -package main -import ( - "fmt" - "log" - "io/ioutil" -) - -func main() { - rfcontent, err := ioutil.ReadFile("ex/runfile") - if err != nil { - log.Fatalf("Runfiles test binary: Error reading from runfile: %v", err) - } - - fmt.Printf("Runfile: %s\n", rfcontent) -} - -EOF - - cat < ex/rf_test.go -package main -import ( - "fmt" - "io/ioutil" - "testing" -) - -func TestRunfiles(t *testing.T) { - rfcontent, err := ioutil.ReadFile("runfile") - if err != nil { - t.Errorf("TestRunfiles: Error reading from runfile: %v", err) - } - - if string(rfcontent) != "12345\n" { - t.Errorf("TestRunfiles: Read incorrect value from runfile: %s", rfcontent) - } - - fmt.Printf("Runfile: %s\n", rfcontent) -} -EOF - - cat < ex/runfile -12345 -EOF - - cat < ex/BUILD -load("/tools/build_rules/go/def", "go_binary", "go_test") -go_binary(name = "runfiles_bin", - srcs = [ "rf.go" ], - data = [ "runfile" ]) -go_test(name = "runfiles_test", - srcs = [ "rf_test.go" ], - data = [ "runfile" ]) -EOF - - assert_build //ex:runfiles_bin - test -x ./bazel-bin/ex/runfiles_bin || fail "binary not found" - (./bazel-bin/ex/runfiles_bin > out) || fail "binary does not execute" - grep "Runfile: 12345" out || fail "binary output suspect" - - assert_build //ex:runfiles_test - test -x ./bazel-bin/ex/runfiles_test || fail "binary not found" - (./bazel-bin/ex/runfiles_test > out) || fail "binary does not execute" - grep "Runfile: 12345" out || fail "binary output suspect" -} - -function test_runfiles_lib() { - setup_go - mkdir -p ex/ - cat < ex/m.go -package main -import ( - "fmt" - "io/ioutil" - "log" - - "prefix/ex" -) -func main() { - rfcontent, err := ioutil.ReadFile(ex.RunfilePath()) - if err != nil { - log.Fatalf("Runfiles test binary: Error reading from runfile: %v", err) - } - - fmt.Printf("Runfile: %s\n", rfcontent) -} - -EOF - - cat < ex/l.go -package ex -func RunfilePath() string { return "ex/runfile" } -EOF - - cat < ex/runfile -12345 -EOF - - cat < ex/BUILD -load("/tools/build_rules/go/def", "go_library", "go_binary") -go_library(name = "go_default_library", - data = [ "runfile" ], - srcs = [ "l.go"]) -go_binary(name = "m", - srcs = [ "m.go" ], - deps = [ ":go_default_library" ]) -EOF - - assert_build //ex:m - test -x ./bazel-bin/ex/m || fail "binary not found" - (./bazel-bin/ex/m > out) || fail "binary does not execute" - grep "Runfile: 12345" out || fail "binary output suspect" -} - - -function test_empty_prefix() { - setup_go - - cat < BUILD -load("/tools/build_rules/go/def", "go_prefix") -go_prefix("") -EOF - - rm -rf ex - mkdir -p ex/ - cat < ex/m.go -package main -import ( - "fmt" - - "library" -) -func main() { - fmt.Println(library.F()) -} -EOF - cat < ex/BUILD -load("/tools/build_rules/go/def", "go_library", "go_binary") -go_binary(name = "m", - srcs = [ "m.go" ], - deps = [ "//library:go_default_library" ]) -EOF - - mkdir -p library - - cat < library/BUILD -package(default_visibility=["//visibility:public"]) -load("/tools/build_rules/go/def", "go_library", "go_binary") -go_library(name = "go_default_library", - srcs = [ "l.go"]) -EOF - - cat < library/l.go -package library -func F() int { return 42 } -EOF - - assert_build //ex:m - test -x ./bazel-bin/ex/m || fail "binary not found" - (./bazel-bin/ex/m > out) || fail "binary does not execute" - grep "42" out || fail "binary output suspect" -} - -run_suite "go_examples" diff --git a/tools/BUILD b/tools/BUILD index afe860031b..fa60b669d4 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -10,17 +10,12 @@ filegroup( "//tools/android:srcs", "//tools/android/jack:srcs", "//tools/buildstamp:srcs", - "//tools/build_defs/d:srcs", "//tools/build_defs/docker:srcs", - "//tools/build_defs/dotnet:srcs", "//tools/build_defs/jsonnet:srcs", "//tools/build_defs/pkg:srcs", - "//tools/build_defs/sass:srcs", "//tools/build_defs/scala:srcs", "//tools/build_rules:srcs", - "//tools/build_rules/appengine:srcs", "//tools/build_rules/closure:srcs", - "//tools/build_rules/go:srcs", "//tools/build_rules/rust:srcs", "//tools/jdk:srcs", "//tools/genrule:srcs", @@ -39,14 +34,10 @@ filegroup( srcs = glob(["**"]) + [ "//tools/android/jack:srcs", "//tools/android:srcs", - "//tools/build_defs/d:srcs", "//tools/build_defs/docker:srcs", "//tools/build_defs/jsonnet:srcs", "//tools/build_defs/pkg:srcs", - "//tools/build_defs/sass:srcs", - "//tools/build_rules/appengine:srcs", "//tools/build_rules/closure:srcs", - "//tools/build_rules/go:srcs", "//tools/build_rules/rust:srcs", "//tools/build_rules:srcs", "//tools/buildstamp:srcs", diff --git a/tools/build_defs/d/BUILD b/tools/build_defs/d/BUILD deleted file mode 100644 index 2801e32762..0000000000 --- a/tools/build_defs/d/BUILD +++ /dev/null @@ -1,48 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "srcs", - srcs = glob(["**"]), -) - -config_setting( - name = "darwin", - values = {"host_cpu": "darwin"}, -) - -config_setting( - name = "k8", - values = {"host_cpu": "k8"}, -) - -filegroup( - name = "dmd", - srcs = select({ - ":darwin": ["@dmd_darwin_x86_64//:dmd"], - ":k8": ["@dmd_linux_x86_64//:dmd"], - }), -) - -filegroup( - name = "libphobos2", - srcs = select({ - ":darwin": ["@dmd_darwin_x86_64//:libphobos2"], - ":k8": ["@dmd_linux_x86_64//:libphobos2"], - }), -) - -filegroup( - name = "phobos-src", - srcs = select({ - ":darwin": ["@dmd_darwin_x86_64//:phobos-src"], - ":k8": ["@dmd_linux_x86_64//:phobos-src"], - }), -) - -filegroup( - name = "druntime-import-src", - srcs = select({ - ":darwin": ["@dmd_darwin_x86_64//:druntime-import-src"], - ":k8": ["@dmd_linux_x86_64//:druntime-import-src"], - }), -) diff --git a/tools/build_defs/d/README.md b/tools/build_defs/d/README.md deleted file mode 100644 index a099cc1665..0000000000 --- a/tools/build_defs/d/README.md +++ /dev/null @@ -1,678 +0,0 @@ -# D rules - -## Rules - - - -## Setup - -To use the D rules, add the following to your `WORKSPACE` file to add the -external repositories for the D toolchain: - -```python -load("@bazel_tools//tools/build_defs/d:d.bzl", "d_repositories") - -d_repositories() -``` - -## Roadmap - -* Generate documentation using [`ddox`](https://github.com/rejectedsoftware/ddox) - for `d_docs` rule. -* Support for other options as defined in the [Dub package - format](http://code.dlang.org/package-format?lang=json) -* Support for specifying different configurations of a library, closer to - [Dub's model for configurations](http://code.dlang.org/package-format?lang=json#configurations) -* Workspace rule for retrieving dependencies from [Dub](http://code.dlang.org/) - - -## d_library - -```python -d_library(name, srcs, deps, includes, linkopts, versions) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-

- This name will be used as the name of the library built by this rule. -

-
srcs - List of labels, required -

List of D .d source files used to build the library.

-
deps - List of labels, optional -

List of libraries to be linked to this library target.

-

- These can either be other d_library targets, - source-only d_source_library targets, or - cc_library targets if linking a native library. -

-
imports - List of strings, optional -

List of import dirs to add to the compile line.

-

- These will be passed to the D compiler via -I flags. -

-
linkopts - List of strings, optional -

List of flags that are added to the D linker command.

-

- These will be passed to the D compiler via -L flags. -

-
versions - List of strings, optional -

List of versions to be defined during compilation.

-

- Versions are used for conditional compilation and are enabled in the - code using version condition blocks. These versions - listed here will be passed to the D compiler using - -version flags. -

-
- -### Example - -Suppose you have the following directory structure for a D project: - -``` -[workspace]/ - WORKSPACE - foo/ - BUILD - foo.d - bar.d - baz.d -``` - -The library `foo` is built using a `d_library` target: - -`foo/BUILD`: - -```python -load("@bazel_tools//tools/build_defs/d/d", "d_library") - -d_binary( - name = "foo", - srcs = [ - "foo.d", - "bar.d", - "baz.d", - ], -) -``` - - -## d_source_library - -```python -d_source_library(name, srcs, deps, includes, linkopts, versions) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
srcs - List of labels, required -

- List of D .d source files that comprises this source - library target. -

-
deps - List of labels, optional -

List of library targets depended on by this target.

-

- These can either be other d_source_library targets or - cc_library targets, such as when this source library - target implements the D interface for a native library. Any native - libraries will be linked by d_library targets that - depend on this target. -

-
imports - List of strings, optional -

List of import dirs to add to the compile line.

-

- These will be passed to the D compiler via -I flags for - any d_library targets that depend on this target. -

-
linkopts - List of strings, optional -

List of flags that are added to the D linker command.

-

- These will be passed to the D compiler via -L flags for - any d_library targets that depend on this target. -

-
versions - List of strings, optional -

List of version flags to be defined during compilation.

-

- Versions are used for conditional compilation and are enabled in the - code using version condition blocks. These versions - listed here will be passed to the D compiler using - -version flags for any d_library targets - that depend on this target. -

-
- -### Example - -Suppose you have the following directory structure for a project building a -C library and a [D interface](http://dlang.org/interfaceToC.html) for the C -library: - -``` -[workspace]/ - WORKSPACE - greeter/ - BUILD - native_greeter.c - native_greeter.h - native_greeter.d - hello_world - BUILD - hello_world.d -``` - -Build the C library using the `cc_library` rule and then use the -`d_source_library` to define the target for the D interface for the C -`native_greeter` library: - -`greeter/BUILD`: - -```python -load("@bazel_tools//tools/build_defs/d/d", "d_source_library") - -cc_library( - name = "native_greeter_lib", - srcs = ["native_greeter.c"], - hdrs = ["native_greeter.h"], -) - -d_source_library( - name = "native_greeter", - srcs = ["native_greeter.d"], - deps = [":native_greeter_lib"], -) -``` - -Other targets can directly depend on the `d_source_library` target to link -the C library: - -`hello_world/BUILD`: - -```python -load("@bazel_tools//tools/build_defs/d/d", "d_source_library") - -d_binary( - name = "hello_world", - srcs = ["hello_world.d"], - deps = ["//greeter:native_greeter"], -) -``` - - -## d_binary - -```python -d_binary(name, srcs, deps, includes, linkopts, versions) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-

- This name will be used as the name of the binary built by this rule. -

-
srcs - List of labels, required -

List of D .d source files used to build the binary.

-
deps - List of labels, optional -

List of libraries to be linked to this binary target.

-

- These can either be other d_library targets, - source-only d_source_library targets, or - cc_library targets if linking a native library. -

-
imports - List of strings, optional -

List of import dirs to add to the compile line.

-

- These will be passed to the D compiler via -I flags. -

-
linkopts - List of strings, optional -

List of flags that are added to the D linker command.

-

- These will be passed to the D compiler via -L flags. -

-
versions - List of strings, optional -

List of versions to be defined during compilation.

-

- Versions are used for conditional compilation and are enabled in the - code using version condition blocks. These versions - listed here will be passed to the D compiler using - -version flags. -

-
- -Suppose you have the following directory structure for a D project: - -``` -[workspace]/ - WORKSPACE - hello_lib/ - BUILD - greeter.d - hello_world - BUILD - hello_world.d -``` - -The source file `hello_lib/greeter.d` defines a module `greeter`: - -```d -module greeter; -... -``` - -The `hello_lib` library is built using a `d_library` target: - -`hello_lib/BUILD`: - -```python -load("@bazel_tools//tools/build_defs/d/d", "d_library") - -d_library( - name = "hello_lib", - srcs = ["greeter.d"], -) -``` - -By default, import paths are from the root of the workspace. Thus, the source -for the `hello_world` binary, `hello_world.d`, would import the `greeter` -module as follows: - -```d -import hello_lib.greeter; -``` - -However, this can be changed via the `imports` attribute on the `d_library` -rule. - -The `hello_world` binary is built using a `d_binary` target: - -`hello_world/BUILD`: - -```python -load("@bazel_tools//tools/build_defs/d/d", "d_library") - -d_binary( - name = "hello_world", - srcs = ["hello_world.d"], - deps = ["//hello_lib"], -) -``` - - -## d_test - -```python -d_test(name, srcs, deps, includes, linkopts, versions) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-

- This name will be used as the name of the test built by this rule. -

-
srcs - List of labels, required -

List of D .d source files used to build the test.

-
deps - List of labels, optional -

List of libraries to be linked to this test target.

-

- These can either be other d_library targets, - source-only d_source_library targets, or - cc_library targets if linking a native library. -

-
imports - List of strings, optional -

List of import dirs to add to the compile line.

-

- These will be passed to the D compiler via -I flags. -

-
linkopts - List of strings, optional -

List of flags that are added to the D linker command.

-

- These will be passed to the D compiler via -L flags. -

-
versions - List of strings, optional -

List of versions to be defined during compilation.

-

- Versions are used for conditional compilation and are enabled in the - code using version condition blocks. These versions - listed here will be passed to the D compiler using - -version flags. -

-
- -### Example - -Suppose you have the following directory structure for a D project: - -``` -[workspace]/ - WORKSPACE - hello_lib/ - BUILD - greeter.d - greeter_test.d -``` - -`hello_lib/greeter.d`: - -```d -module greeter; - -import std.stdio; -import std.string; - -class Greeter { - private string greeting; - - public: - this(in string greeting) { - this.greeting = greeting.dup; - } - - string makeGreeting(in immutable string thing) { - return format("%s %s!", this.greeting, thing); - } - - void greet(in immutable string thing) { - writeln(makeGreeting(thing)); - } -} -``` - -`hello_lib/greeter_test.d`: - -```d -import hello_lib.greeter; - -unittest { - auto greeter = new Greeter("Hello"); - assert(greeter.makeGreeting("world") == "Hello world!"); -} - -void main() {} -``` - -To build the library and unit test: - -`hello_lib/BUILD`: - -```python -load("@bazel_tools//tools/build_defs/d/d", "d_library", "d_test") - -d_library( - name = "greeter", - srcs = ["greeter.d"], -) - -d_test( - name = "greeter_test", - srcs = ["greeter_test.d"], - deps = [":greeter"], -) -``` - -The unit test can then be run using: - -```sh -bazel test //hello_lib:greeter_test -``` - - -## d_docs - -```python -d_docs(name, dep) -``` - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
dep - Label, required -

The label of the target to generate code documentation for.

-

- d_docs can generate HTML code documentation for the - source files of d_library, d_source_library, - d_binary, or d_test targets. -

-
- -### Example - -Suppose you have the following directory structure for a D project: - -``` -[workspace]/ - WORKSPACE - foo/ - BUILD - foo.d - bar.d - baz.d -``` - -The `foo/` directory contains the sources for the `d_library` `foo`. To -generate HTML documentation for the `foo` library, define a `d_docs` target -that takes the `d_library` `foo` as its dependency: - -`foo/BUILD`: - -```python -load("@bazel_tools//tools/build_defs/d/d", "d_library", "d_docs") - -d_library( - name = "foo", - srcs = [ - "foo.d", - "bar.d", - "baz.d", - ], -) - -d_docs( - name = "foo_docs", - dep = ":foo", -) -``` - -Running `bazel build //foo:foo_docs` will generate a zip file containing the -HTML documentation generated from the source files. See the official D language -documentation on the [Documentation Generator](http://dlang.org/ddoc.html) for -more information on the conventions for source documentation. diff --git a/tools/build_defs/d/d.bzl b/tools/build_defs/d/d.bzl deleted file mode 100644 index 9e8164a0fe..0000000000 --- a/tools/build_defs/d/d.bzl +++ /dev/null @@ -1,534 +0,0 @@ -# Copyright 2015 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. - -"""D rules for Bazel.""" - -load("//tools/build_rules:deprecation.bzl", "deprecated") - -def warning(rule): - print(deprecated( - "d", - rule, - "@bazel_tools//tools/build_defs/d:d.bzl", - "@io_bazel_rules_d//d:d.bzl")) - -A_FILETYPE = FileType([".a"]) - -D_FILETYPE = FileType([ - ".d", - ".di", -]) - -ZIP_PATH = "/usr/bin/zip" - -def _relative(src_path, dest_path): - """Returns the relative path from src_path to dest_path.""" - src_parts = src_path.split("/") - dest_parts = dest_path.split("/") - n = 0 - for src_part, dest_part in zip(src_parts, dest_parts): - if src_part != dest_part: - break - n += 1 - - relative_path = "" - for _ in range(n, len(src_parts)): - relative_path += "../" - relative_path += "/".join(dest_parts[n:]) - - return relative_path - -def _create_setup_cmd(lib, deps_dir): - """Constructs a command for symlinking a library into the deps directory.""" - return ( - "ln -sf " + _relative(deps_dir, lib.path) + " " + - deps_dir + "/" + lib.basename + "\n" - ) - -def _d_toolchain(ctx): - """Returns a struct containing info about the D toolchain. - - Args: - ctx: The ctx object. - - Return: - Struct containing the following fields: - d_compiler_path: The path to the D compiler. - link_flags: Linker (-L) flags for adding the standard library to the - library search paths. - import_flags: import (-L) flags for adding the standard library sources - to the import paths. - """ - - d_compiler_path = ctx.file._d_compiler.path - return struct( - d_compiler_path = d_compiler_path, - link_flags = ["-L-L" + ctx.files._d_stdlib[0].dirname], - import_flags = [ - "-I" + ctx.files._d_stdlib_src[0].dirname, - "-I" + ctx.files._d_runtime_import_src[0].dirname]) - -def _format_version(name): - """Formats the string name to be used in a --version flag.""" - return name.replace("-", "_") - -def _build_compile_command(ctx, srcs, out, depinfo, extra_flags=[]): - """Returns a string containing the D compile command.""" - toolchain = _d_toolchain(ctx) - cmd = ( - ["set -e;"] + - depinfo.setup_cmd + - [toolchain.d_compiler_path] + - extra_flags + [ - "-of" + out.path, - "-I.", - "-debug", - "-w", - "-g", - ] + - ["-I%s/%s" % (ctx.label.package, im) for im in ctx.attr.imports] + - ["-I%s" % im for im in depinfo.imports] + - toolchain.import_flags + - ["-version=Have_%s" % _format_version(ctx.label.name)] + - ["-version=%s" % v for v in ctx.attr.versions] + - ["-version=%s" % v for v in depinfo.versions] + - srcs) - return " ".join(cmd) - -def _build_link_command(ctx, objs, out, depinfo): - """Returns a string containing the D link command.""" - toolchain = _d_toolchain(ctx) - cmd = ( - ["set -e;"] + - depinfo.setup_cmd + - [toolchain.d_compiler_path] + - ["-of" + out.path] + - toolchain.link_flags + - depinfo.lib_flags + - depinfo.link_flags + - objs) - return " ".join(cmd) - -def _setup_deps(deps, name, working_dir): - """Sets up dependencies. - - Walks through dependencies and constructs the commands and flags needed - for linking the necessary dependencies. - - Args: - deps: List of deps labels from ctx.attr.deps. - name: Name of the current target. - working_dir: The output directory of the current target's output. - - Returns: - Returns a struct containing the following fields: - libs: List of Files containing the target's direct library dependencies. - transitive_libs: List of Files containing all of the target's - transitive libraries. - d_srcs: List of Files representing D source files of dependencies that - will be used as inputs for this target. - versions: List of D versions to be used for compiling the target. - setup_cmd: String containing the symlink commands to be used to set - up the dependencies. - imports: List of Strings containing input paths that will be passed - to the D compiler via -I flags. - link_flags: List of linker flags. - lib_flags: List of library search flags. - """ - deps_dir = working_dir + "/" + name + ".deps" - setup_cmd = ["rm -rf " + deps_dir + ";" + "mkdir -p " + deps_dir + ";"] - - libs = set() - transitive_libs = set() - d_srcs = set() - transitive_d_srcs = set() - versions = set() - imports = set() - link_flags = set() - symlinked_libs = set() - for dep in deps: - if hasattr(dep, "d_lib"): - # The dependency is a d_library. - libs += [dep.d_lib] - transitive_libs += dep.transitive_libs - symlinked_libs += [dep.d_lib] + dep.transitive_libs - d_srcs += dep.d_srcs - transitive_d_srcs += dep.transitive_d_srcs - versions += dep.versions + ["Have_%s" % _format_version(dep.label.name)] - link_flags += ["-L-l%s" % dep.label.name] + dep.link_flags - imports += ["%s/%s" % (dep.label.package, im) for im in dep.imports] - - elif hasattr(dep, "d_srcs"): - # The dependency is a d_source_library. - d_srcs += dep.d_srcs - transitive_d_srcs += dep.transitive_d_srcs - transitive_libs += dep.transitive_libs - symlinked_libs += dep.transitive_libs - link_flags += ["-L%s" % linkopt for linkopt in dep.linkopts] - imports += ["%s/%s" % (dep.label.package, im) for im in dep.imports] - versions += dep.versions - - elif hasattr(dep, "cc"): - # The dependency is a cc_library - native_libs = A_FILETYPE.filter(dep.cc.libs) - libs += native_libs - transitive_libs += native_libs - symlinked_libs += native_libs - link_flags += ["-L-l%s" % dep.label.name] - - else: - fail("D targets can only depend on d_library, d_source_library, or " + - "cc_library targets.", "deps") - - for symlinked_libs in symlinked_libs: - setup_cmd += [_create_setup_cmd(symlinked_libs, deps_dir)] - - return struct( - libs = list(libs), - transitive_libs = list(transitive_libs), - d_srcs = list(d_srcs), - transitive_d_srcs = list(transitive_d_srcs), - versions = versions, - setup_cmd = setup_cmd, - imports = list(imports), - link_flags = list(link_flags), - lib_flags = ["-L-L%s" % deps_dir]) - -def _d_library_impl(ctx): - """Implementation of the d_library rule.""" - warning("d_library") - d_lib = ctx.outputs.d_lib - - # Dependencies - depinfo = _setup_deps(ctx.attr.deps, ctx.label.name, d_lib.dirname) - - # Build compile command. - cmd = _build_compile_command( - ctx = ctx, - srcs = [src.path for src in ctx.files.srcs], - out = d_lib, - depinfo = depinfo, - extra_flags = ["-lib"]) - - compile_inputs = ( - ctx.files.srcs + - depinfo.d_srcs + - depinfo.transitive_d_srcs + - depinfo.libs + - depinfo.transitive_libs + - [ctx.file._d_compiler] + - ctx.files._d_stdlib + - ctx.files._d_stdlib_src + - ctx.files._d_runtime_import_src) - - ctx.action(inputs = compile_inputs, - outputs = [d_lib], - mnemonic = "Dcompile", - command = cmd, - use_default_shell_env = True, - progress_message = "Compiling D library " + ctx.label.name) - - return struct(files = set([d_lib]), - d_srcs = ctx.files.srcs, - transitive_d_srcs = depinfo.d_srcs, - transitive_libs = depinfo.transitive_libs, - link_flags = depinfo.link_flags, - versions = ctx.attr.versions, - imports = ctx.attr.imports, - d_lib = d_lib) - -def _d_binary_impl_common(ctx, extra_flags=[]): - """Common implementation for rules that build a D binary.""" - d_bin = ctx.outputs.executable - d_obj = ctx.new_file(ctx.configuration.bin_dir, - d_bin.basename + ".o") - depinfo = _setup_deps(ctx.attr.deps, ctx.label.name, d_bin.dirname) - - # Build compile command - compile_cmd = _build_compile_command( - ctx = ctx, - srcs = [src.path for src in ctx.files.srcs], - depinfo = depinfo, - out = d_obj, - extra_flags = ["-c"] + extra_flags) - - toolchain_files = ( - [ctx.file._d_compiler] + - ctx.files._d_stdlib + - ctx.files._d_stdlib_src + - ctx.files._d_runtime_import_src) - - compile_inputs = (ctx.files.srcs + - depinfo.d_srcs + - depinfo.transitive_d_srcs + - toolchain_files) - ctx.action(inputs = compile_inputs, - outputs = [d_obj], - mnemonic = "Dcompile", - command = compile_cmd, - use_default_shell_env = True, - progress_message = "Compiling D binary " + ctx.label.name) - - # Build link command - link_cmd = _build_link_command( - ctx = ctx, - objs = [d_obj.path], - depinfo = depinfo, - out = d_bin) - - link_inputs = ( - [d_obj] + - depinfo.libs + - depinfo.transitive_libs + - toolchain_files) - - ctx.action(inputs = link_inputs, - outputs = [d_bin], - mnemonic = "Dlink", - command = link_cmd, - use_default_shell_env = True, - progress_message = "Linking D binary " + ctx.label.name) - - return struct(d_srcs = ctx.files.srcs, - transitive_d_srcs = depinfo.d_srcs, - imports = ctx.attr.imports) - -def _d_binary_impl(ctx): - """Implementation of the d_binary rule.""" - warning("d_binary") - return _d_binary_impl_common(ctx) - -def _d_test_impl(ctx): - """Implementation of the d_test rule.""" - warning("d_test") - return _d_binary_impl_common(ctx, extra_flags=["-unittest"]) - -def _d_source_library_impl(ctx): - """Implementation of the d_source_library rule.""" - warning("d_library") - transitive_d_srcs = set(order="compile") - transitive_libs = set() - transitive_imports = set() - transitive_linkopts = set() - transitive_versions = set() - for dep in ctx.attr.deps: - if hasattr(dep, "d_srcs"): - # Dependency is another d_source_library target. - transitive_d_srcs += dep.d_srcs - transitive_imports += dep.imports - transitive_linkopts += dep.linkopts - transitive_versions += dep.versions - - elif hasattr(dep, "cc"): - # Dependency is a cc_library target. - native_libs = A_FILETYPE.filter(dep.cc.libs) - transitive_libs += native_libs - transitive_linkopts += ["-l%s" % dep.label.name] - - else: - fail("d_source_library can only depend on other " + - "d_source_library or cc_library targets.", "deps") - - return struct( - d_srcs = ctx.files.srcs, - transitive_d_srcs = list(transitive_d_srcs), - transitive_libs = transitive_libs, - imports = ctx.attr.imports + list(transitive_imports), - linkopts = ctx.attr.linkopts + list(transitive_linkopts), - versions = ctx.attr.versions + list(transitive_versions)) - -# TODO(dzc): Use ddox for generating HTML documentation. -def _d_docs_impl(ctx): - """Implementation for the d_docs rule - - This rule runs the following steps to generate an archive containing - HTML documentation generated from doc comments in D source code: - 1. Run the D compiler with the -D flags to generate HTML code - documentation. - 2. Create a ZIP archive containing the HTML documentation. - """ - warning("d_docs") - d_docs_zip = ctx.outputs.d_docs - docs_dir = d_docs_zip.dirname + "/_d_docs" - objs_dir = d_docs_zip.dirname + "/_d_objs" - - target = struct(name = ctx.attr.dep.label.name, - srcs = ctx.attr.dep.d_srcs, - transitive_srcs = ctx.attr.dep.transitive_d_srcs, - imports = ctx.attr.dep.imports) - - # Build D docs command - toolchain = _d_toolchain(ctx) - doc_cmd = ( - [ - "set -e;", - "rm -rf %s; mkdir %s;" % (docs_dir, docs_dir), - "rm -rf %s; mkdir %s;" % (objs_dir, objs_dir), - toolchain.d_compiler_path, - "-c", - "-D", - "-Dd%s" % docs_dir, - "-od%s" % objs_dir, - "-I.", - ] + - ["-I%s/%s" % (ctx.label.package, im) for im in target.imports] + - toolchain.import_flags + - [src.path for src in target.srcs] + - [ - "&&", - "(cd %s &&" % docs_dir, - ZIP_PATH, - "-qR", - d_docs_zip.basename, - "$(find . -type f) ) &&", - "mv %s/%s %s" % (docs_dir, d_docs_zip.basename, d_docs_zip.path) - ]) - - toolchain_files = ( - [ctx.file._d_compiler] + - ctx.files._d_stdlib + - ctx.files._d_stdlib_src + - ctx.files._d_runtime_import_src) - ddoc_inputs = target.srcs + target.transitive_srcs + toolchain_files - ctx.action(inputs = ddoc_inputs, - outputs = [d_docs_zip], - mnemonic = "Ddoc", - command = " ".join(doc_cmd), - use_default_shell_env = True, - progress_message = "Generating D docs for " + ctx.label.name) - -_d_common_attrs = { - "srcs": attr.label_list(allow_files = D_FILETYPE), - "deps": attr.label_list(), - "imports": attr.string_list(), - "linkopts": attr.string_list(), - "versions": attr.string_list(), -} - -_d_compile_attrs = { - "_d_compiler": attr.label( - default = Label("@bazel_tools//tools/build_defs/d:dmd"), - executable = True, - single_file = True, - ), - "_d_stdlib": attr.label( - default = Label("@bazel_tools//tools/build_defs/d:libphobos2"), - ), - "_d_stdlib_src": attr.label( - default = Label("@bazel_tools//tools/build_defs/d:phobos-src"), - ), - "_d_runtime_import_src": attr.label( - default = Label("@bazel_tools//tools/build_defs/d:druntime-import-src"), - ), -} - -d_library = rule( - _d_library_impl, - attrs = _d_common_attrs + _d_compile_attrs, - outputs = { - "d_lib": "lib%{name}.a", - }, -) - -d_source_library = rule( - _d_source_library_impl, - attrs = _d_common_attrs, -) - -d_binary = rule( - _d_binary_impl, - attrs = _d_common_attrs + _d_compile_attrs, - executable = True, -) - -d_test = rule( - _d_test_impl, - attrs = _d_common_attrs + _d_compile_attrs, - executable = True, - test = True, -) - -_d_docs_attrs = { - "dep": attr.label(mandatory = True), -} - -d_docs = rule( - _d_docs_impl, - attrs = _d_docs_attrs + _d_compile_attrs, - outputs = { - "d_docs": "%{name}-docs.zip", - }, -) - -DMD_BUILD_FILE = """ -package(default_visibility = ["//visibility:public"]) - -config_setting( - name = "darwin", - values = {"host_cpu": "darwin"}, -) - -config_setting( - name = "k8", - values = {"host_cpu": "k8"}, -) - -filegroup( - name = "dmd", - srcs = select({ - ":darwin": ["dmd2/osx/bin/dmd"], - ":k8": ["dmd2/linux/bin64/dmd"], - }), -) - -filegroup( - name = "libphobos2", - srcs = select({ - ":darwin": ["dmd2/osx/lib/libphobos2.a"], - ":k8": [ - "dmd2/linux/lib64/libphobos2.a", - "dmd2/linux/lib64/libphobos2.so", - ], - }), -) - -filegroup( - name = "phobos-src", - srcs = glob(["dmd2/src/phobos/**/*.*"]), -) - -filegroup( - name = "druntime-import-src", - srcs = glob([ - "dmd2/src/druntime/import/*.*", - "dmd2/src/druntime/import/**/*.*", - ]), -) -""" - -def d_repositories(): - warning("d_repositories") - native.new_http_archive( - name = "dmd_linux_x86_64", - url = "http://downloads.dlang.org/releases/2.x/2.070.0/dmd.2.070.0.linux.tar.xz", - sha256 = "42f48db8716f523076e881151f631e741342012881ec9b57353544ed46c4f774", - build_file_content = DMD_BUILD_FILE, - ) - - native.new_http_archive( - name = "dmd_darwin_x86_64", - url = "http://downloads.dlang.org/releases/2.x/2.070.0/dmd.2.070.0.osx.tar.xz", - sha256 = "c1dd14ded8e099dcb2f136379013959b07790249f440010d556e67ff59fe44a0", - build_file_content = DMD_BUILD_FILE, - ) diff --git a/tools/build_defs/dotnet/BUILD b/tools/build_defs/dotnet/BUILD deleted file mode 100644 index 2e566326ab..0000000000 --- a/tools/build_defs/dotnet/BUILD +++ /dev/null @@ -1,23 +0,0 @@ -# Detect our platform, -# mac os x -config_setting( - name = "darwin", - values = {"host_cpu": "darwin"}, -) - -# linux amd64 -config_setting( - name = "linux", - values = {"host_cpu": "k8"}, -) - -config_setting( - name = "debug", - values = {"compilation_mode": "dbg"}, -) - -filegroup( - name = "srcs", - srcs = glob(["**"]), - visibility = ["//tools:__pkg__"], -) diff --git a/tools/build_defs/dotnet/README.md b/tools/build_defs/dotnet/README.md deleted file mode 100644 index 36873ec411..0000000000 --- a/tools/build_defs/dotnet/README.md +++ /dev/null @@ -1,269 +0,0 @@ -# C# Rules - -## Rules - - - -## Overview - -This is a minimal viable set of C# bindings for building csharp code with -mono. It's still pretty rough but it works as a proof of concept that could -grow into something more. If windows support ever happens for Bazel then this -might become especially valuable. - -## Setup - -Add the following to your `WORKSPACE` file to add the external repositories: - -```python -load("@bazel_tools//tools/build_defs/dotnet:csharp.bzl", "csharp_repositories") - -csharp_repositories() -``` - -## Examples - -### csharp_library - -```python -csharp_library( - name = "MyLib", - srcs = ["MyLib.cs"], - deps = ["//my/dependency:SomeLib"], -) -``` - -### csharp_binary - -```python -csharp_binary( - name = "MyApp", - main = "MyApp", # optional name of the main class. - srcs = ["MyApp.cs"], - deps = ["//my/dependency:MyLib"], -) -``` - -### csharp\_nunit\_test - -```python -csharp_nunit_test( - name = "MyApp", - srcs = ["MyApp.cs"], - deps = ["//my/dependency:MyLib"], -) -``` - -## Things still missing: - -- Handle .resx files correctly. -- .Net Modules -- Conditionally building documentation. -- Pulling Mono in through a mono.WORKSPACE file. - -## Future nice to haves: - -- Building csproj and sln files for VS and MonoDevelop. -- Nuget Packaging -- Windows .NET framwork support - - -## csharp_library - -```python -csharp_library(name, srcs, deps, warn=4, csc) -``` - -Builds a C# .NET library and its corresponding documentation. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name -

Name, required

-

Unique name for this rule

-
srcs -

List of Labels; required

-

Csharp .cs or .resx files.

-
deps -

List of Labels; optional

-

Dependencies for this rule.

-
warn -

Int; optional; default is 4

-

Compiler warn level for this library. (Defaults to 4.)

-
csc -

string; optional

-

Override the default csharp compiler.

-

- Note: This attribute may removed in future - versions. -

-
- - -## csharp_binary - -```python -csharp_binary(name, srcs, deps, main_class, warn=4, csc) -``` - -Builds a C# .NET binary. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name -

Name, required

-

Unique name for this rule

-
srcs -

List of Labels; required

-

Csharp .cs or .resx files.

-
deps -

List of Labels; optional

-

Dependencies for this rule.

-
main_class -

String; optional -

Name of class with main() method to use as entry point.

-
warn -

Int; optional; default is 4

-

Compiler warn level for this binary. (Defaults to 4.)

-
csc -

string; optional

-

Override the default csharp compiler.

-

- Note: This attribute may removed in future - versions. -

-
- - -## csharp\_nunit\_test - -```python -csharp_nunit_test(name, srcs, deps, warn=4, csc) -``` - -Builds a C# .NET test binary that uses the [NUnit](http://www.nunit.org/) unit -testing framework. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name -

Name, required

-

Unique name for this rule

-
srcs -

List of Labels; required

-

Csharp .cs or .resx files.

-
deps -

List of Labels; optional

-

Dependencies for this rule.

-
warn -

Int; optional; default is 4

-

Compiler warn level for this test. (Defaults to 4.)

-
csc -

string; optional

-

Override the default csharp compiler.

-

- Note: This attribute may removed in future - versions. -

-
diff --git a/tools/build_defs/dotnet/csharp.bzl b/tools/build_defs/dotnet/csharp.bzl deleted file mode 100644 index 918aa38e01..0000000000 --- a/tools/build_defs/dotnet/csharp.bzl +++ /dev/null @@ -1,332 +0,0 @@ -# Copyright 2015 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. - -"""CSharp bazel rules""" - -load("//tools/build_rules:deprecation.bzl", "deprecated") - -def warning(rule): - print(deprecated( - "dotnet", - rule, - "@bazel_tools//tools/build_defs/dotnet:csharp.bzl", - "@io_bazel_rules_dotnet//dotnet:csharp.bzl")) - -_MONO_UNIX_CSC = "/usr/local/bin/mcs" - -# TODO(jeremy): Windows when it's available. - -def _make_csc_flag(flag_start, flag_name, flag_value=None): - return flag_start + flag_name + (":" + flag_value if flag_value else "") - -def _make_csc_deps(deps, extra_files=[]): - dlls = set() - refs = set() - transitive_dlls = set() - for dep in deps: - if hasattr(dep, "target_type"): - dep_type = getattr(dep, "target_type") - if dep_type == "exe": - fail("You can't use a binary target as a dependency") - if dep_type == "library": - dlls += [dep.out] - refs += [dep.name] - if dep.transitive_dlls: - transitive_dlls += dep.transitive_dlls - return struct( - dlls = dlls + set(extra_files), - refs = refs, - transitive_dlls = transitive_dlls) - -def _get_libdirs(dlls, libdirs=[]): - return [dep.dirname for dep in dlls] + libdirs - -def _make_csc_arglist(ctx, output, depinfo, extra_refs=[]): - flag_start = ctx.attr._flag_start - args = [ - # /out: - _make_csc_flag(flag_start, "out", output.path), - # /target (exe for binary, library for lib, module for module) - _make_csc_flag(flag_start, "target", ctx.attr._target_type), - # /fullpaths - _make_csc_flag(flag_start, "fullpaths"), - # /warn - _make_csc_flag(flag_start, "warn", str(ctx.attr.warn)), - # /nologo - _make_csc_flag(flag_start, "nologo"), - ] - - # /modulename: only used for modules - libdirs = _get_libdirs(depinfo.dlls) - libdirs = _get_libdirs(depinfo.transitive_dlls, libdirs) - # /lib:dir1,[dir1] - args += [_make_csc_flag(flag_start, "lib", ",".join(list(libdirs)))] if libdirs else [] - # /reference:filename[,filename2] - args += [_make_csc_flag(flag_start, "reference", ",".join(list(depinfo.refs + extra_refs)))] if depinfo.refs else extra_refs - - # /doc - args += [_make_csc_flag(flag_start, "doc", ctx.outputs.doc_xml.path)] if hasattr(ctx.outputs, "doc_xml") else [] - # /debug - debug = ctx.var.get("BINMODE", "") == "-dbg" - args += [_make_csc_flag(flag_start, "debug")] if debug else [] - # /warnaserror - # TODO(jeremy): /define:name[;name2] - # TODO(jeremy): /resource:filename[,identifier[,accesibility-modifier]] - # /main:class - if hasattr(ctx.attr, "main_class") and ctx.attr.main_class: - args += [_make_csc_flag(flag_start, "main", ctx.attr.main_class)] - # TODO(jwall): /parallel - return args - -def _make_nunit_launcher(ctx, depinfo, output): - content = """#!/bin/bash -cd $0.runfiles -# TODO(jeremy): This is a gross and fragile hack. -# We should be able to do better than this. -for l in {libs}; do - ln -s -f $l $(basename $l) -done -/usr/local/bin/mono {nunit_exe} {libs} "$@" - -""" - libs = [d.short_path for d in depinfo.dlls] - libs += [d.short_path for d in depinfo.transitive_dlls] - - content = content.format( - nunit_exe=ctx.files._nunit_exe[0].path, - libs=" ".join(libs)) - - ctx.file_action( - output=ctx.outputs.executable, - content=content) - -def _make_launcher(ctx, depinfo, output): - content = """#!/bin/bash -cd $0.runfiles -# TODO(jeremy): This is a gross and fragile hack. -# We should be able to do better than this. -ln -s -f {exe} $(basename {exe}) -for l in {libs}; do - ln -s -f $l $(basename $l) -done -/usr/local/bin/mono $(basename {exe}) "$@" -""" - libs = [d.short_path for d in depinfo.dlls] - libs += [d.short_path for d in depinfo.transitive_dlls] - - content = content.format( - exe=output.short_path, - libs=" ".join(libs)) - - ctx.file_action( - output=ctx.outputs.executable, - content=content) - -def _csc_get_output(ctx): - output = None - if hasattr(ctx.outputs, "csc_lib"): - output = ctx.outputs.csc_lib - elif hasattr(ctx.outputs, "csc_exe"): - output = ctx.outputs.csc_exe - else: - fail("You must supply one of csc_lib or csc_exe") - return output - -def _csc_collect_inputs(ctx, extra_files=[]): - depinfo = _make_csc_deps(ctx.attr.deps, extra_files=extra_files) - inputs = set(ctx.files.srcs) + depinfo.dlls + depinfo.transitive_dlls - srcs = [src.path for src in ctx.files.srcs] - return struct( - depinfo=depinfo, - inputs=inputs, - srcs=srcs) - -def _csc_compile_action(ctx, assembly, all_outputs, collected_inputs, extra_refs=[]): - csc_args = _make_csc_arglist(ctx, assembly, collected_inputs.depinfo, extra_refs=extra_refs) - command_script = " ".join([ctx.attr.csc] + csc_args + collected_inputs.srcs) - - ctx.action( - inputs = list(collected_inputs.inputs), - outputs = all_outputs, - command = command_script, - arguments = csc_args, - progress_message = ("Compiling " + - ctx.label.package + ":" + - ctx.label.name)) - -def _cs_runfiles(ctx, outputs, depinfo): - return ctx.runfiles( - files = outputs, - transitive_files = set(depinfo.dlls + depinfo.transitive_dlls) or None) - -def _csc_compile_impl(ctx): - warning("csharp_library") - if hasattr(ctx.outputs, "csc_lib") and hasattr(ctx.outputs, "csc_exe"): - fail("exactly one of csc_lib and csc_exe must be defined") - - output = _csc_get_output(ctx) - outputs = [output] + ([ctx.outputs.doc_xml] if hasattr(ctx.outputs, "doc_xml") else []) - - collected = _csc_collect_inputs(ctx) - - depinfo = collected.depinfo - inputs = collected.inputs - srcs = collected.srcs - - runfiles = _cs_runfiles(ctx, outputs, depinfo) - - _csc_compile_action(ctx, output, outputs, collected) - - if hasattr(ctx.outputs, "csc_exe"): - _make_launcher(ctx, depinfo, output) - - return struct(name= ctx.label.name, - srcs = srcs, - target_type=ctx.attr._target_type, - out = output, - dlls = set([output]), - transitive_dlls = depinfo.dlls, - runfiles=runfiles) - -def _cs_nunit_run_impl(ctx): - warning("csharp_nunit_test") - if hasattr(ctx.outputs, "csc_lib") and hasattr(ctx.outputs, "csc_exe"): - fail("exactly one of csc_lib and csc_exe must be defined") - - output = _csc_get_output(ctx) - outputs = [output] + ([ctx.outputs.doc_xml] if hasattr(ctx.outputs, "doc_xml") else []) - outputs = outputs - - collected_inputs = _csc_collect_inputs(ctx, ctx.files._nunit_framework) - - depinfo = collected_inputs.depinfo - inputs = collected_inputs.inputs - srcs = collected_inputs.srcs - - runfiles = _cs_runfiles(ctx, outputs + ctx.files._nunit_exe + ctx.files._nunit_exe_libs, depinfo) - - _csc_compile_action(ctx, output, outputs, collected_inputs, extra_refs=["Nunit.Framework"]) - - _make_nunit_launcher(ctx, depinfo, output) - - return struct(name=ctx.label.name, - srcs=srcs, - target_type=ctx.attr._target_type, - out=output, - dlls = set([output]) if hasattr(ctx.outputs, "csc_lib") else None, - transitive_dlls = depinfo.dlls, - runfiles=runfiles) - -_COMMON_ATTRS = { - # configuration fragment that specifies - "_flag_start": attr.string(default = "-"), - # where the csharp compiler is. - "csc": attr.string(default = _MONO_UNIX_CSC), - # code dependencies for this rule. - # all dependencies must provide an out field. - "deps": attr.label_list(providers = [ - "out", - "target_type", - ]), - # source files for this target. - "srcs": attr.label_list(allow_files = FileType([ - ".cs", - ".resx", - ])), - # resources to use as dependencies. - # TODO(jeremy): "resources_deps": attr.label_list(allow_files=True), - #TODO(jeremy): # name of the module if you are creating a module. - #TODO(jeremy): "modulename": attri.string(), - # warn level to use - "warn": attr.int(default = 4), - # define preprocessor symbols. - #TODO(jeremy): "define": attr.string_list(), -} - -_LIB_ATTRS = {"_target_type": attr.string(default = "library")} - -_EXE_ATTRS = { - "_target_type": attr.string(default = "exe"), - # main class to use as entry point. - "main_class": attr.string(), -} - -_NUNIT_ATTRS = { - "_nunit_exe": attr.label( - default = Label("@nunit//:nunit_exe"), - single_file = True, - ), - "_nunit_framework": attr.label(default = Label("@nunit//:nunit_framework")), - "_nunit_exe_libs": attr.label(default = Label("@nunit//:nunit_exe_libs")), -} - -_LIB_OUTPUTS = { - "csc_lib": "%{name}.dll", - "doc_xml": "%{name}.xml", -} - -_BIN_OUTPUTS = { - "csc_exe": "%{name}.exe", -} - -csharp_library = rule( - attrs = _COMMON_ATTRS + _LIB_ATTRS, - outputs = _LIB_OUTPUTS, - implementation = _csc_compile_impl, -) - -csharp_binary = rule( - attrs = _COMMON_ATTRS + _EXE_ATTRS, - executable = True, - outputs = _BIN_OUTPUTS, - implementation = _csc_compile_impl, -) - -csharp_nunit_test = rule( - attrs = _COMMON_ATTRS + _LIB_ATTRS + _NUNIT_ATTRS, - executable = True, - outputs = _LIB_OUTPUTS, - test = True, - implementation = _cs_nunit_run_impl, -) - -NUNIT_BUILD_FILE = """ -filegroup( - name = "nunit_exe", - srcs = ["NUnit-2.6.4/bin/nunit-console.exe"], - visibility = ["//visibility:public"], -) - -filegroup( - name = "nunit_exe_libs", - srcs = glob(["NUnit-2.6.4/bin/lib/*.dll"]), - visibility = ["//visibility:public"], -) - -filegroup( - name = "nunit_framework", - srcs = glob(["NUnit-2.6.4/bin/framework/*.dll"]), - visibility = ["//visibility:public"], -) -""" - -def csharp_repositories(): - warning("csharp_repositories") - native.new_http_archive( - name = "nunit", - build_file_content = NUNIT_BUILD_FILE, - sha256 = "1bd925514f31e7729ccde40a38a512c2accd86895f93465f3dfe6d0b593d7170", - type = "zip", - url = "https://github.com/nunit/nunitv2/releases/download/2.6.4/NUnit-2.6.4.zip", - ) diff --git a/tools/build_defs/groovy/README.md b/tools/build_defs/groovy/README.md deleted file mode 100644 index f954e5dbfc..0000000000 --- a/tools/build_defs/groovy/README.md +++ /dev/null @@ -1,588 +0,0 @@ -# Groovy Rules - - - -## Overview - -These build rules are used for building [Groovy](http://www.groovy-lang.org/) -projects with Bazel. Groovy libraries may interoperate with and depend on Java -libraries and vice-versa. - - -## Setup - -To be able to use the Groovy rules, you must provide bindings for the following -targets: - - * `//external:groovy-sdk`, pointing at the - [Groovy SDK binaries](http://www.groovy-lang.org/download.html) - * `//external:groovy`, pointing at the Groovy core language jar - * `//external:junit`, pointing at JUnit (only required if using the test rules) - * `//external:spock`, pointing at Spock (only required if using `spock_test`) - -The easiest way to do so is to add the following to your `WORKSPACE` file and -putting `groovy.BUILD` at the root of your workspace: - -```python -load("@bazel_tools//tools:build_defs/groovy/groovy.bzl", "groovy_repositories") - -groovy_repositories() -``` - - -## Basic Example - -Suppose you have the following directory structure for a simple Groovy and Java -application: - -``` -[workspace]/ - WORKSPACE - src/main/groovy/ - app/ - BUILD - GroovyApp.groovy - lib/ - BUILD - GroovyLib.groovy - JavaLib.java - src/test/groovy/ - lib/ - BUILD - LibTest.groovy -``` - -Then, to build the code under src/main/groovy/lib/, your -`src/main/groovy/lib/BUILD` can look like this: - -```python -load("@bazel_tools//tools:build_defs/groovy/groovy.bzl", "groovy_library") - -groovy_library( - name = "groovylib", - srcs = glob(["*.groovy"]), - deps = [ - ":javalib", - ], -) - -java_library( - name = "javalib", - srcs = glob(["*.java"]), -) -``` - -For simplicity, you can combine Groovy and Java sources into a single library -using `groovy_and_java_library`. Note that this allows the Groovy code to -reference the Java code, but not vice-versa. Your `src/main/groovy/lib/BUILD` -file would then look like this: - -```python -load("@bazel_tools//tools:build_defs/groovy/groovy.bzl", "groovy_and_java_library") - -groovy_and_java_library( - name = "lib", - srcs = glob(["*.groovy", "*.java"]), -) -``` - -To build the application under src/main/groovy/app, you can define a binary -using `groovy_binary` as follows: - -```python -load("@bazel_tools//tools:build_defs/groovy/groovy.bzl", "groovy_binary") - -groovy_binary( - name = "GroovyApp", - srcs = glob(["*.groovy"]), - main_class = "GroovyApp", - deps = [ - "//src/main/groovy/lib", - ], -) -``` - -Finally, you can write tests in Groovy using `groovy_test`. The `srcs` of this -rule will be converted into names of class files that are passed to JUnit. For -this to work, the test sources must be under src/test/groovy or src/test/java. -To build the test under src/test/groovy/lib, your BUILD file would look like -this: - -```python -load("@bazel_tools//tools:build_defs/groovy/groovy.bzl", "groovy_test", "groovy_library") - - -groovy_library( - name = "testlib", - srcs = glob(["*.groovy"]), -) - -groovy_test( - name = "LibTest", - srcs = ["LibTest.groovy"], - deps = [":testlib"], -) -``` - -If you're using JUnit or Spock, see -groovy_junit_test or - -## groovy_library - -```python -groovy_library(name, srcs, deps, **kwargs) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
srcs - List of labels, required -

List of .groovy source files used to build the library.

-
deps - List of labels or .jar files, optional -

- List of other libraries to be included on the compile-time classpath - when building this library. -

-

- These can be either other `groovy_library` targets, `java_library` - targets, `groovy_and_java_library` targets, or raw .jar files. -

-
**kwargs - see java_binary -

- The other arguments of this rule will be passed to the `java_import` - that wraps the groovy library. -

-
- - -## groovy\_and\_java\_library - -```python -groovy_and_java_library(name, srcs, deps, **kwargs) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
srcs - List of labels, required -

List of .groovy and .java source files used to build the library.

-
deps - List of labels or .jar files, optional -

- List of other libraries to be included on the compile-time classpath - when building this library. -

-

- These can be either other `groovy_library` targets, `java_library` - targets, `groovy_and_java_library` targets, or raw .jar files. -

-
**kwargs - see java_binary -

- The other arguments of this rule will be passed to the `java_import` - that wraps the groovy library. -

-
- - -## groovy_binary - -```python -groovy_binary(name, main_class, srcs, deps, **kwargs) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
main_class - String, required -

- The name of either a class containing a `main` method or a Groovy - script file to use as an entry point (see - - here for more details on scripts vs. classes). -

-
srcs - List of labels, required -

List of .groovy source files used to build the application.

-
deps - List of labels or .jar files, optional -

- List of other libraries to be included on both the compile-time - classpath when building this application and the runtime classpath - when executing it. -

-

- These can be `groovy_library` targets, `java_library` targets, - `groovy_and_java_library` targets, or raw .jar files. -

-
**kwargs - see java_binary -

- The other arguments of this rule will be passed to the `java_binary` - underlying the `groovy_binary`. -

-
- - -## groovy_test - -```python -groovy_test(name, deps, srcs, data, resources, jvm_flags, size, tags) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
srcs - List of labels, required -

- List of .groovy source files whose names will be converted to classes - passed to JUnitCore. -

-
deps - List of labels or .jar files, optional -

- List of libraries to be included on both the compile-time classpath - when building this test and on the runtime classpath when executing it. -

-

- These can be `groovy_library` targets, `java_library` targets, - `groovy_and_java_library` targets, or raw .jar files. -

-
resources - List of labels, optional -

- A list of data files to include on the test's classpath. This is - accomplished by creating a `java_library` containing only the specified - resources and including that library in the test's dependencies. -

-
jvm_flags - List of strings, optional -

- A list of flags to embed in the wrapper script generated for running - this binary. -

-
- - -## groovy_junit_test - -```python -groovy_junit_test(name, tests, deps, groovy_srcs, java_srcs, data, resources, jvm_flags, size, tags) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
tests - List of labels, required -

- List of .groovy source files that will be used as test specifications - that will be executed by JUnit. -

-
groovy_srcs - List of labels, optional -

- List of additional .groovy source files that will be used to build the - test. -

-
java_srcs - List of labels, optional -

- List of additional .java source files that will be used to build the - test. -

-
deps - List of labels or .jar files, optional -

- List of libraries to be included on both the compile-time classpath - when building this test and on the runtime classpath when executing it. -

-

- These can be `groovy_library` targets, `java_library` targets, - `groovy_and_java_library` targets, or raw .jar files. -

-
resources - List of labels, optional -

- A list of data files to include on the test's classpath. This is - accomplished by creating a `java_library` containing only the specified - resources and including that library in the test's dependencies. -

-
jvm_flags - List of strings, optional -

- A list of flags to embed in the wrapper script generated for running - this binary. -

-
- - -## spock_test - -```python -spock_test(name, specs, deps, groovy_srcs, java_srcs, data, resources, jvm_flags, size, tags) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
specs - List of labels, required -

- List of .groovy source files that will be used as test specifications - that will be executed by JUnit. -

-
groovy_srcs - List of labels, optional -

- List of additional .groovy source files that will be used to build the - test. -

-
java_srcs - List of labels, optional -

- List of additional .java source files that will be used to build the - test. -

-
deps - List of labels or .jar files, optional -

- List of libraries to be included on both the compile-time classpath - when building this test and on the runtime classpath when executing it. -

-

- These can be `groovy_library` targets, `java_library` targets, - `groovy_and_java_library` targets, or raw .jar files. -

-
resources - List of labels, optional -

- A list of data files to include on the test's classpath. This is - accomplished by creating a `java_library` containing only the specified - resources and including that library in the test's dependencies. -

-
jvm_flags - List of strings, optional -

- A list of flags to embed in the wrapper script generated for running - this binary. -

-
diff --git a/tools/build_defs/groovy/groovy.bzl b/tools/build_defs/groovy/groovy.bzl deleted file mode 100644 index 992e7caf1a..0000000000 --- a/tools/build_defs/groovy/groovy.bzl +++ /dev/null @@ -1,438 +0,0 @@ -# Copyright 2015 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("//tools/build_rules:deprecation.bzl", "deprecated") - -def warning(rule): - print(deprecated( - "groovy", - rule, - "@bazel_tools//tools/build_defs/groovy:groovy.bzl", - "@io_bazel_rules_groovy//groovy:groovy.bzl")) - -def _groovy_jar_impl(ctx): - """Creates a .jar file from Groovy sources. Users should rely on - groovy_library instead of using this rule directly. - """ - warning("groovy_jar") - class_jar = ctx.outputs.class_jar - build_output = class_jar.path + ".build_output" - - # Extract all transitive dependencies - # TODO(bazel-team): get transitive dependencies from other groovy libraries - all_deps = set(ctx.files.deps) - for this_dep in ctx.attr.deps: - if hasattr(this_dep, "java"): - all_deps += this_dep.java.transitive_runtime_deps - - # Set up the output directory and set JAVA_HOME - cmd = "rm -rf %s\n" % build_output - cmd += "mkdir -p %s\n" % build_output - cmd += "export JAVA_HOME=external/local_jdk\n" - - # Set GROOVY_HOME by scanning through the groovy SDK to find the license file, - # which should be at the root of the SDK. - for file in ctx.files._groovysdk: - if file.basename == "CLI-LICENSE.txt": - cmd += "export GROOVY_HOME=%s\n" % file.dirname - break - - # Compile all files in srcs with groovyc - cmd += "$GROOVY_HOME/bin/groovyc %s -d %s %s\n" % ( - "-cp " + ":".join([dep.path for dep in all_deps]) if len(all_deps) != 0 else "", - build_output, - " ".join([src.path for src in ctx.files.srcs]), - ) - - # Discover all of the generated class files and write their paths to a file. - # Run the paths through sed to trim out everything before the package root so - # that the paths match how they should look in the jar file. - cmd += "find . -name '*.class' | sed 's:^./%s/::' > %s/class_list\n" % ( - build_output, - build_output, - ) - - # Create a jar file using the discovered paths - cmd += "root=`pwd`\n" - cmd += "cd %s; $root/%s Cc ../%s @class_list\n" % ( - build_output, - ctx.executable._zipper.path, - class_jar.basename, - ) - cmd += "cd $root\n" - - # Clean up temporary output - cmd += "rm -rf %s" % build_output - - # Execute the command - ctx.action( - inputs = ( - ctx.files.srcs - + list(all_deps) - + ctx.files._groovysdk - + ctx.files._jdk - + ctx.files._zipper), - outputs = [class_jar], - mnemonic = "Groovyc", - command = "set -e;" + cmd, - use_default_shell_env = True, - ) - -_groovy_jar = rule( - attrs = { - "srcs": attr.label_list( - non_empty = True, - allow_files = FileType([".groovy"]), - ), - "deps": attr.label_list( - mandatory = False, - allow_files = FileType([".jar"]), - ), - "_groovysdk": attr.label( - default = Label("//external:groovy-sdk"), - ), - "_jdk": attr.label( - default = Label("//tools/defaults:jdk"), - ), - "_zipper": attr.label( - default = Label("@bazel_tools//tools/zip:zipper"), - executable = True, - single_file = True, - ), - }, - outputs = { - "class_jar": "lib%{name}.jar", - }, - implementation = _groovy_jar_impl, -) - -def groovy_library(name, srcs=[], deps=[], **kwargs): - """Rule analagous to java_library that accepts .groovy sources instead of - .java sources. The result is wrapped in a java_import so that java rules may - depend on it. - """ - warning("groovy_library") - _groovy_jar( - name = name + "-impl", - srcs = srcs, - deps = deps, - ) - native.java_import( - name = name, - jars = [name + "-impl"], - deps = deps, - **kwargs - ) - -def groovy_and_java_library(name, srcs=[], deps=[], **kwargs): - """Accepts .groovy and .java srcs to create a groovy_library and a - java_library. The groovy_library will depend on the java_library, so the - Groovy code may reference the Java code but not vice-versa. - """ - warning("groovy_and_java_library") - groovy_deps = deps - jars = [] - - # Put all .java sources in a java_library - java_srcs = [src for src in srcs if src.endswith(".java")] - if java_srcs: - native.java_library( - name = name + "-java", - srcs = java_srcs, - deps = deps, - ) - groovy_deps += [name + "-java"] - jars += ["lib" + name + "-java.jar"] - - # Put all .groovy sources in a groovy_library depending on the java_library - groovy_srcs = [src for src in srcs if src.endswith(".groovy")] - if groovy_srcs: - _groovy_jar( - name = name + "-groovy", - srcs = groovy_srcs, - deps = groovy_deps, - ) - jars += ["lib" + name + "-groovy.jar"] - - # Output a java_import combining both libraries - native.java_import( - name = name, - jars = jars, - deps = deps, - **kwargs - ) - -def groovy_binary(name, main_class, srcs=[], deps=[], **kwargs): - """Rule analagous to java_binary that accepts .groovy sources instead of .java - sources. - """ - warning("groovy_binary") - all_deps = deps + ["//external:groovy"] - if srcs: - groovy_library( - name = name + "-lib", - srcs = srcs, - deps = deps, - ) - all_deps += [name + "-lib"] - - native.java_binary( - name = name, - main_class = main_class, - runtime_deps = all_deps, - **kwargs - ) - -def path_to_class(path): - if path.startswith("src/test/groovy/"): - return path[len("src/test/groovy/") : path.index(".groovy")].replace('/', '.') - elif path.startswith("src/test/java/"): - return path[len("src/test/java/") : path.index(".groovy")].replace('/', '.') - else: - fail("groovy_test sources must be under src/test/java or src/test/groovy") - -def _groovy_test_impl(ctx): - warning("groovy_test") - # Collect jars from the Groovy sdk - groovy_sdk_jars = [file - for file in ctx.files._groovysdk - if file.basename.endswith(".jar") - ] - - # Extract all transitive dependencies - all_deps = set(ctx.files.deps + ctx.files._implicit_deps + groovy_sdk_jars) - for this_dep in ctx.attr.deps: - if hasattr(this_dep, 'java'): - all_deps += this_dep.java.transitive_runtime_deps - - # Infer a class name from each src file - classes = [path_to_class(src.path) for src in ctx.files.srcs] - - # Write a file that executes JUnit on the inferred classes - cmd = "external/local_jdk/bin/java %s -cp %s org.junit.runner.JUnitCore %s\n" % ( - " ".join(ctx.attr.jvm_flags), - ":".join([dep.short_path for dep in all_deps]), - " ".join(classes), - ) - ctx.file_action( - output = ctx.outputs.executable, - content = cmd - ) - - # Return all dependencies needed to run the tests - return struct( - runfiles=ctx.runfiles(files=list(all_deps) + ctx.files.data + ctx.files._jdk), - ) - -_groovy_test = rule( - attrs = { - "srcs": attr.label_list( - mandatory = True, - allow_files = FileType([".groovy"]), - ), - "deps": attr.label_list(allow_files = FileType([".jar"])), - "data": attr.label_list(allow_files = True), - "jvm_flags": attr.string_list(), - "_groovysdk": attr.label( - default = Label("//external:groovy-sdk"), - ), - "_jdk": attr.label( - default = Label("//tools/defaults:jdk"), - ), - "_implicit_deps": attr.label_list(default = [ - Label("//external:junit"), - ]), - }, - test = True, - implementation = _groovy_test_impl, -) - -def groovy_test( - name, - deps=[], - srcs=[], - data=[], - resources=[], - jvm_flags=[], - size="medium", - tags=[]): - # Create an extra jar to hold the resource files if any were specified - all_deps = deps - if resources: - native.java_library( - name = name + "-resources", - resources = resources, - ) - all_deps += [name + "-resources"] - - _groovy_test( - name = name, - size = size, - tags = tags, - srcs = srcs, - deps = all_deps, - data = data, - jvm_flags = jvm_flags, - ) - -def groovy_junit_test( - name, - tests, - deps=[], - groovy_srcs=[], - java_srcs=[], - data=[], - resources=[], - jvm_flags=[], - size="small", - tags=[]): - warning("groovy_junit_test") - groovy_lib_deps = deps + ["//external:junit"] - test_deps = deps + ["//external:junit"] - - if len(tests) == 0: - fail("Must provide at least one file in tests") - - # Put all Java sources into a Java library - if java_srcs: - native.java_library( - name = name + "-javalib", - srcs = java_srcs, - deps = deps + ["//external:junit"], - ) - groovy_lib_deps += [name + "-javalib"] - test_deps += [name + "-javalib"] - - # Put all tests and Groovy sources into a Groovy library - groovy_library( - name = name + "-groovylib", - srcs = tests + groovy_srcs, - deps = groovy_lib_deps, - ) - test_deps += [name + "-groovylib"] - - # Create a groovy test - groovy_test( - name = name, - deps = test_deps, - srcs = tests, - data = data, - resources = resources, - jvm_flags = jvm_flags, - size = size, - tags = tags, - ) - -def spock_test( - name, - specs, - deps=[], - groovy_srcs=[], - java_srcs=[], - data=[], - resources=[], - jvm_flags=[], - size="small", - tags=[]): - warning("spock_test") - groovy_lib_deps = deps + [ - "//external:junit", - "//external:spock", - ] - test_deps = deps + [ - "//external:junit", - "//external:spock", - ] - - if len(specs) == 0: - fail("Must provide at least one file in specs") - - # Put all Java sources into a Java library - if java_srcs: - native.java_library( - name = name + "-javalib", - srcs = java_srcs, - deps = deps + [ - "//external:junit", - "//external:spock", - ], - ) - groovy_lib_deps += [name + "-javalib"] - test_deps += [name + "-javalib"] - - # Put all specs and Groovy sources into a Groovy library - groovy_library( - name = name + "-groovylib", - srcs = specs + groovy_srcs, - deps = groovy_lib_deps, - ) - test_deps += [name + "-groovylib"] - - # Create a groovy test - groovy_test( - name = name, - deps = test_deps, - srcs = specs, - data = data, - resources = resources, - jvm_flags = jvm_flags, - size = size, - tags = tags, - ) - -def groovy_repositories(): - warning("groovy_repositories") - native.new_http_archive( - name = "groovy_sdk_artifact", - url = "http://dl.bintray.com/groovy/maven/apache-groovy-binary-2.4.4.zip", - sha256 = "a7cc1e5315a14ea38db1b2b9ce0792e35174161141a6a3e2ef49b7b2788c258c", - build_file_content = """ -filegroup( - name = "sdk", - srcs = glob(["groovy-2.4.4/**"], exclude_directories=0), - visibility = ["//visibility:public"], -) -java_import( - name = "groovy", - jars = ["groovy-2.4.4/lib/groovy-2.4.4.jar"], - visibility = ["//visibility:public"], -) -""", - ) - native.bind( - name = "groovy-sdk", - actual = "@groovy_sdk_artifact//:sdk", - ) - native.bind( - name = "groovy", - actual = "@groovy_sdk_artifact//:groovy", - ) - - native.maven_jar( - name = "junit_artifact", - artifact = "junit:junit:4.12", - ) - native.bind( - name = "junit", - actual = "@junit_artifact//jar", - ) - - native.maven_jar( - name = "spock_artifact", - artifact = "org.spockframework:spock-core:0.7-groovy-2.0", - ) - native.bind( - name = "spock", - actual = "@spock_artifact//jar", - ) diff --git a/tools/build_defs/sass/BUILD b/tools/build_defs/sass/BUILD deleted file mode 100644 index 062ab56c4a..0000000000 --- a/tools/build_defs/sass/BUILD +++ /dev/null @@ -1,12 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "srcs", - srcs = glob(["**"]), - visibility = ["//tools:__pkg__"], -) - -filegroup( - name = "sassc", - srcs = ["@sassc//:sassc"], -) diff --git a/tools/build_defs/sass/README.md b/tools/build_defs/sass/README.md deleted file mode 100644 index 5e7d7217ef..0000000000 --- a/tools/build_defs/sass/README.md +++ /dev/null @@ -1,271 +0,0 @@ -# Sass Rules for Bazel - -
-

Rules

- -
- -## Overview -These build rules are used for building [Sass][sass] projects with Bazel. - -[sass]: http://www.sass-lang.com - - -## Setup -To use the Sass rules, add the following to your `WORKSPACE` file to add the -external repositories for Sass: - -```python -load("@bazel_tools//tools/build_defs/sass:sass.bzl", "sass_repositories") - -sass_repositories() -``` - - -## Basic Example - -Suppose you have the following directory structure for a simple Sass project: - -``` -[workspace]/ - WORKSPACE - hello_world/ - BUILD - main.scss - shared/ - BUILD - _fonts.scss - _colors.scss -``` - -`shared/_fonts.scss` - -```scss -$default-font-stack: Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", ser -if; -$modern-font-stack: Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif", "Bitstream Vera Serif", "Liber -ation Serif", Georgia, serif; -``` - -`shared/_colors.scss` - -```scss -$example-blue: #0000ff; -$example-red: #ff0000; -``` - -`shared/BUILD` - -```python -package(default_visibility = ["//visibility:public"]) - -load("@bazel_tools//tools/build_defs/sass:sass.bzl", "sass_library") - -sass_library( - name = "colors", - srcs = ["_colors.scss"], -) - -sass_library( - name = "fonts", - srcs = ["_fonts.scss"], -) -``` - -`hello_world/main.scss`: - -```scss -@import "examples/sass/shared/fonts"; -@import "examples/sass/shared/colors"; - -html { - body { - font-family: $default-font-stack; - h1 { - font-family: $modern-font-stack; - color: $example-red; - } - } -} -``` - -`hello_world/BUILD:` - -```python -package(default_visibility = ["//visibility:public"]) - -load("@bazel_tools//tools/build_defs/sass:sass.bzl", "sass_binary") - -sass_binary( - name = "hello_world", - src = "main.scss", - deps = [ - "//shared:colors", - "//shared:fonts", - ], -) -``` - -Build the binary: - -``` -$ bazel build //hello_world -INFO: Found 1 target... -Target //hello_world:hello_world up-to-date: - bazel-bin/hello_world/hello_world.css - bazel-bin/hello_world/hello_world.css.map -INFO: Elapsed time: 1.911s, Critical Path: 0.01s -``` - - -## Build Rule Reference - - -## sass_binary - -```python -sass_binary(name, src, deps=[], output_style="compressed") -``` - -Used to generate a CSS artifact from a given `src` sass file. - - - - - - - - - - - - - - - - - - - - - -
Implicit Output Targets
name.css -

The generated CSS artifact containing all the styles

-
name.css.map -

- source map - that can be used to optionally debug the generated CSS in a browser. -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-

- This name will also be used as the name of the generated CSS and source map file of - this rule. -

-
src - Main source file, required -

The primary Sass source file that will be compiled to CSS.

-

- sass_binary assumes a 1:1 mapping of src to output CSS file (and source map). -

-
deps - list of labels, optional -

-

- Each target should be defined using a filegroup rule and should only include "_" prefixed files that are referenced via @import in the target's source file. -

-
output_style - string; optional -

Defaults to compressed.

-

- Can be set to one of the following output styles defined by sassc. -

-
- - -## sass_library - -```python -sass_library(name, src, deps=[]) -``` - -Used to reference sass a collection of sass files that a -[`sass_binary`](#reference-sass_binary) may depend on (via `@import` -statements), but should not result in any output targets. - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-

-

-
srcs - a list of labels, required -

-

- sass_library all files should start with an underscore, eg: _colors.scss. -

-
deps - list of labels, optional -

-

- This could be any other sass_library targets that this target may include. -

-
diff --git a/tools/build_defs/sass/sass.bzl b/tools/build_defs/sass/sass.bzl deleted file mode 100644 index 4ae978a1a1..0000000000 --- a/tools/build_defs/sass/sass.bzl +++ /dev/null @@ -1,156 +0,0 @@ -# Copyright 2015 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("//tools/build_rules:deprecation.bzl", "deprecated") - -def warning(rule): - print(deprecated( - "sass", - rule, - "@bazel_tools//tools/build_defs/sass:sass.bzl", - "@io_bazel_rules_sass//sass:sass.bzl")) - -SASS_FILETYPES = FileType([ - ".sass", - ".scss", -]) - -def collect_transitive_sources(ctx): - source_files = set(order="compile") - for dep in ctx.attr.deps: - source_files += dep.transitive_sass_files - return source_files - -def _sass_library_impl(ctx): - warning("sass_library") - transitive_sources = collect_transitive_sources(ctx) - transitive_sources += SASS_FILETYPES.filter(ctx.files.srcs) - return struct( - files = set(), - transitive_sass_files = transitive_sources) - -def _sass_binary_impl(ctx): - # Reference the sass compiler and define the default options - # that sass_binary uses. - warning("sass_binary") - sassc = ctx.file._sassc - options = [ - "--style={0}".format(ctx.attr.output_style), - "--sourcemap", - ] - - # Load up all the transitive sources as dependent includes. - transitive_sources = collect_transitive_sources(ctx) - for src in transitive_sources: - options += ["-I={0}".format(src)] - - ctx.action( - inputs = [sassc, ctx.file.src] + list(transitive_sources), - executable = sassc, - arguments = options + [ctx.file.src.path, ctx.outputs.css_file.path], - mnemonic = "SassCompiler", - outputs = [ctx.outputs.css_file, ctx.outputs.css_map_file], - ) - -sass_deps_attr = attr.label_list( - providers = ["transitive_sass_files"], - allow_files = False, -) - -sass_library = rule( - attrs = { - "srcs": attr.label_list( - allow_files = SASS_FILETYPES, - non_empty = True, - mandatory = True, - ), - "deps": sass_deps_attr, - }, - implementation = _sass_library_impl, -) - -sass_binary = rule( - attrs = { - "src": attr.label( - allow_files = SASS_FILETYPES, - mandatory = True, - single_file = True, - ), - "output_style": attr.string(default = "compressed"), - "deps": sass_deps_attr, - "_sassc": attr.label( - default = Label("@bazel_tools//tools/build_defs/sass:sassc"), - executable = True, - single_file = True, - ), - }, - outputs = { - "css_file": "%{name}.css", - "css_map_file": "%{name}.css.map", - }, - implementation = _sass_binary_impl, -) - -LIBSASS_BUILD_FILE = """ -package(default_visibility = ["@sassc//:__pkg__"]) - -filegroup( - name = "srcs", - srcs = glob([ - "src/**/*.h*", - "src/**/*.c*", - ]), -) - -# Includes directive may seem unnecessary here, but its needed for the weird -# interplay between libsass/sassc projects. This is intentional. -cc_library( - name = "headers", - includes = ["include"], - hdrs = glob(["include/**/*.h"]), -) -""" - -SASSC_BUILD_FILE = """ -package(default_visibility = ["//visibility:public"]) - -cc_binary( - name = "sassc", - srcs = [ - "@libsass//:srcs", - "sassc.c", - "sassc_version.h", -], - linkopts = ["-ldl", "-lm"], - deps = ["@libsass//:headers"], -) -""" - -def sass_repositories(): - warning("sass_repositories") - native.new_http_archive( - name = "libsass", - url = "https://github.com/sass/libsass/archive/3.3.0-beta1.tar.gz", - sha256 = "6a4da39cc0b585f7a6ee660dc522916f0f417c890c3c0ac7ebbf6a85a16d220f", - build_file_content = LIBSASS_BUILD_FILE, - strip_prefix = "libsass-3.3.0-beta1", - ) - - native.new_http_archive( - name = "sassc", - url = "https://github.com/sass/sassc/archive/3.3.0-beta1.tar.gz", - sha256 = "87494218eea2441a7a24b40f227330877dbba75c5fa9014ac6188711baed53f6", - build_file_content = SASSC_BUILD_FILE, - strip_prefix = "sassc-3.3.0-beta1", - ) diff --git a/tools/build_defs/sass/test/BUILD b/tools/build_defs/sass/test/BUILD deleted file mode 100644 index 2caae9c6a5..0000000000 --- a/tools/build_defs/sass/test/BUILD +++ /dev/null @@ -1,3 +0,0 @@ -load(":sass_rule_test.bzl", "sass_rule_test") - -sass_rule_test("//examples/sass") diff --git a/tools/build_defs/sass/test/sass_rule_test.bzl b/tools/build_defs/sass/test/sass_rule_test.bzl deleted file mode 100644 index c4a12fec86..0000000000 --- a/tools/build_defs/sass/test/sass_rule_test.bzl +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2015 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( - "//tools/build_defs/sass:sass.bzl", - "sass_binary", -) - -load( - "//tools/build_rules:test_rules.bzl", - "success_target", - "successful_test", - "failure_target", - "failed_test", - "assert_", - "strip_prefix", - "expectation_description", - "check_results", - "load_results", - "analysis_results", - "rule_test", - "file_test", -) - -def _sass_binary_test(package): - rule_test( - name = "hello_world_rule_test", - generates = ["hello_world.css", "hello_world.css.map"], - rule = package + "/hello_world:hello_world", - ) - -def sass_rule_test(package): - """Issue simple tests on sass rules.""" - _sass_binary_test(package) diff --git a/tools/build_rules/appengine/BUILD b/tools/build_rules/appengine/BUILD deleted file mode 100644 index 235ebf0873..0000000000 --- a/tools/build_rules/appengine/BUILD +++ /dev/null @@ -1,25 +0,0 @@ -# A target to ensure the servlet-api is not linked in the webapp. -java_library( - name = "javax.servlet.api", - neverlink = 1, - visibility = ["//visibility:public"], - exports = ["@javax_servlet_api//jar:jar"], -) - -filegroup( - name = "runner_template", - srcs = ["appengine_runner.sh.template"], - visibility = ["//visibility:public"], -) - -filegroup( - name = "deploy_template", - srcs = ["appengine_deploy.sh.template"], - visibility = ["//visibility:public"], -) - -filegroup( - name = "srcs", - srcs = glob(["**"]), - visibility = ["//tools:__pkg__"], -) diff --git a/tools/build_rules/appengine/README.md b/tools/build_rules/appengine/README.md deleted file mode 100644 index 0b047c9203..0000000000 --- a/tools/build_rules/appengine/README.md +++ /dev/null @@ -1,231 +0,0 @@ -# Java App Engine Rules for Bazel - -
-

Rules

- -
- -## Overview - -These build rules are used for building -[Java App Engine](https://cloud.google.com/appengine/docs/java/) -application with Bazel. It does not aim at general Java web application -support but can be easily modified to handle a standard web application. - - -## Setup - -To be able to use the Java App Engine rules, you must make the App Engine SDK -available to Bazel. The easiest way to do so is by adding the following to your -`WORKSPACE` file: - -```python -load("@bazel_tools//tools/build_rules/appengine:appengine.bzl", "appengine_repositories") - -appengine_repositories() -``` - - -## Basic Example - -Suppose you have the following directory structure for a simple App Engine -application: - -``` -[workspace]/ - WORKSPACE - hello_app/ - BUILD - java/my/webapp/ - TestServlet.java - webapp/ - index.html - webapp/WEB-INF - web.xml - appengine-web.xml -``` - -Then, to build your webapp, your `hello_app/BUILD` can look like: - -```python -load("@bazel_tools//tools/build_rules/appengine:appengine.bzl", "appengine_war") - -java_library( - name = "mylib", - srcs = ["java/my/webapp/TestServlet.java"], - deps = [ - "//external:appengine/java/api", - "//external:javax/servlet/api", - ], -) - -appengine_war( - name = "myapp", - jars = [":mylib"], - data = glob(["webapp/**"]), - data_path = "webapp", -) -``` - -For simplicity, you can use the `java_war` rule to build an app from source. -Your `hello_app/BUILD` file would then look like: - -```python -load("@bazel_tools//tools/build_rules/appengine:appengine.bzl", "java_war") - -java_war( - name = "myapp", - srcs = ["java/my/webapp/TestServlet.java"], - data = glob(["webapp/**"]), - data_path = "webapp", - deps = [ - "//external:appengine/java/api", - "//external:javax/servlet/api", - ], -) -``` - -You can then build the application with `bazel build //hello_app:myapp` and -run in it a development server with `bazel run //hello_app:myapp`. This will -bind a test server on port 8080. If you wish to select another port, -simply append the `--port=12345` to the command-line. - -Another target `//hello_app:myapp.deploy` allows you to deploy your -application to App Engine. It takes an optional argument: the -`APP_ID`. If not specified, it uses the default `APP_ID` provided in -the application. This target needs to be authorized to App Engine. Since -Bazel does not connect the standard input, it is easier to run it by: -``` -bazel-bin/hello_app/myapp.deploy APP_ID -``` - -After the first launch, subsequent launch will be registered to -App Engine so you can just do a normal `bazel run -//hello_app:myapp.deploy APP_ID` to deploy next versions of -your application. - - -## appengine_war - -```python -appengine_war(name, jars, data, data_path) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
jars - List of labels, required -

- List of JAR files that will be uncompressed as the code for the - Web Application. -

-

- If it is a `java_library` or a `java_import`, the - JAR from the runtime classpath will be added in the `lib` directory - of the Web Application. -

-
data - List of files, optional -

List of files used by the Web Application at runtime.

-

- This attribute can be used to specify the list of resources to - be included into the WAR file. -

-
data_path - String, optional -

Root path of the data.

-

- The directory structure from the data is preserved inside the - WebApplication but a prefix path determined by `data_path` - is removed from the the directory structure. This path can - be absolute from the workspace root if starting with a `/` or - relative to the rule's directory. It is set to `.` by default. -

-
- - -## java_war - -``` -java_war(name, data, data_path, **kwargs) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
data - List of labels, optional -

List of files used by the Web Application at runtime.

-

Passed to the appengine_war rule.

-
data_path - String, optional -

Root path of the data.

-

Passed to the appengine_war rule.

-
**kwargs - see java_library -

- The other arguments of this rule will be passed to build a `java_library` - that will be passed in the `jar` arguments of a - appengine_war rule. -

-
diff --git a/tools/build_rules/appengine/appengine.bzl b/tools/build_rules/appengine/appengine.bzl deleted file mode 100644 index 1abbc83a44..0000000000 --- a/tools/build_rules/appengine/appengine.bzl +++ /dev/null @@ -1,316 +0,0 @@ -# Copyright 2015 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. -"""Java AppEngine support for Bazel. - -For now, it only support bundling a WebApp and running locally. - -To create a WebApp for Google AppEngine, add the rules: -appengine_war( - name = "MyWebApp", - # Jars to use for the classpath in the webapp. - jars = ["//java/com/google/examples/mywebapp:java"], - # data to put in the webapp, the directory structure of the data set - # will be maintained. - data = ["//java/com/google/examples/mywebapp:data"], - # Data's root path, it will be considered as the root of the data files. - # If unspecified, the path to the current package will be used. The path is - # relative to current package or, relative to the workspace root if starting - # with a leading slash. - data_path = "/java/com/google/examples/mywebapp", -) - - -You can also make directly a single target for it with: - -java_war( - name = "MyWebApp", - srcs = glob(["**/*.java"]), - resources = ["..."], - data = ["..."], - data_path = "...", -) - -Resources will be put in the classpath whereas data will be bundled at the root -of the war file. This is strictly equivalent to (it is actually a convenience -macros that translate to that): - -java_library( - name = "libMyWebApp", - srcs = glob(["**/*.java"]), - resources = ["..."], -) - -appengine_war( - name = "MyWebApp", - jars = [":libMyWebApp"], - data = ["..."], - data_path = "...", -) - -This rule will also create a .deploy target that will try to use the AppEngine -SDK to upload your application to AppEngine. It takes an optional argument: the -APP_ID. If not specified, it uses the default APP_ID provided in the application -web.xml. -""" - -load("//tools/build_rules:deprecation.bzl", "deprecated") - -def warning(rule): - print(deprecated( - "appengine", - rule, - "@bazel_tools//tools/build_rules/appengine:appengine.bzl", - "@io_bazel_rules_appengine//appengine:appengine.bzl")) - -jar_filetype = FileType([".jar"]) - -def _add_file(in_file, output, path = None): - output_path = output - input_path = in_file.path - if path and input_path.startswith(path): - output_path += input_path[len(path):] - return [ - "mkdir -p $(dirname %s)" % output_path, - "test -L %s || ln -s $(pwd)/%s %s\n" % (output_path, input_path, - output_path) - ] - -def _make_war(zipper, input_dir, output): - return [ - "(root=$(pwd);" + - ("cd %s &&" % input_dir) + - ("${root}/%s Cc ${root}/%s $(find .))" % (zipper.path, output.path)) - ] - -def _common_substring(str1, str2): - i = 0 - res = "" - for c in str1: - if str2[i] != c: - return res - res += c - i += 1 - return res - -def _short_path_dirname(path): - sp = path.short_path - return sp[0:len(sp)-len(path.basename)-1] - -def _war_impl(ctxt): - warning("appengine_war") - zipper = ctxt.file._zipper - - data_path = ctxt.attr.data_path - if not data_path: - data_path = _short_path_dirname(ctxt.outputs.war) - elif data_path[0] == "/": - data_path = data_path[1:] - else: # relative path - data_path = _short_path_dirname(ctxt.outputs.war) + "/" + data_path - - war = ctxt.outputs.war - build_output = war.path + ".build_output" - cmd = [ - "set -e;rm -rf " + build_output, - "mkdir -p " + build_output - ] - - inputs = [zipper] - cmd += ["mkdir -p %s/WEB-INF/lib" % build_output] - - transitive_deps = set() - for jar in ctxt.attr.jars: - if hasattr(jar, "java"): # java_library, java_import - transitive_deps += jar.java.transitive_runtime_deps - elif hasattr(jar, "files"): # a jar file - transitive_deps += jar.files - - for dep in transitive_deps: - cmd += _add_file(dep, build_output + "/WEB-INF/lib") - inputs.append(dep) - - for jar in ctxt.files._appengine_deps: - cmd += _add_file(jar, build_output + "/WEB-INF/lib") - inputs.append(jar) - - inputs += ctxt.files.data - for res in ctxt.files.data: - # Add the data file - cmd += _add_file(res, build_output, path = data_path) - - cmd += _make_war(zipper, build_output, war) - - ctxt.action( - inputs = inputs, - outputs = [war], - mnemonic="WAR", - command="\n".join(cmd), - use_default_shell_env=True) - - executable = ctxt.outputs.executable - appengine_sdk = None - for f in ctxt.files._appengine_sdk: - if not appengine_sdk: - appengine_sdk = f.path - elif not f.path.startswith(appengine_sdk): - appengine_sdk = _common_substring(appengine_sdk, f.path) - - classpath = [ - "${JAVA_RUNFILES}/%s" % jar.short_path - for jar in ctxt.files._appengine_jars - ] - substitutions = { - "%{zipper}": ctxt.file._zipper.short_path, - "%{war}": ctxt.outputs.war.short_path, - "%{java}": ctxt.file._java.short_path, - "%{appengine_sdk}": appengine_sdk, - "%{classpath}": (":".join(classpath)), - } - ctxt.template_action( - output = executable, - template = ctxt.file._runner_template, - substitutions = substitutions, - executable = True) - ctxt.template_action( - output = ctxt.outputs.deploy, - template = ctxt.file._deploy_template, - substitutions = substitutions, - executable = True) - - runfiles = ctxt.runfiles(files = [war, executable] - + ctxt.files._appengine_sdk - + ctxt.files._appengine_jars - + [ctxt.file._java, ctxt.file._zipper]) - return struct(runfiles = runfiles) - -appengine_war = rule( - _war_impl, - attrs = { - "_java": attr.label( - default = Label("@bazel_tools//tools/jdk:java"), - single_file = True, - ), - "_zipper": attr.label( - default = Label("@bazel_tools//tools/zip:zipper"), - single_file = True, - ), - "_runner_template": attr.label( - default = Label("@bazel_tools//tools/build_rules/appengine:runner_template"), - single_file = True, - ), - "_deploy_template": attr.label( - default = Label("@bazel_tools//tools/build_rules/appengine:deploy_template"), - single_file = True, - ), - "_appengine_sdk": attr.label( - default = Label("//external:appengine/java/sdk"), - ), - "_appengine_jars": attr.label( - default = Label("//external:appengine/java/jars"), - ), - "_appengine_deps": attr.label_list( - default = [ - Label("@com_google_appengine_java//:api"), - Label("@org_apache_commons_lang//jar"), - Label("@org_apache_commons_collections//jar"), - ], - ), - "jars": attr.label_list( - allow_files = jar_filetype, - mandatory = True, - ), - "data": attr.label_list(allow_files = True), - "data_path": attr.string(), - }, - executable = True, - outputs = { - "war": "%{name}.war", - "deploy": "%{name}.deploy", - }, -) - -def java_war(name, data=[], data_path=None, **kwargs): - warning("java_war") - native.java_library(name = "lib%s" % name, **kwargs) - appengine_war(name = name, - jars = ["lib%s" % name], - data=data, - data_path=data_path) - -APPENGINE_BUILD_FILE = """ -# BUILD file to use the Java AppEngine SDK with a remote repository. -java_import( - name = "jars", - jars = glob(["**/*.jar"]), - visibility = ["//visibility:public"], -) - -java_import( - name = "api", - jars = ["appengine-java-sdk-1.9.23/lib/impl/appengine-api.jar"], - visibility = ["//visibility:public"], - neverlink = 1, -) - -filegroup( - name = "sdk", - srcs = glob(["appengine-java-sdk-1.9.23/**"]), - visibility = ["//visibility:public"], - path = "appengine-java-sdk-1.9.23", -) -""" - -def appengine_repositories(): - warning("appengine_repositories") - native.new_http_archive( - name = "com_google_appengine_java", - url = "http://central.maven.org/maven2/com/google/appengine/appengine-java-sdk/1.9.23/appengine-java-sdk-1.9.23.zip", - sha256 = "05e667036e9ef4f999b829fc08f8e5395b33a5a3c30afa9919213088db2b2e89", - build_file_content = APPENGINE_BUILD_FILE, - ) - - native.bind( - name = "appengine/java/sdk", - actual = "@com_google_appengine_java//:sdk", - ) - - native.bind( - name = "appengine/java/api", - actual = "@com_google_appengine_java//:api", - ) - - native.bind( - name = "appengine/java/jars", - actual = "@com_google_appengine_java//:jars", - ) - - native.maven_jar( - name = "javax_servlet_api", - artifact = "javax.servlet:servlet-api:2.5", - ) - - native.bind( - name = "javax/servlet/api", - actual = "@bazel_tools//tools/build_rules/appengine:javax.servlet.api", - ) - - native.maven_jar( - name = "org_apache_commons_lang", - artifact = "commons-lang:commons-lang:2.6", - ) - - native.maven_jar( - name = "org_apache_commons_collections", - artifact = "commons-collections:commons-collections:3.2.2", - ) diff --git a/tools/build_rules/appengine/appengine_deploy.sh.template b/tools/build_rules/appengine/appengine_deploy.sh.template deleted file mode 100644 index b61ddb023d..0000000000 --- a/tools/build_rules/appengine/appengine_deploy.sh.template +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -# Copyright 2015 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. - -case "$0" in -/*) self="$0" ;; -*) self="$PWD/$0";; -esac - -if [[ -z "$JAVA_RUNFILES" ]]; then - if [[ -e "${self%.deploy}.runfiles" ]]; then - JAVA_RUNFILES="${self%.deploy}.runfiles" - else - JAVA_RUNFILES=$PWD - fi -fi - -root_path=$(pwd) -tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/war.XXXXXXXX) -trap "{ cd ${root_path}; rm -rf ${tmp_dir}; }" EXIT -cd ${tmp_dir} -${JAVA_RUNFILES}/%{zipper} x ${JAVA_RUNFILES}/%{war} -cd ${root_dir} - -APP_ENGINE_ROOT=${JAVA_RUNFILES}/%{appengine_sdk} -if [ -n "${1-}" ]; then - ${APP_ENGINE_ROOT}/bin/appcfg.sh -A "$1" update ${tmp_dir} - retCode=$? -else - ${APP_ENGINE_ROOT}/bin/appcfg.sh update ${tmp_dir} - retCode=$? -fi - -rm -rf ${tmp_dir} -trap - EXIT - -exit $retCode diff --git a/tools/build_rules/appengine/appengine_runner.sh.template b/tools/build_rules/appengine/appengine_runner.sh.template deleted file mode 100644 index d6ff8215f1..0000000000 --- a/tools/build_rules/appengine/appengine_runner.sh.template +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -# Copyright 2015 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. - -case "$0" in -/*) self="$0" ;; -*) self="$PWD/$0";; -esac - -if [[ -z "$JAVA_RUNFILES" ]]; then - if [[ -e "${self}.runfiles" ]]; then - JAVA_RUNFILES="${self}.runfiles" - fi -fi - -root_path=$(pwd) -tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/war.XXXXXXXX) -trap "{ cd ${root_path}; rm -rf ${tmp_dir}; }" EXIT -cd ${tmp_dir} - -${JAVA_RUNFILES}/%{zipper} x ${JAVA_RUNFILES}/%{war} - -jvm_bin=${JAVA_RUNFILES}/%{java} -if [[ ! -x ${jvm_bin} ]]; then - jvm_bin=$(which java) -fi - -APP_ENGINE_ROOT=${JAVA_RUNFILES}/%{appengine_sdk} -main_class="com.google.appengine.tools.development.DevAppServerMain" -classpath="%{classpath}" - -${jvm_bin} -Dappengine.sdk.root=${APP_ENGINE_ROOT} -cp "${classpath}" \ - ${main_class} "$@" ${tmp_dir} -retCode=$? - -# We remove the trap so the return code doesn't get intercepted by it on OS X. -cd ${root_path} -rm -rf ${tmp_dir} -trap - EXIT - -exit $retCode diff --git a/tools/build_rules/deprecation.bzl b/tools/build_rules/deprecation.bzl deleted file mode 100644 index e85953e831..0000000000 --- a/tools/build_rules/deprecation.bzl +++ /dev/null @@ -1,27 +0,0 @@ -# -# Copyright 2016 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. - -def deprecated(language, rule, old_path, new_path): - return """This rule has moved out of @bazel_tools! - -The {0} rules have moved to https://github.com/bazelbuild/rules_{0}, you -should now refer them via @io_bazel_rules_{0}, use: - -load('{3}', '{1}') - -instead of: - -load('{2}', '{1}') -""".format(language, rule, old_path, new_path) diff --git a/tools/build_rules/go/BUILD b/tools/build_rules/go/BUILD deleted file mode 100644 index 24d5589187..0000000000 --- a/tools/build_rules/go/BUILD +++ /dev/null @@ -1,15 +0,0 @@ -package( - default_visibility = ["//visibility:public"], -) - -filegroup( - name = "srcs", - srcs = glob(["**"]) + [ - "//tools/build_rules/go/tools:srcs", - "//tools/build_rules/go/toolchain:srcs", - ], - visibility = [ - "//src:__subpackages__", - "//tools:__pkg__", - ], -) diff --git a/tools/build_rules/go/DESIGN.md b/tools/build_rules/go/DESIGN.md deleted file mode 100644 index 15015c4ae3..0000000000 --- a/tools/build_rules/go/DESIGN.md +++ /dev/null @@ -1,61 +0,0 @@ -Go support in Bazel -=================== - -Objective ---------- - -Provide Go support in Bazel that feels familiar to existing Go users and -existing Go tools. - - -Use cases ---------- - -Users might find benefit from using Bazel for Go in the following scenarios: - -* Multi-language/multi-platform builds, where not all platforms are supported by `go` natively. For example: test iOS app running against a Go backend from a single tool, or Bazel itself, where the BUILD file formatter (`buildifier`) is written Go, and Bazel (Java/C++) interact. -* Large Go projects, where correctness and scalability of `go` become a problem. -* Go projects where the executable is not the final product. -* Projects with complex native code builds, eg. a Go server that uses first party native code through CGO. -* Projects with complex code generation steps, such as protocol buffers. - -Constraints ------------ - -The Go rules should not impose restrictions on how non-Go projects should organize their source trees. - -Proposal --------- - -* Bazel will support `go_library`, `go_binary` and `go_test` rules. These take go files as srcs, and `go_library` rules as `deps`. Along with the rules, we will have a tool that generates the main.go file based on the sources of a go_test rule. -* The go rules use a global setting `GO_PREFIX`. `GO_PREFIX` is set through Bazel's `WORKSPACE` mechanism, and may be empty. It is recommended that Go projects use the canonical import name (eg. `github.com/name/project`) as `GO_PREFIX` in Bazel. -* The go rules will support dependencies on go_library targets with other names, eg. `//a/b:c`. These are to be imported as `GO_PREFIX/a/b/c`. This convention is typically used for depending on generated Go code. -* The go rules will support a magic target name `go_default_library`. A dependency on `//a/b:go_default_library` will be staged by Bazel so it can be imported in a go file as `GO_PREFIX/a/b`, rather than `GO_PREFIX/a/b/go_default_library`. -* For making Bazel work with Go, we will have a tool called `glaze`, which analyzes the Go source files in a directory, and emits a BUILD file to match. Glaze must be run by hand (or, as an editor hook) when modifying Go code. -* When Glaze encounters an import line `GO_PREFIX/a/b` for which `a/b/` is a directory, it will write a dependency on `//a/b:go_default_library`. -* If a target has a dependency that contains a `vendor` directory component, the compiler will be invoked with a corresponding `-importmap` option, eg. a dependency on `x/y/vendor/domain/p/q:target` will yield `-importmap=domain/p/q/target=GO_PREFIX/x/y/vendor/domain/p/q/target`. - * Multiple dependencies that map to the same importmap key is an analysis-time error. -* When Glaze encounters an import line that can be satisfied from a `vendor/` directory, as specified in the [Go vendoring decision](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo/), it will emit the full target name of the vendored library. - -Caveats -------- - -Is not fully compatible with the `go` tool: -* `go` still cannot handle generated source code (ie. protocol buffers) -* the workspace will need to be in a directory called `src` for `go` to work with it (possibly through a symlink) -* Does not address compatibility with `go generate`: - * Bazel puts sources and artifacts in different directories, so `go` tooling does not work out of the box if only parts of a go library are generated. - * We could export the generated sources as some sort of tree with `//go:generate` lines in the source, but the command line will not run if the generator was built by Bazel too. - * We could import generated sources by extracting `//go:generate` lines. Since the lines do not declare the sources of the invoked tooling, this will be hard to automatically get right, though. -* The `GO_PREFIX` that `WORKSPACE` sets is similar to the workspace name (see build encyclopedia), but it should only affect Go. Since Go prefixes are URLs, they contain dots, so using the `WORKSPACE` name would break Python imports. -* Does not specify how native interoperability (eg. cgo) should work. - -Implementation plan -------------------- - -* Implement `go_prefix` support in `WORKSPACE` -* Reintroduce the Skylark Go rules, but supporting `go_default_library` and `go_prefix`. -* Ship them in Bazel; this yields bare bones rules. -* Open-source the `BUILD` file formatter, and use it as basis to create `glaze`. -* Open-source compiler glue program and use it in the Skylark rules. This will yields conformance with //+ build tags, and other build system directives embedded in source code. -* Consider cleaning and opening up internal rules. diff --git a/tools/build_rules/go/README.md b/tools/build_rules/go/README.md deleted file mode 100644 index 535c2a487a..0000000000 --- a/tools/build_rules/go/README.md +++ /dev/null @@ -1,292 +0,0 @@ -# Go rules - -
-

Rules

- -
- -## Overview - -The rules should be considered experimental. They support: - -* libraries -* binaries -* tests -* vendoring - -They currently do not support (in order of importance): - -* `//+build` tags -* auto generated BUILD files. -* C/C++ interoperation (cgo, swig etc.) -* race detector -* coverage -* test sharding - -## Setup - -* Decide on the name of your package, eg. `github.com/joe/project` -* Add the following to your WORKSPACE file: - - ```python - load("@bazel_tools//tools/build_rules/go:def.bzl", "go_repositories") - - go_repositories() - ``` - -* Add a `BUILD` file to the top of your workspace, declaring the name of your - workspace using `go_prefix`. It is strongly recommended that the prefix is not - empty. - - ```python - load("@bazel_tools//tools/build_rules/go:def.bzl", "go_prefix") - - go_prefix("github.com/joe/project") - ``` - -* For a library `github.com/joe/project/lib`, create `lib/BUILD`, containing - - ```python - load("@bazel_tools//tools/build_rules/go:def.bzl", "go_library") - - go_library( - name = "go_default_library", - srcs = ["file.go"] - ) - ``` - -* Inside your project, you can use this library by declaring a dependency - - ```python - go_binary( - ... - deps = ["//lib:go_default_library"] - ) - ``` - -* In this case, import the library as `github.com/joe/project/lib`. -* For vendored libraries, you may depend on - `//lib/vendor/github.com/user/project:go_default_library`. Vendored - libraries should have BUILD files like normal libraries. -* To declare a test, - - ```python - go_test( - name = "mytest", - srcs = ["file_test.go"], - library = ":go_default_library" - ) - ``` - -## FAQ - -### Can I still use the `go` tool? - -Yes, this setup was deliberately chosen to be compatible with the `go` -tool. Make sure your workspace appears under - -```sh -$GOROOT/src/github.com/joe/project/ -``` - -eg. - -```sh -mkdir -p $GOROOT/src/github.com/joe/ -ln -s my/bazel/workspace $GOROOT/src/github.com/joe/project -``` - -and it should work. - -## Disclaimer - -These rules are not supported by Google's Go team. - - -## go\_prefix - -```python -go_prefix(prefix) -``` - - - - - - - - - - - - - - - - - -
Attributes
prefix - String, required -

Global prefix used to fully quality all Go targets.

-

- In Go, imports are always fully qualified with a URL, eg. - github.com/user/project. Hence, a label //foo:bar - from within a Bazel workspace must be referred to as - github.com/user/project/foo/bar. To make this work, each - rule must know the repository's URL. This is achieved, by having all - go rules depend on a globally unique target that has a - go_prefix transitive info provider. -

-
- - -## go\_library - -```python -go_library(name, srcs, deps, data) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
srcs - List of labels, required -

List of Go .go source files used to build the - library

-
deps - List of labels, optional -

List of other libraries to linked to this library target

-
data - List of labels, optional -

List of files needed by this rule at runtime.

-
- - -## go\_binary - -```python -go_binary(name, srcs, deps, data) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
srcs - List of labels, required -

List of Go .go source files used to build the - binary

-
deps - List of labels, optional -

List of other libraries to linked to this binary target

-
data - List of labels, optional -

List of files needed by this rule at runtime.

-
- - -## go\_test - -```python -go_test(name, srcs, deps, data) -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Attributes
name - Name, required -

A unique name for this rule.

-
srcs - List of labels, required -

List of Go .go source files used to build the - test

-
deps - List of labels, optional -

List of other libraries to linked to this test target

-
data - List of labels, optional -

List of files needed by this rule at runtime.

-
diff --git a/tools/build_rules/go/def.bzl b/tools/build_rules/go/def.bzl deleted file mode 100644 index 0527d92bc3..0000000000 --- a/tools/build_rules/go/def.bzl +++ /dev/null @@ -1,431 +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. - -"""These are bare-bones Go rules. - -In order of priority: - -- No support for build tags - -- BUILD file must be written by hand. - -- No C++ interop (SWIG, cgo). - -- No test sharding or test XML. - -""" - -load("//tools/build_rules:deprecation.bzl", "deprecated") - -def warning(rule): - print(deprecated( - "go", - rule, - "@bazel_tools//tools/build_rules/go:def.bzl", - "@io_bazel_rules_go//go:def.bzl")) - -_DEFAULT_LIB = "go_default_library" - -_VENDOR_PREFIX = "/vendor/" - -go_filetype = FileType([".go"]) - -################ - -# In Go, imports are always fully qualified with a URL, -# eg. github.com/user/project. Hence, a label //foo:bar from within a -# Bazel workspace must be referred to as -# "github.com/user/project/foo/bar". To make this work, each rule must -# know the repository's URL. This is achieved, by having all go rules -# depend on a globally unique target that has a "go_prefix" transitive -# info provider. - -def _go_prefix_impl(ctx): - """go_prefix_impl provides the go prefix to use as a transitive info provider.""" - return struct(go_prefix = ctx.attr.prefix) - -def _go_prefix(ctx): - """slash terminated go-prefix""" - warning("go_prefix") - prefix = ctx.attr.go_prefix.go_prefix - if prefix != "" and not prefix.endswith("/"): - prefix = prefix + "/" - return prefix - -_go_prefix_rule = rule( - _go_prefix_impl, - attrs = { - "prefix": attr.string(mandatory = True), - }, -) - -def go_prefix(prefix): - """go_prefix sets the Go import name to be used for this workspace.""" - _go_prefix_rule(name = "go_prefix", - prefix = prefix, - visibility = ["//visibility:public" ] - ) - -################ - -# 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 old_path, new_path in artifact_dict.items(): - 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 go_environment_vars(ctx): - """Return a map of environment variables for use with actions, based on - the arguments. Uses the ctx.fragments.cpp.cpu attribute, if present, - and picks a default of target_os="linux" and target_arch="amd64" - otherwise. - - Args: - The skylark Context. - - Returns: - A dict of environment variables for running Go tool commands that build for - the target OS and architecture. - """ - bazel_to_go_toolchain = {"k8": {"GOOS": "linux", - "GOARCH": "amd64"}, - "piii": {"GOOS": "linux", - "GOARCH": "386"}, - "darwin": {"GOOS": "darwin", - "GOARCH": "amd64"}, - "freebsd": {"GOOS": "freebsd", - "GOARCH": "amd64"}, - "armeabi-v7a": {"GOOS": "linux", - "GOARCH": "arm"}, - "arm": {"GOOS": "linux", - "GOARCH": "arm"}} - return bazel_to_go_toolchain.get(ctx.fragments.cpp.cpu, - {"GOOS": "linux", - "GOARCH": "amd64"}) - -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 - tree_layout = {} - inputs = [] - prefix = _go_prefix(ctx) - import_map = {} - 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] - - source_import = prefix + d.label.package + "/" + d.label.name - actual_import = prefix + d.label.package + "/" + d.label.name - if d.label.name == _DEFAULT_LIB: - source_import = prefix + d.label.package - - if source_import.rfind(_VENDOR_PREFIX) != -1: - source_import = source_import[len(_VENDOR_PREFIX) + source_import.rfind(_VENDOR_PREFIX):] - - if source_import != actual_import: - if source_import in import_map: - fail("duplicate import %s: adding %s and have %s" - % (source_import, actual_import, import_map[source_import])) - import_map[source_import] = actual_import - - inputs += list(sources) - for s in sources: - tree_layout[s.path] = prefix + s.path - - cmds = symlink_tree_commands(out_dir, tree_layout) - args = [ - "cd ", out_dir, "&&", - ('../' * out_depth) + ctx.file.go_tool.path, - "tool", "compile", - "-o", ('../' * out_depth) + out_lib.path, "-pack", - - # Import path. - "-I", "."] + [ - "-importmap=%s=%s" % (k,v) for k, v in import_map.items() - ] - - # Set -p to the import path of the library, ie. - # (ctx.label.package + "/" ctx.label.name) for now. - cmds += [ "export GOROOT=$(pwd)/" + ctx.file.go_tool.dirname + "/..", - ' '.join(args + cmd_helper.template(sources, prefix + "%{path}"))] - - ctx.action( - inputs = inputs + ctx.files.toolchain, - outputs = [out_lib], - mnemonic = "GoCompile", - command = " && ".join(cmds), - env = go_environment_vars(ctx)) - -def go_library_impl(ctx): - """Implements the go_library() rule.""" - warning("go_library") - - sources = set(ctx.files.srcs) - deps = ctx.attr.deps - if ctx.attr.library: - sources += ctx.attr.library.go_sources - deps += ctx.attr.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.attr.deps: - transitive_libs += dep.transitive_go_library_object - - runfiles = ctx.runfiles(collect_data = True) - return struct( - label = ctx.label, - files = set([out_lib]), - direct_deps = deps, - runfiles = runfiles, - 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 = _go_prefix(ctx) - - 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.file.go_tool.dirname + "/..", - "cd " + out_dir, - ' '.join([ - ('../' * out_depth) + ctx.file.go_tool.path, - "tool", "link", "-L", ".", - "-o", prefix + executable.path[config_strip:], - prefix + lib.path[config_strip:]])] - - ctx.action( - inputs = list(transitive_libs) + [lib] + ctx.files.toolchain, - outputs = [executable], - command = ' && '.join(cmds), - mnemonic = "GoLink", - env = go_environment_vars(ctx)) - -def go_binary_impl(ctx): - """go_binary_impl emits actions for compiling and linking a go executable.""" - warning("go_binary") - 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) - - runfiles = ctx.runfiles(collect_data = True, - files = ctx.files.data) - return struct(files = set([executable]) + lib_result.files, - runfiles = runfiles) - -def go_test_impl(ctx): - """go_test_impl implements go testing. - - It emits an action to run the test generator, and then compiles the - test into a binary.""" - - warning("go_test") - - lib_result = go_library_impl(ctx) - main_go = ctx.outputs.main_go - prefix = _go_prefix(ctx) - - 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}")) - - inputs = list(lib_result.go_sources) + list(ctx.files.toolchain) - ctx.action( - inputs = inputs, - executable = ctx.executable.test_generator, - outputs = [main_go], - mnemonic = "GoTestGenTest", - arguments = args, - env = dict(go_environment_vars(ctx), RUNDIR=ctx.label.package)) - - emit_go_compile_action( - ctx, set([main_go]), ctx.attr.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.files.data + [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", - ], - ), - "toolchain": attr.label( - default = Label("@bazel_tools//tools/build_rules/go/toolchain:toolchain"), - allow_files = True, - cfg = HOST_CFG, - ), - "go_tool": attr.label( - default = Label("@bazel_tools//tools/build_rules/go/toolchain:go_tool"), - single_file = True, - allow_files = True, - cfg = HOST_CFG, - ), - "library": attr.label( - providers = ["go_sources"], - ), - "go_prefix": attr.label( - providers = ["go_prefix"], - default = Label( - "//:go_prefix", - relative_to_caller_repository = True, - ), - allow_files = False, - cfg = HOST_CFG, - ), -} - -go_library_outputs = { - "lib": "%{name}.a", -} - -go_library = rule( - go_library_impl, - attrs = go_library_attrs, - fragments = ["cpp"], - outputs = go_library_outputs, -) - -go_binary = rule( - go_binary_impl, - attrs = go_library_attrs + { - "stamp": attr.bool(default = False), - }, - executable = True, - fragments = ["cpp"], - outputs = go_library_outputs, -) - -go_test = rule( - go_test_impl, - attrs = go_library_attrs + { - "test_generator": attr.label( - executable = True, - default = Label( - "@bazel_tools//tools/build_rules/go/tools:generate_test_main", - ), - cfg = HOST_CFG, - ), - }, - executable = True, - fragments = ["cpp"], - outputs = { - "lib": "%{name}.a", - "main_lib": "%{name}_main_test.a", - "main_go": "%{name}_main_test.go", - }, - test = True, -) - -GO_TOOLCHAIN_BUILD_FILE = """ -package( - default_visibility = [ "//visibility:public" ]) - -filegroup( - name = "toolchain", - srcs = glob(["go/bin/*", "go/pkg/**", ]), -) - -filegroup( - name = "go_tool", - srcs = [ "go/bin/go" ], -) -""" - -def go_repositories(): - warning("go_repositories") - native.new_http_archive( - name= "golang_linux_amd64", - url = "https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz", - build_file_content = GO_TOOLCHAIN_BUILD_FILE, - sha256 = "2593132ca490b9ee17509d65ee2cd078441ff544899f6afb97a03d08c25524e7" - ) - - native.new_http_archive( - name= "golang_darwin_amd64", - url = "https://storage.googleapis.com/golang/go1.5.1.darwin-amd64.tar.gz", - build_file_content = GO_TOOLCHAIN_BUILD_FILE, - sha256 = "e94487b8cd2e0239f27dc51e6c6464383b10acb491f753584605e9b28abf48fb" - ) diff --git a/tools/build_rules/go/toolchain/BUILD b/tools/build_rules/go/toolchain/BUILD deleted file mode 100644 index c3afba9268..0000000000 --- a/tools/build_rules/go/toolchain/BUILD +++ /dev/null @@ -1,42 +0,0 @@ -package( - default_visibility = ["//src:__subpackages__"], -) - -config_setting( - name = "darwin", - values = {"host_cpu": "darwin"}, -) - -config_setting( - name = "k8", - values = {"host_cpu": "k8"}, -) - -filegroup( - name = "toolchain", - srcs = select({ - ":darwin": ["@golang_darwin_amd64//:toolchain"], - ":k8": ["@golang_linux_amd64//:toolchain"], - }), - visibility = ["//visibility:public"], -) - -filegroup( - name = "go_tool", - srcs = select({ - ":darwin": ["@golang_darwin_amd64//:go_tool"], - ":k8": ["@golang_linux_amd64//:go_tool"], - }), - visibility = ["//visibility:public"], -) - -filegroup( - name = "srcs", - srcs = [ - "BUILD", - ], - visibility = [ - "//src:__subpackages__", - "//tools/build_rules/go:__pkg__", - ], -) diff --git a/tools/build_rules/go/tools/BUILD b/tools/build_rules/go/tools/BUILD deleted file mode 100644 index 1dfa4c25c4..0000000000 --- a/tools/build_rules/go/tools/BUILD +++ /dev/null @@ -1,17 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools/build_rules/go:def.bzl", "go_binary") - -# This binary is used implicitly by go_test(). -go_binary( - name = "generate_test_main", - srcs = ["generate_test_main.go"], -) - -filegroup( - name = "srcs", - srcs = [ - "BUILD", - "generate_test_main.go", - ], -) diff --git a/tools/build_rules/go/tools/filter_tags/BUILD b/tools/build_rules/go/tools/filter_tags/BUILD deleted file mode 100644 index d1dc3faaa9..0000000000 --- a/tools/build_rules/go/tools/filter_tags/BUILD +++ /dev/null @@ -1,19 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools/build_rules/go:def.bzl", "go_prefix", "go_library", "go_binary", "go_test") - -go_library( - name = "filter_tags_lib", - srcs = ["filter_tags.go"], -) - -go_binary( - name = "filter_tags", - library = ":filter_tags_lib", -) - -go_test( - name = "filter_tags_test", - srcs = ["filter_tags_test.go"], - library = ":filter_tags_lib", -) diff --git a/tools/build_rules/go/tools/filter_tags/filter_tags.go b/tools/build_rules/go/tools/filter_tags/filter_tags.go deleted file mode 100644 index 44ca6bd0b9..0000000000 --- a/tools/build_rules/go/tools/filter_tags/filter_tags.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "go/build" - "log" - "path/filepath" - "strings" -) - -// Returns an array of strings containing only the filenames that should build -// according to the Context given. -func filterFilenames(bctx build.Context, inputs []string) ([]string, error) { - outputs := []string{} - - for _, filename := range inputs { - fullPath, err := filepath.Abs(filename) - if err != nil { - return nil, err - } - dir, base := filepath.Split(fullPath) - - matches, err := bctx.MatchFile(dir, base) - if err != nil { - return nil, err - } - - if matches { - outputs = append(outputs, filename) - } - } - return outputs, nil -} - -func main() { - cgo := flag.Bool("cgo", false, "Sets whether cgo-using files are allowed to pass the filter.") - tags := flag.String("tags", "", "Only pass through files that match these tags.") - flag.Parse() - - bctx := build.Default - bctx.BuildTags = strings.Split(*tags, ",") - bctx.CgoEnabled = *cgo // Worth setting? build.MatchFile ignores this. - - outputs, err := filterFilenames(bctx, flag.Args()) - if err != nil { - log.Fatalf("build_tags error: %v\n", err) - } - - fmt.Println(strings.Join(outputs, " ")) -} diff --git a/tools/build_rules/go/tools/filter_tags/filter_tags_test.go b/tools/build_rules/go/tools/filter_tags/filter_tags_test.go deleted file mode 100644 index 652d3af1d5..0000000000 --- a/tools/build_rules/go/tools/filter_tags/filter_tags_test.go +++ /dev/null @@ -1,119 +0,0 @@ -package main - -import ( - "go/build" - "io/ioutil" - "os" - "path/filepath" - "reflect" - "testing" -) - -var testFileCGO = ` -// This file is not intended to actually build. - -package cgo - -/* -#include -#include - -void myprint(char* s) { - printf("%s", s); -} -*/ - -import "C" - -func main() { - C.myprint("hello") -} -` - -var testFileFILENAMETAG = ` -// This file is not intended to actually compile. - -package filenametag_darwin -` - -var testFileIGNORE = ` -// This file is not intended to actually build. - -//+build ignore - -package ignore -` - -var testFileTAGS = ` -// This file is not intended to actually build. - -//+build arm,darwin linux,mips - -package tags -` - -func TestTags(t *testing.T) { - tempdir, err := ioutil.TempDir("", "goruletest") - if err != nil { - t.Fatalf("Error creating temporary directory: %v", err) - } - defer os.RemoveAll(tempdir) - - for k, v := range map[string]string{ - "cgo.go": testFileCGO, - "darwin.go": testFileFILENAMETAG, - "ignore.go": testFileIGNORE, - "tags.go": testFileTAGS, - } { - p := filepath.Join(tempdir, k) - if err := ioutil.WriteFile(p, []byte(v), 0644); err != nil { - t.Fatalf("WriteFile(%s): %v", p, err) - } - } - - testContext := build.Default - wd, err := os.Getwd() - if err != nil { - t.Fatalf("Getwd: %v", err) - } - - err = os.Chdir(tempdir) - if err != nil { - t.Fatalf("Chdir(%s): %v", tempdir, err) - } - defer os.Chdir(wd) - - // Test tags.go (tags in +build comments) - testContext.BuildTags = []string{"arm", "darwin"} - inputs := []string{"tags.go"} - outputs, err := filterFilenames(testContext, inputs) - if err != nil { - t.Errorf("filterFilenames(%s): %v", inputs, err) - } - - if !reflect.DeepEqual(inputs, outputs) { - t.Error("Output missing an expected file: tags.go") - } - - testContext.BuildTags = []string{"arm, linux"} - outputs, err = filterFilenames(testContext, inputs) - if err != nil { - t.Errorf("filterFilenames(%s): %v", inputs, err) - } - - if !reflect.DeepEqual([]string{}, outputs) { - t.Error("Output contains an unexpected file: tags.go") - } - - // Test ignore.go (should not build a file with +ignore comment) - testContext.BuildTags = []string{} - inputs = []string{"ignore.go"} - outputs, err = filterFilenames(testContext, inputs) - if err != nil { - t.Errorf("filterFilenames(%s): %v", inputs, err) - } - - if !reflect.DeepEqual([]string{}, outputs) { - t.Error("Output contains an unexpected file: ignore.go") - } -} diff --git a/tools/build_rules/go/tools/generate_test_main.go b/tools/build_rules/go/tools/generate_test_main.go deleted file mode 100644 index b87022406d..0000000000 --- a/tools/build_rules/go/tools/generate_test_main.go +++ /dev/null @@ -1,95 +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 - RunDir 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, - RunDir: os.Getenv("RUNDIR"), - } - 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 ( - "os" - "testing" - - undertest "{{.Package}}" -) - -func everything(pat, str string) (bool, error) { - return true, nil -} - -var tests = []testing.InternalTest{ -{{range .Names}} - {"{{.}}", undertest.{{.}} }, -{{end}} -} - -func main() { - os.Chdir("{{.RunDir}}") - testing.Main(everything, tests, nil, nil) -} -`)) - if err := tpl.Execute(outFile, &cases); err != nil { - log.Fatalf("template.Execute(%v): %v", cases, err) - } -} -- cgit v1.2.3