From 3671ff634e85e5c3307f37e7c86d88bdf7bf911b Mon Sep 17 00:00:00 2001 From: Kristina Chodorow Date: Thu, 19 Feb 2015 18:28:40 +0000 Subject: Add symlinks to third_party/ and tools/ to base_workspace While attempting to clean up the Bazel examples, I noticed that the example tests don't actually work because they expect a third_party directory. We could link third_party/ from the top-level bazel directory, but then we'd have crossing symlinks (base_workspace/tools->tools and third_party->base_workspace/third_party). Linking everything in one direction seemed like a better option, but alternative suggestions are welcome. -- MOS_MIGRATED_REVID=86703332 --- .gitignore | 10 +- base_workspace/tools/BUILD | 1 - base_workspace/tools/build_rules/genproto.bzl | 77 ------- base_workspace/tools/build_rules/go_rules.bzl | 184 ---------------- .../tools/build_rules/java_rules_oss.bzl | 233 --------------------- base_workspace/tools/build_rules/py_rules.bzl | 122 ----------- base_workspace/tools/cpp/BUILD | 70 ------- base_workspace/tools/cpp/CROSSTOOL | 193 ----------------- base_workspace/tools/cpp/empty.cc | 19 -- base_workspace/tools/defaults/BUILD | 2 - base_workspace/tools/genrule/BUILD | 1 - base_workspace/tools/genrule/genrule-setup.sh | 0 base_workspace/tools/go/BUILD | 11 - base_workspace/tools/go/generate_test_main.go | 91 -------- base_workspace/tools/jdk/BUILD | 75 ------- base_workspace/tools/test/BUILD | 6 - base_workspace/tools/test/test-setup.sh | 16 -- compile.sh | 6 +- .../build/lib/testutil/FoundationTestCase.java | 2 +- tools/BUILD | 1 + tools/build_rules/genproto.bzl | 77 +++++++ tools/build_rules/go_rules.bzl | 184 ++++++++++++++++ tools/build_rules/java_rules_oss.bzl | 233 +++++++++++++++++++++ tools/build_rules/py_rules.bzl | 122 +++++++++++ tools/cpp/BUILD | 70 +++++++ tools/cpp/CROSSTOOL | 193 +++++++++++++++++ tools/cpp/empty.cc | 19 ++ tools/defaults/BUILD | 2 + tools/genrule/BUILD | 1 + tools/genrule/genrule-setup.sh | 0 tools/go/BUILD | 11 + tools/go/generate_test_main.go | 91 ++++++++ tools/jdk/BUILD | 75 +++++++ tools/test/BUILD | 6 + tools/test/test-setup.sh | 16 ++ 35 files changed, 1110 insertions(+), 1110 deletions(-) delete mode 100644 base_workspace/tools/BUILD delete mode 100644 base_workspace/tools/build_rules/genproto.bzl delete mode 100644 base_workspace/tools/build_rules/go_rules.bzl delete mode 100644 base_workspace/tools/build_rules/java_rules_oss.bzl delete mode 100644 base_workspace/tools/build_rules/py_rules.bzl delete mode 100644 base_workspace/tools/cpp/BUILD delete mode 100644 base_workspace/tools/cpp/CROSSTOOL delete mode 100644 base_workspace/tools/cpp/empty.cc delete mode 100644 base_workspace/tools/defaults/BUILD delete mode 100644 base_workspace/tools/genrule/BUILD delete mode 100755 base_workspace/tools/genrule/genrule-setup.sh delete mode 100644 base_workspace/tools/go/BUILD delete mode 100644 base_workspace/tools/go/generate_test_main.go delete mode 100644 base_workspace/tools/jdk/BUILD delete mode 100644 base_workspace/tools/test/BUILD delete mode 100755 base_workspace/tools/test/test-setup.sh create mode 100644 tools/BUILD create mode 100644 tools/build_rules/genproto.bzl create mode 100644 tools/build_rules/go_rules.bzl create mode 100644 tools/build_rules/java_rules_oss.bzl create mode 100644 tools/build_rules/py_rules.bzl create mode 100644 tools/cpp/BUILD create mode 100644 tools/cpp/CROSSTOOL create mode 100644 tools/cpp/empty.cc create mode 100644 tools/defaults/BUILD create mode 100644 tools/genrule/BUILD create mode 100755 tools/genrule/genrule-setup.sh create mode 100644 tools/go/BUILD create mode 100644 tools/go/generate_test_main.go create mode 100644 tools/jdk/BUILD create mode 100644 tools/test/BUILD create mode 100755 tools/test/test-setup.sh diff --git a/.gitignore b/.gitignore index e340510bee..daa603d63d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ /output/ /bazel-* /fromhost/ -/base_workspace/tools/jdk/jdk -/base_workspace/tools/java/ijar -/base_workspace/tools/java/JavaBuilder_deploy.jar -/base_workspace/tools/java/SingleJar_deploy.jar -/tools +/base_workspace/tools/ +/tools/jdk/jdk +/tools/java/ijar +/tools/java/JavaBuilder_deploy.jar +/tools/java/SingleJar_deploy.jar diff --git a/base_workspace/tools/BUILD b/base_workspace/tools/BUILD deleted file mode 100644 index ffd0fb0cdc..0000000000 --- a/base_workspace/tools/BUILD +++ /dev/null @@ -1 +0,0 @@ -package(default_visibility = ["//visibility:public"]) diff --git a/base_workspace/tools/build_rules/genproto.bzl b/base_workspace/tools/build_rules/genproto.bzl deleted file mode 100644 index 14801e3c93..0000000000 --- a/base_workspace/tools/build_rules/genproto.bzl +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is a quick and dirty rule to make Bazel compile itself. It -# only supports Java. - - -# TODO(bazel-team): unify the OSS Java rules and load from another -# file. -jar_filetype = FileType([".jar"]) - -proto_filetype = FileType([".proto"]) - -def genproto_impl(ctx): - src = ctx.file.src - proto_compiler = ctx.file._proto_compiler - proto_dep = ctx.file._proto_dep - class_jar = ctx.outputs.java - proto_output = class_jar.path + ".proto_output" - build_output = class_jar.path + ".build_output" - - inputs = [src, proto_dep, proto_compiler] - proto_compiler_path = proto_compiler.path - - javapath = "tools/jdk/jdk/bin/" - cmd = ("set -e;" + - "rm -rf " + proto_output + ";" + - "mkdir " + proto_output + ";" + - "rm -rf " + build_output + ";" + - "mkdir " + build_output + "\n" + - proto_compiler_path + " --java_out=" + - proto_output +" " + src.path + "\n" + - "JAVA_FILES=$(find " + proto_output + " -name '*.java')\n" + - javapath + "javac" + " -classpath " + proto_dep.path + - " ${JAVA_FILES} -d " + build_output + "\n" + - javapath + "jar cf " + class_jar.path + " -C " + build_output + " .\n") - ctx.action( - inputs = inputs, - outputs = [class_jar], - mnemonic = 'CompileProtos', - command = cmd, - use_default_shell_env = True) - - return struct(compile_time_jars = set([class_jar]), - runtime_jars = set([class_jar, proto_dep], order="link")) - - -genproto = rule(genproto_impl, - # There should be a flag like gen_java, and only generate the jar if it's - # set. Skylark needs a bit of improvement first (concat structs). - attrs = { - "src": attr.label(allow_files=proto_filetype, single_file=True), - # TODO(bazel-team): this should be a hidden attribute with a default - # value, but Skylark needs to support select first. - "_proto_compiler": attr.label( - default=Label("//third_party:protoc"), - allow_files=True, - single_file=True), - "_proto_dep": attr.label( - default=Label("//third_party:protobuf"), - single_file=True, - allow_files=jar_filetype, - ), - }, - outputs = {"java": "lib%{name}.jar"}, -) diff --git a/base_workspace/tools/build_rules/go_rules.bzl b/base_workspace/tools/build_rules/go_rules.bzl deleted file mode 100644 index ae218ccd39..0000000000 --- a/base_workspace/tools/build_rules/go_rules.bzl +++ /dev/null @@ -1,184 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""These are bare-bones Go rules. - -Several issues: - -- For "a/b/c.go", the go tool creates library "a/b.a" with import path -"a/b". We can probably simulate this with symlink trees. - -- Dependencies are not enforced; a symlink tree might help here too. - -- Hardcoded to 6g from the GC suite. We should be able to support GCC - and derive 6g from the CPU (from which configuration?) - -- It would be nice to be able to create a full-fledged Go - configuration in Skylark. - -- It would be nice to support zero-configuration -go_library()/go_binary()/go_test() rules: - - * name defaults to basename of directory - * srcs defaults to *.go - -- does not support checked in compilers. - -- No C++ interop. - -- deps must be populated by hand. - -- go_test must have both test and non-test files in srcs. -""" - -go_filetype = FileType([".go"]) -go_lib_filetype = FileType([".a"]) - - -def go_compile_command(ctx, sources, out_lib): - args = [ - ctx.files.go_root[0].path + "/bin/go", - - "tool", "6g", - "-o", out_lib.path, "-pack", - - # Import path. - "-I", ctx.configuration.bin_dir.path] - - # Set -p to the import path of the library, ie. - # (ctx.label.package + "/" ctx.label.name) for now. - return ' '.join(args + cmd_helper.template(sources, "%{path}")) - -def go_library_impl(ctx): - sources = ctx.files.srcs - if not sources: - fail("may not be empty", "srcs") - - out_lib = ctx.outputs.lib - - ctx.action( - inputs = sources + ctx.files.deps, - outputs = [out_lib], - mnemonic = "GoCompile", - env = { - "GOROOT": ctx.files.go_root[0].path, - }, - command = go_compile_command(ctx, set(sources), out_lib)) - - out_nset = set([out_lib]) - return struct( - files = out_nset, - go_library_object = out_nset) - - -def go_link_action(ctx, lib, executable): - cmd = ' '.join([ - ctx.files.go_root[0].path + "/bin/go", - "tool", "6l", - # Link search path. - "-L", ctx.configuration.bin_dir.path, - "-o", executable.path, - lib.path]) - ctx.action( - inputs = [lib], - outputs = [executable], - command = cmd, - env = { - "GOROOT": ctx.files.go_root[0].path, - }, - mnemonic = "GoLink") - - -def go_binary_impl(ctx): - lib_result = go_library_impl(ctx) - executable = ctx.outputs.executable - lib_out = ctx.outputs.lib - - go_link_action(ctx, lib_out, executable) - return struct(files = set([executable]) + lib_result.files) - - -def go_test_impl(ctx): - lib_result = go_library_impl(ctx) - main_go = ctx.outputs.main_go - - go_import = ctx.label.package + "/" + ctx.label.name - - # Would be nice to use transitive info provider to get at sources of - # a dependent library. - sources = ctx.files.srcs - args = (["--package", go_import, "--output", ctx.outputs.main_go.path] + - cmd_helper.template(set(sources), "%{path}")) - - ctx.action( - inputs = sources, - executable = ctx.executable.test_generator, - outputs = [main_go], - mnemonic = "GoTestGenTest", - arguments = args) - - ctx.action( - inputs = [main_go, ctx.outputs.lib], - outputs = [ctx.outputs.main_lib], - command = go_compile_command(ctx, set([main_go]), ctx.outputs.main_lib), - env = { - "GOROOT": ctx.files.go_root[0].path, - }, - mnemonic = "GoCompileTest") - - go_link_action(ctx, ctx.outputs.main_lib, ctx.outputs.executable) - - runfiles = ctx.runfiles(collect_data = True, files = [ctx.outputs.executable]) - return struct(runfiles=runfiles) - -go_library_attrs = { - "data": attr.label_list(allow_files=True, cfg=DATA_CFG), - "srcs": attr.label_list(allow_files=go_filetype), - "deps": attr.label_list( - providers=["go_library_object"]), - "go_root": attr.label( - default=Label("//tools/go:go_root"), - allow_files=True, - cfg=HOST_CFG), - } - -go_library_outputs = { - "lib": "%{name}.a", - } - -go_library = rule( - go_library_impl, - attrs = go_library_attrs, - outputs =go_library_outputs) - -go_binary = rule( - go_binary_impl, - executable = True, - attrs = go_library_attrs, - outputs = go_library_outputs) - -go_test = rule( - go_test_impl, - executable = True, - test = True, - attrs = go_library_attrs + { - "test_generator": attr.label( - default=Label("//tools/go:generate_test_main"), - cfg=HOST_CFG, flags=["EXECUTABLE"]) - }, - outputs = { - "lib" : "%{name}.a", - "main_lib": "%{name}_main_test.a", - "main_go": "%{name}_main_test.go", - }) diff --git a/base_workspace/tools/build_rules/java_rules_oss.bzl b/base_workspace/tools/build_rules/java_rules_oss.bzl deleted file mode 100644 index dcd2329ebc..0000000000 --- a/base_workspace/tools/build_rules/java_rules_oss.bzl +++ /dev/null @@ -1,233 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -java_filetype = FileType([".java"]) -jar_filetype = FileType([".jar"]) -srcjar_filetype = FileType([".jar", ".srcjar"]) - -JAVA_PATH='tools/jdk/jdk/bin/' - -def is_windows(config): - return config.fragment(cpp).compiler.startswith("windows_") - -def path_separator(ctx): - if is_windows(ctx.configuration): - return ";" - else: - return ":" - -# This is a quick and dirty rule to make Bazel compile itself. It's not -# production ready. - -def java_library_impl(ctx): - class_jar = ctx.outputs.class_jar - compile_time_jars = set(order="link") - runtime_jars = set(order="link") - for dep in ctx.targets.deps: - compile_time_jars += dep.compile_time_jars - runtime_jars += dep.runtime_jars - - jars = jar_filetype.filter(ctx.files.jars) - compile_time_jars += jars - runtime_jars += jars - compile_time_jars_list = list(compile_time_jars) # TODO: This is weird. - - build_output = class_jar.path + ".build_output" - sources = ctx.files.srcs - - sources_param_file = ctx.new_file( - ctx.configuration.bin_dir, class_jar, "-2.params") - ctx.file_action( - output = sources_param_file, - content = cmd_helper.join_paths("\n", set(sources)), - executable = False) - - # Cleaning build output directory - cmd = "set -e;rm -rf " + build_output + ";mkdir " + build_output + "\n" - if ctx.files.srcs: - cmd += JAVA_PATH + "javac" - if compile_time_jars: - cmd += " -classpath '" + cmd_helper.join_paths(path_separator(ctx), compile_time_jars) + "'" - cmd += " -d " + build_output + " @" + sources_param_file.path + "\n" - - # We haven't got a good story for where these should end up, so - # stick them in the root of the jar. - for r in ctx.files.resources: - cmd += "cp %s %s\n" % (r.path, build_output) - cmd += (JAVA_PATH + "jar cf " + class_jar.path + " -C " + build_output + " .\n" + - "touch " + build_output + "\n") - ctx.action( - inputs = (sources + compile_time_jars_list + [sources_param_file] + - ctx.files.resources), - outputs = [class_jar], - mnemonic='Javac', - command=cmd, - use_default_shell_env=True) - - runfiles = ctx.runfiles(collect_data = True) - - return struct(files = set([class_jar]), - compile_time_jars = compile_time_jars + [class_jar], - runtime_jars = runtime_jars + [class_jar], - runfiles = runfiles) - - -def java_binary_impl(ctx): - library_result = java_library_impl(ctx) - - deploy_jar = ctx.outputs.deploy_jar - manifest = ctx.outputs.manifest - build_output = deploy_jar.path + ".build_output" - main_class = ctx.attr.main_class - ctx.file_action( - output = manifest, - content = "Main-Class: " + main_class + "\n", - executable = False) - - # Cleaning build output directory - cmd = "set -e;rm -rf " + build_output + ";mkdir " + build_output + "\n" - for jar in library_result.runtime_jars: - cmd += "unzip -qn " + jar.path + " -d " + build_output + "\n" - cmd += (JAVA_PATH + "jar cmf " + manifest.path + " " + - deploy_jar.path + " -C " + build_output + " .\n" + - "touch " + build_output + "\n") - - ctx.action( - inputs=list(library_result.runtime_jars) + [manifest], - outputs=[deploy_jar], - mnemonic='Deployjar', - command=cmd, - use_default_shell_env=True) - - # Write the wrapper. - executable = ctx.outputs.executable - ctx.file_action( - output = executable, - content = '\n'.join([ - "#!/bin/bash", - "# autogenerated - do not edit.", - "case \"$0\" in", - "/*) self=\"$0\" ;;", - "*) self=\"$PWD/$0\";;", - "esac", - "", - "if [[ -z \"$JAVA_RUNFILES\" ]]; then", - " if [[ -e \"${self}.runfiles\" ]]; then", - " export JAVA_RUNFILES=\"${self}.runfiles\"", - " fi", - " if [[ -n \"$JAVA_RUNFILES\" ]]; then", - " export TEST_SRCDIR=${TEST_SRCDIR:-$JAVA_RUNFILES}", - " fi", - "fi", - "", - - "jvm_bin=%s" % (ctx.file.javabin.path), - "if [[ ! -x ${jvm_bin} ]]; then", - " jvm_bin=$(which java)", - "fi", - - # We extract the .so into a temp dir. If only we could mmap - # directly from the zip file. - "DEPLOY=$(dirname $self)/$(basename %s)" % deploy_jar.path, - - # This works both on Darwin and Linux, with the darwin path - # looking like tmp.XXXXXXXX.{random} - "SO_DIR=$(mktemp -d -t tmp.XXXXXXXXX)", - "function cleanup() {", - " rm -rf ${SO_DIR}", - "}", - "trap cleanup EXIT", - "unzip -q -d ${SO_DIR} ${DEPLOY} \"*.so\" \"*.dll\" \"*.dylib\" >& /dev/null", - ("${jvm_bin} -Djava.library.path=${SO_DIR} %s -jar $DEPLOY \"$@\"" - % ' '.join(ctx.attr.jvm_flags)) , - "", - ]), - executable = True) - - runfiles = ctx.runfiles(files = [ - deploy_jar, executable] + ctx.files.jvm, collect_data = True) - files_to_build = set([deploy_jar, manifest, executable]) - files_to_build += library_result.files - - return struct(files = files_to_build, runfiles = runfiles) - - -def java_import_impl(ctx): - # TODO(bazel-team): Why do we need to filter here? The attribute - # already says only jars are allowed. - jars = set(jar_filetype.filter(ctx.files.jars)) - runfiles = ctx.runfiles(collect_data = True) - return struct(files = jars, - compile_time_jars = jars, - runtime_jars = jars, - runfiles = runfiles) - - -java_library_attrs = { - "data": attr.label_list(allow_files=True, cfg=DATA_CFG), - "resources": attr.label_list(allow_files=True), - "srcs": attr.label_list(allow_files=java_filetype), - "jars": attr.label_list(allow_files=jar_filetype), - "deps": attr.label_list( - allow_files=False, - providers = ["compile_time_jars", "runtime_jars"]), - } - -java_library = rule( - java_library_impl, - attrs = java_library_attrs, - outputs = { - "class_jar": "lib%{name}.jar", - }) - -java_binary_attrs_common = java_library_attrs + { - "jvm_flags": attr.string_list(), - "jvm": attr.label(default=Label("//tools/jdk:jdk"), allow_files=True), - "javabin": attr.label(default=Label("//tools/jdk:java"), single_file=True), - "args": attr.string_list(), -} - -java_binary_attrs = java_binary_attrs_common + { - "main_class": attr.string(mandatory=True), -} - -java_binary_outputs = { - "class_jar": "lib%{name}.jar", - "deploy_jar": "%{name}_deploy.jar", - "manifest": "%{name}_MANIFEST.MF" -} - -java_binary = rule(java_binary_impl, - executable = True, - attrs = java_binary_attrs, - outputs = java_binary_outputs) - -java_test = rule(java_binary_impl, - executable = True, - attrs = java_binary_attrs_common + { - "main_class": attr.string(default="org.junit.runner.JUnitCore"), - # TODO(bazel-team): it would be better if we could offer a - # test_class attribute, but the "args" attribute is hard - # coded in the bazel infrastructure. - }, - outputs = java_binary_outputs, - test = True, -) - -java_import = rule( - java_import_impl, - attrs = { - "jars": attr.label_list(allow_files=jar_filetype), - "srcjar": attr.label(allow_files=srcjar_filetype), - }) diff --git a/base_workspace/tools/build_rules/py_rules.bzl b/base_workspace/tools/build_rules/py_rules.bzl deleted file mode 100644 index ddd43df75d..0000000000 --- a/base_workspace/tools/build_rules/py_rules.bzl +++ /dev/null @@ -1,122 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -ZIP_PATH = "/usr/bin/zip" - -py_file_types = FileType([".py"]) - - -def collect_transitive_sources(ctx): - source_files = set(order="compile") - for dep in ctx.targets.deps: - source_files += dep.transitive_py_files - - source_files += py_file_types.filter(ctx.files.srcs) - return source_files - - -def py_library_impl(ctx): - transitive_sources = collect_transitive_sources(ctx) - return struct( - files = set(), - transitive_py_files = transitive_sources) - - -def py_binary_impl(ctx): - main_file = py_file_types.filter(ctx.files.srcs)[0] - transitive_sources = collect_transitive_sources(ctx) - deploy_zip = ctx.outputs.deploy_zip - - deploy_zip_nomain = ctx.new_file( - ctx.configuration.bin_dir, deploy_zip, ".nomain.zip") - - # This is not very scalable, because we just construct a huge string instead - # of using a nested set. We need to do it this way because Skylark currently - # does not support actions with non-artifact executables but with an - # argument list (instead of just a single command) - command = ZIP_PATH +" -q " + deploy_zip_nomain.path + " " + " ".join([f.path for f in transitive_sources]) - ctx.action( - inputs = list(transitive_sources), - outputs = [ deploy_zip_nomain ], - mnemonic = "PyZip", - command = command, - use_default_shell_env = False) - - dirs = [f.path[:f.path.rfind('/')] for f in transitive_sources] - outdir = deploy_zip.path + ".out" - - # Add __init__.py files and the __main__.py driver. - main_cmd = ("mkdir %s && " % outdir + - " cp %s %s/__main__.py && " % (main_file.path, outdir) + - " cp %s %s/main.zip && " % (deploy_zip_nomain.path, outdir) + - " (cd %s && " % outdir + - " mkdir -p %s && " % " ".join(dirs) + - " find -type d -exec touch -t 198001010000 '{}'/__init__.py ';' && " + - " chmod +w main.zip && " + - " %s -qR main.zip $(find -type f ) ) && " % (ZIP_PATH) + - " mv %s/main.zip %s " % (outdir, deploy_zip.path)) - - ctx.action( - inputs = [ deploy_zip_nomain, main_file ], - outputs = [ deploy_zip ], - mnemonic = "PyZipMain", - command = main_cmd) - - executable = ctx.outputs.executable - ctx.action( - inputs = [ deploy_zip, ], - outputs = [ executable, ], - command = "echo '#!/usr/bin/env python' | cat - %s > %s && chmod +x %s" % ( - deploy_zip.path, executable.path, executable.path)) - - runfiles_files = transitive_sources + [executable] - - runfiles = ctx.runfiles(transitive_files = runfiles_files, - collect_default = True) - - files_to_build = set([deploy_zip, executable]) - return struct(files = files_to_build, runfiles = runfiles) - - -py_srcs_attr = attr.label_list( - flags=["DIRECT_COMPILE_TIME_INPUT"], - allow_files = py_file_types) - -py_deps_attr = attr.label_list( - providers = ["transitive_py_files"], - allow_files = False) - -py_attrs = { - "srcs": py_srcs_attr, - "deps": py_deps_attr } - -py_library = rule( - py_library_impl, - attrs = py_attrs) - -py_binary_outputs = { - "deploy_zip": "%{name}.zip" - } - -py_binary = rule( - py_binary_impl, - executable = True, - attrs = py_attrs, - outputs = py_binary_outputs) - -py_test = rule( - py_binary_impl, - executable = True, - attrs = py_attrs, - outputs = py_binary_outputs) diff --git a/base_workspace/tools/cpp/BUILD b/base_workspace/tools/cpp/BUILD deleted file mode 100644 index b3f32c9609..0000000000 --- a/base_workspace/tools/cpp/BUILD +++ /dev/null @@ -1,70 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -# TODO(bazel-team): The MacOS tools give an error if there is no object file on -# the command line to libtool, so we use an empty .cc file here. We should find -# a better way to handle this case. -cc_library( - name = "malloc", - srcs = ["empty.cc"], -) - -cc_library( - name = "stl", - srcs = ["empty.cc"], -) - -filegroup( - name = "empty", - srcs = [], -) - -filegroup( - name = "toolchain", - srcs = [ - ":cc-compiler-local", - ":cc-compiler-darwin", - ":empty", - ], -) - -cc_toolchain( - name = "cc-compiler-local", - all_files = ":empty", - compiler_files = ":empty", - cpu = "local", - dwp_files = ":empty", - dynamic_runtime_libs = [":empty"], - linker_files = ":empty", - objcopy_files = ":empty", - static_runtime_libs = [":empty"], - strip_files = ":empty", - supports_param_files = 0, -) - -cc_toolchain( - name = "cc-compiler-k8", - all_files = ":empty", - compiler_files = ":empty", - cpu = "local", - dwp_files = ":empty", - dynamic_runtime_libs = [":empty"], - linker_files = ":empty", - objcopy_files = ":empty", - static_runtime_libs = [":empty"], - strip_files = ":empty", - supports_param_files = 0, -) - -cc_toolchain( - name = "cc-compiler-darwin", - all_files = ":empty", - compiler_files = ":empty", - cpu = "darwin", - dwp_files = ":empty", - dynamic_runtime_libs = [":empty"], - linker_files = ":empty", - objcopy_files = ":empty", - static_runtime_libs = [":empty"], - strip_files = ":empty", - supports_param_files = 0, -) diff --git a/base_workspace/tools/cpp/CROSSTOOL b/base_workspace/tools/cpp/CROSSTOOL deleted file mode 100644 index 7287bc49ba..0000000000 --- a/base_workspace/tools/cpp/CROSSTOOL +++ /dev/null @@ -1,193 +0,0 @@ -major_version: "local" -minor_version: "" -default_target_cpu: "k8" -default_toolchain { - cpu: "k8" - toolchain_identifier: "local_linux" -} -default_toolchain { - cpu: "darwin" - toolchain_identifier: "local_darwin" -} - -toolchain { - abi_version: "local" - abi_libc_version: "local" - builtin_sysroot: "" - compiler: "compiler" - host_system_name: "local" - needsPic: true - supports_gold_linker: false - supports_incremental_linker: false - supports_fission: false - supports_interface_shared_objects: false - supports_normalizing_ar: false - supports_start_end_lib: false - supports_thin_archives: false - target_libc: "local" - target_cpu: "local" - target_system_name: "local" - toolchain_identifier: "local_linux" - - tool_path { name: "ar" path: "/usr/bin/ar" } - tool_path { name: "compat-ld" path: "/usr/bin/ld" } - tool_path { name: "cpp" path: "/usr/bin/cpp" } - tool_path { name: "dwp" path: "/usr/bin/dwp" } - tool_path { name: "gcc" path: "/usr/bin/gcc" } - cxx_flag: "-std=c++0x" - linker_flag: "-lstdc++" - # TODO(bazel-team): In theory, the path here ought to exactly match the path - # used by gcc. That works because bazel currently doesn't track files at - # absolute locations and has no remote execution, yet. However, this will need - # to be fixed, maybe with auto-detection? - cxx_builtin_include_directory: "/usr/lib/gcc/" - cxx_builtin_include_directory: "/usr/local/include" - cxx_builtin_include_directory: "/usr/include" - tool_path { name: "gcov" path: "/usr/bin/gcov" } - tool_path { name: "ld" path: "/usr/bin/ld" } - tool_path { name: "nm" path: "/usr/bin/nm" } - tool_path { name: "objcopy" path: "/usr/bin/objcopy" } - objcopy_embed_flag: "-I" - objcopy_embed_flag: "binary" - tool_path { name: "objdump" path: "/usr/bin/objdump" } - tool_path { name: "strip" path: "/usr/bin/strip" } -} - -toolchain { - abi_version: "local" - abi_libc_version: "local" - builtin_sysroot: "" - compiler: "compiler" - host_system_name: "local" - needsPic: true - target_libc: "macosx" - target_cpu: "darwin" - target_system_name: "local" - toolchain_identifier: "local_darwin" - - tool_path { name: "ar" path: "/usr/bin/libtool" } - tool_path { name: "compat-ld" path: "/usr/bin/ld" } - tool_path { name: "cpp" path: "/usr/bin/cpp" } - tool_path { name: "dwp" path: "/usr/bin/dwp" } - tool_path { name: "gcc" path: "/usr/bin/gcc" } - cxx_flag: "-std=c++0x" - ar_flag: "-static" - ar_flag: "-s" - ar_flag: "-o" - linker_flag: "-lstdc++" - cxx_builtin_include_directory: "/usr/include" - cxx_builtin_include_directory: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain" - cxx_builtin_include_directory: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs" - cxx_builtin_include_directory: "/opt/local/include" - cxx_builtin_include_directory: "/Library/Developer/CommandLineTools" - tool_path { name: "gcov" path: "/usr/bin/gcov" } - tool_path { name: "ld" path: "/usr/bin/ld" } - tool_path { name: "nm" path: "/usr/bin/nm" } - tool_path { name: "objcopy" path: "/usr/bin/objcopy" } - objcopy_embed_flag: "-I" - objcopy_embed_flag: "binary" - tool_path { name: "objdump" path: "/usr/bin/objdump" } - tool_path { name: "strip" path: "/usr/bin/strip" } -} - -toolchain { - abi_version: "local" - abi_libc_version: "local" - builtin_sysroot: "" - compiler: "windows_mingw" - host_system_name: "local" - needsPic: false - target_libc: "local" - target_cpu: "k8" - target_system_name: "local" - toolchain_identifier: "local_windows_mingw" - - tool_path { name: "ar" path: "C:/mingw/bin/ar" } - tool_path { name: "compat-ld" path: "C:/mingw/bin/ld" } - tool_path { name: "cpp" path: "C:/mingw/bin/cpp" } - tool_path { name: "dwp" path: "C:/mingw/bin/dwp" } - tool_path { name: "gcc" path: "C:/mingw/bin/gcc" } - cxx_flag: "-std=c++0x" - # TODO(bazel-team): In theory, the path here ought to exactly match the path - # used by gcc. That works because bazel currently doesn't track files at - # absolute locations and has no remote execution, yet. However, this will need - # to be fixed, maybe with auto-detection? - cxx_builtin_include_directory: "C:/mingw/include" - cxx_builtin_include_directory: "C:/mingw/lib/gcc" - tool_path { name: "gcov" path: "C:/mingw/bin/gcov" } - tool_path { name: "ld" path: "C:/mingw/bin/ld" } - tool_path { name: "nm" path: "C:/mingw/bin/nm" } - tool_path { name: "objcopy" path: "C:/mingw/bin/objcopy" } - objcopy_embed_flag: "-I" - objcopy_embed_flag: "binary" - tool_path { name: "objdump" path: "C:/mingw/bin/objdump" } - tool_path { name: "strip" path: "C:/mingw/bin/strip" } -} - -toolchain { - abi_version: "local" - abi_libc_version: "local" - builtin_sysroot: "" - compiler: "windows_msys64_mingw64" - host_system_name: "local" - needsPic: false - target_libc: "local" - target_cpu: "k8" - target_system_name: "local" - toolchain_identifier: "local_windows_msys64_mingw64" - - tool_path { name: "ar" path: "C:/msys64/mingw64/bin/ar" } - tool_path { name: "compat-ld" path: "C:/msys64/mingw64/bin/ld" } - tool_path { name: "cpp" path: "C:/msys64/mingw64/bin/cpp" } - tool_path { name: "dwp" path: "C:/msys64/mingw64/bin/dwp" } - tool_path { name: "gcc" path: "C:/msys64/mingw64/bin/gcc" } - cxx_flag: "-std=c++0x" - # TODO(bazel-team): In theory, the path here ought to exactly match the path - # used by gcc. That works because bazel currently doesn't track files at - # absolute locations and has no remote execution, yet. However, this will need - # to be fixed, maybe with auto-detection? - cxx_builtin_include_directory: "C:/msys64/mingw64/x86_64-w64-mingw32/include" - tool_path { name: "gcov" path: "C:/msys64/mingw64/bin/gcov" } - tool_path { name: "ld" path: "C:/msys64/mingw64/bin/ld" } - tool_path { name: "nm" path: "C:/msys64/mingw64/bin/nm" } - tool_path { name: "objcopy" path: "C:/msys64/mingw64/bin/objcopy" } - objcopy_embed_flag: "-I" - objcopy_embed_flag: "binary" - tool_path { name: "objdump" path: "C:/msys64/mingw64/bin/objdump" } - tool_path { name: "strip" path: "C:/msys64/mingw64/bin/strip" } -} - -toolchain { - abi_version: "local" - abi_libc_version: "local" - builtin_sysroot: "" - compiler: "windows_clang" - host_system_name: "local" - needsPic: false - target_libc: "local" - target_cpu: "k8" - target_system_name: "local" - toolchain_identifier: "local_windows_clang" - - tool_path { name: "ar" path: "C:/mingw/bin/ar" } - tool_path { name: "compat-ld" path: "C:/Program Files (x86)/LLVM/bin/ld" } - tool_path { name: "cpp" path: "C:/Program Files (x86)/LLVM/bin/cpp" } - tool_path { name: "dwp" path: "C:/Program Files (x86)/LLVM/bin/dwp" } - tool_path { name: "gcc" path: "C:/Program Files (x86)/LLVM/bin/clang" } - cxx_flag: "-std=c++0x" - # TODO(bazel-team): In theory, the path here ought to exactly match the path - # used by gcc. That works because bazel currently doesn't track files at - # absolute locations and has no remote execution, yet. However, this will need - # to be fixed, maybe with auto-detection? - cxx_builtin_include_directory: "/usr/lib/gcc/" - cxx_builtin_include_directory: "/usr/local/include" - cxx_builtin_include_directory: "/usr/include" - tool_path { name: "gcov" path: "C:/Program Files (x86)/LLVM/bin/gcov" } - tool_path { name: "ld" path: "C:/Program Files (x86)/LLVM/bin/ld" } - tool_path { name: "nm" path: "C:/Program Files (x86)/LLVM/bin/nm" } - tool_path { name: "objcopy" path: "C:/Program Files (x86)/LLVM/bin/objcopy" } - objcopy_embed_flag: "-I" - objcopy_embed_flag: "binary" - tool_path { name: "objdump" path: "C:/Program Files (x86)/LLVM/bin/objdump" } - tool_path { name: "strip" path: "C:/Program Files (x86)/LLVM/bin/strip" } -} diff --git a/base_workspace/tools/cpp/empty.cc b/base_workspace/tools/cpp/empty.cc deleted file mode 100644 index 7309f1cff2..0000000000 --- a/base_workspace/tools/cpp/empty.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 Google Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -// -// Workaround for the problem that MacOS tools give an error if there is no -// object file on the command line. -// diff --git a/base_workspace/tools/defaults/BUILD b/base_workspace/tools/defaults/BUILD deleted file mode 100644 index fab37b3da7..0000000000 --- a/base_workspace/tools/defaults/BUILD +++ /dev/null @@ -1,2 +0,0 @@ -# At runtime, a package is synthesized in memory that corresponds -# the command-line flag settings. diff --git a/base_workspace/tools/genrule/BUILD b/base_workspace/tools/genrule/BUILD deleted file mode 100644 index 318ebb0410..0000000000 --- a/base_workspace/tools/genrule/BUILD +++ /dev/null @@ -1 +0,0 @@ -exports_files(["genrule-setup.sh"]) diff --git a/base_workspace/tools/genrule/genrule-setup.sh b/base_workspace/tools/genrule/genrule-setup.sh deleted file mode 100755 index e69de29bb2..0000000000 diff --git a/base_workspace/tools/go/BUILD b/base_workspace/tools/go/BUILD deleted file mode 100644 index de99b06eac..0000000000 --- a/base_workspace/tools/go/BUILD +++ /dev/null @@ -1,11 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("tools/build_rules/go_rules", "go_binary", "go_library") - -# This should be a symlink to a GOROOT holding bin/ and pkg/ -exports_files(srcs = ["go_root"]) - -go_binary( - name = "generate_test_main", - srcs = ["generate_test_main.go"], -) diff --git a/base_workspace/tools/go/generate_test_main.go b/base_workspace/tools/go/generate_test_main.go deleted file mode 100644 index 6316802dde..0000000000 --- a/base_workspace/tools/go/generate_test_main.go +++ /dev/null @@ -1,91 +0,0 @@ -// Bare bones Go testing support for Bazel. - -package main - -import ( - "flag" - "go/ast" - "go/parser" - "go/token" - "log" - "os" - "strings" - "text/template" -) - -// Cases holds template data. -type Cases struct { - Package string - Names []string -} - -func main() { - pkg := flag.String("package", "", "package from which to import test methods.") - out := flag.String("output", "", "output file to write. Defaults to stdout.") - flag.Parse() - - if *pkg == "" { - log.Fatal("must set --package.") - } - - outFile := os.Stdout - if *out != "" { - var err error - outFile, err = os.Create(*out) - if err != nil { - log.Fatalf("os.Create(%q): %v", *out, err) - } - defer outFile.Close() - } - - cases := Cases{ - Package: *pkg, - } - testFileSet := token.NewFileSet() - for _, f := range flag.Args() { - parse, err := parser.ParseFile(testFileSet, f, nil, parser.ParseComments) - if err != nil { - log.Fatalf("ParseFile(%q): %v", f, err) - } - - for _, d := range parse.Decls { - fn, ok := d.(*ast.FuncDecl) - if !ok { - continue - } - if fn.Recv != nil { - continue - } - if !strings.HasPrefix(fn.Name.Name, "Test") { - continue - } - cases.Names = append(cases.Names, fn.Name.Name) - } - } - - tpl := template.Must(template.New("source").Parse(` -package main -import ( - "testing" - - undertest "{{.Package}}" -) - -func everything(pat, str string) (bool, error) { - return true, nil -} - -var tests = []testing.InternalTest{ -{{range .Names}} - {"{{.}}", undertest.{{.}} }, -{{end}} -} - -func main() { - testing.Main(everything, tests, nil, nil) -} -`)) - if err := tpl.Execute(outFile, &cases); err != nil { - log.Fatalf("template.Execute(%v): %v", cases, err) - } -} diff --git a/base_workspace/tools/jdk/BUILD b/base_workspace/tools/jdk/BUILD deleted file mode 100644 index 89241c1aa5..0000000000 --- a/base_workspace/tools/jdk/BUILD +++ /dev/null @@ -1,75 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "jni_header", - srcs = ["jdk/include/jni.h"], -) - -filegroup( - name = "jni_md_header-darwin", - srcs = ["jdk/include/darwin/jni_md.h"], -) - -filegroup( - name = "jni_md_header-linux", - srcs = ["jdk/include/linux/jni_md.h"], -) - -filegroup( - name = "java", - srcs = ["jdk/jre/bin/java"], -) - -BOOTCLASS_JARS = [ - "rt.jar", - "resources.jar", - "jsse.jar", - "jce.jar", - "charsets.jar", -] - -filegroup( - name = "bootclasspath", - srcs = ["jdk/jre/lib/%s" % jar for jar in BOOTCLASS_JARS], -) - -filegroup( - name = "langtools", - srcs = ["jdk/lib/tools.jar"], -) - -java_import( - name = "langtools-neverlink", - jars = ["jdk/lib/tools.jar"], - neverlink = 1, -) - -# This one is just needed because of how filegroup redirection works. -filegroup(name = "jdk-null") - -filegroup( - name = "jdk-default", - srcs = [":java"], - path = "jdk/jre", -) - -filegroup( - name = "jdk", - srcs = [ - ":jdk-default", - ":jdk-null", - ], -) - -java_toolchain( - name = "toolchain", - encoding = "UTF-8", - source_version = "8", - target_version = "8", -) - -exports_files([ - "JavaBuilder_deploy.jar", - "ijar", - "SingleJar_deploy.jar", -]) diff --git a/base_workspace/tools/test/BUILD b/base_workspace/tools/test/BUILD deleted file mode 100644 index db26d3bb78..0000000000 --- a/base_workspace/tools/test/BUILD +++ /dev/null @@ -1,6 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "runtime", - srcs = ["test-setup.sh"], -) diff --git a/base_workspace/tools/test/test-setup.sh b/base_workspace/tools/test/test-setup.sh deleted file mode 100755 index 35bb6c6284..0000000000 --- a/base_workspace/tools/test/test-setup.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -# shift stderr to stdout. -exec 2>&1 - -# Executing the test log will page it. -echo 'exec ${PAGER:-/usr/bin/less} "$0" || exit 1' - -DIR="$TEST_SRCDIR" - -# normal commands are run in the exec-root where they have access to -# the entire source tree. By chdir'ing to the runfiles root, tests only -# have direct access to their declared dependencies. -cd "$DIR" || { echo "Could not chdir $DIR"; exit 1; } - -"$@" diff --git a/compile.sh b/compile.sh index 87eb5b8ba9..fde544c354 100755 --- a/compile.sh +++ b/compile.sh @@ -64,8 +64,9 @@ function log() { fi } -# Create a tools symlink so we can run the Bazel bootstrap. -rm -f tools && ln -s base_workspace/tools tools +# Create symlinks so we can use tools from the base_workspace. +rm -f base_workspace/tools && ln -s $(pwd)/tools base_workspace/tools +rm -f base_workspace/third_party && ln -s $(pwd)/third_party base_workspace/third_party mkdir -p fromhost cat << EOF > fromhost/BUILD @@ -181,7 +182,6 @@ esac test -z "$JAVA_HOME" && fail "JDK not found, please set \$JAVA_HOME." rm -f tools/jdk/jdk && ln -s "${JAVA_HOME}" tools/jdk/jdk - JAVAC="${JAVA_HOME}/bin/javac" [[ -x $JAVAC ]] \ diff --git a/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java b/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java index 8c80d7d99d..3302d33f7f 100644 --- a/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java @@ -91,7 +91,7 @@ public abstract class FoundationTestCase extends ChattyAssertsTestCase { scratchFile(rootDirectory.getRelative("devtools/blaze/rules/BUILD").getPathString()); scratchFile(rootDirectory.getRelative("rules/BUILD").getPathString()); copySkylarkFilesIfExist("devtools/blaze/rules/staging", "devtools/blaze/rules/staging"); - copySkylarkFilesIfExist("devtools/blaze/bazel/base_workspace/tools/build_rules", "rules"); + copySkylarkFilesIfExist("devtools/blaze/bazel/tools/build_rules", "rules"); } private void copySkylarkFilesIfExist(String from, String to) throws IOException { diff --git a/tools/BUILD b/tools/BUILD new file mode 100644 index 0000000000..ffd0fb0cdc --- /dev/null +++ b/tools/BUILD @@ -0,0 +1 @@ +package(default_visibility = ["//visibility:public"]) diff --git a/tools/build_rules/genproto.bzl b/tools/build_rules/genproto.bzl new file mode 100644 index 0000000000..14801e3c93 --- /dev/null +++ b/tools/build_rules/genproto.bzl @@ -0,0 +1,77 @@ +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is a quick and dirty rule to make Bazel compile itself. It +# only supports Java. + + +# TODO(bazel-team): unify the OSS Java rules and load from another +# file. +jar_filetype = FileType([".jar"]) + +proto_filetype = FileType([".proto"]) + +def genproto_impl(ctx): + src = ctx.file.src + proto_compiler = ctx.file._proto_compiler + proto_dep = ctx.file._proto_dep + class_jar = ctx.outputs.java + proto_output = class_jar.path + ".proto_output" + build_output = class_jar.path + ".build_output" + + inputs = [src, proto_dep, proto_compiler] + proto_compiler_path = proto_compiler.path + + javapath = "tools/jdk/jdk/bin/" + cmd = ("set -e;" + + "rm -rf " + proto_output + ";" + + "mkdir " + proto_output + ";" + + "rm -rf " + build_output + ";" + + "mkdir " + build_output + "\n" + + proto_compiler_path + " --java_out=" + + proto_output +" " + src.path + "\n" + + "JAVA_FILES=$(find " + proto_output + " -name '*.java')\n" + + javapath + "javac" + " -classpath " + proto_dep.path + + " ${JAVA_FILES} -d " + build_output + "\n" + + javapath + "jar cf " + class_jar.path + " -C " + build_output + " .\n") + ctx.action( + inputs = inputs, + outputs = [class_jar], + mnemonic = 'CompileProtos', + command = cmd, + use_default_shell_env = True) + + return struct(compile_time_jars = set([class_jar]), + runtime_jars = set([class_jar, proto_dep], order="link")) + + +genproto = rule(genproto_impl, + # There should be a flag like gen_java, and only generate the jar if it's + # set. Skylark needs a bit of improvement first (concat structs). + attrs = { + "src": attr.label(allow_files=proto_filetype, single_file=True), + # TODO(bazel-team): this should be a hidden attribute with a default + # value, but Skylark needs to support select first. + "_proto_compiler": attr.label( + default=Label("//third_party:protoc"), + allow_files=True, + single_file=True), + "_proto_dep": attr.label( + default=Label("//third_party:protobuf"), + single_file=True, + allow_files=jar_filetype, + ), + }, + outputs = {"java": "lib%{name}.jar"}, +) diff --git a/tools/build_rules/go_rules.bzl b/tools/build_rules/go_rules.bzl new file mode 100644 index 0000000000..ae218ccd39 --- /dev/null +++ b/tools/build_rules/go_rules.bzl @@ -0,0 +1,184 @@ +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""These are bare-bones Go rules. + +Several issues: + +- For "a/b/c.go", the go tool creates library "a/b.a" with import path +"a/b". We can probably simulate this with symlink trees. + +- Dependencies are not enforced; a symlink tree might help here too. + +- Hardcoded to 6g from the GC suite. We should be able to support GCC + and derive 6g from the CPU (from which configuration?) + +- It would be nice to be able to create a full-fledged Go + configuration in Skylark. + +- It would be nice to support zero-configuration +go_library()/go_binary()/go_test() rules: + + * name defaults to basename of directory + * srcs defaults to *.go + +- does not support checked in compilers. + +- No C++ interop. + +- deps must be populated by hand. + +- go_test must have both test and non-test files in srcs. +""" + +go_filetype = FileType([".go"]) +go_lib_filetype = FileType([".a"]) + + +def go_compile_command(ctx, sources, out_lib): + args = [ + ctx.files.go_root[0].path + "/bin/go", + + "tool", "6g", + "-o", out_lib.path, "-pack", + + # Import path. + "-I", ctx.configuration.bin_dir.path] + + # Set -p to the import path of the library, ie. + # (ctx.label.package + "/" ctx.label.name) for now. + return ' '.join(args + cmd_helper.template(sources, "%{path}")) + +def go_library_impl(ctx): + sources = ctx.files.srcs + if not sources: + fail("may not be empty", "srcs") + + out_lib = ctx.outputs.lib + + ctx.action( + inputs = sources + ctx.files.deps, + outputs = [out_lib], + mnemonic = "GoCompile", + env = { + "GOROOT": ctx.files.go_root[0].path, + }, + command = go_compile_command(ctx, set(sources), out_lib)) + + out_nset = set([out_lib]) + return struct( + files = out_nset, + go_library_object = out_nset) + + +def go_link_action(ctx, lib, executable): + cmd = ' '.join([ + ctx.files.go_root[0].path + "/bin/go", + "tool", "6l", + # Link search path. + "-L", ctx.configuration.bin_dir.path, + "-o", executable.path, + lib.path]) + ctx.action( + inputs = [lib], + outputs = [executable], + command = cmd, + env = { + "GOROOT": ctx.files.go_root[0].path, + }, + mnemonic = "GoLink") + + +def go_binary_impl(ctx): + lib_result = go_library_impl(ctx) + executable = ctx.outputs.executable + lib_out = ctx.outputs.lib + + go_link_action(ctx, lib_out, executable) + return struct(files = set([executable]) + lib_result.files) + + +def go_test_impl(ctx): + lib_result = go_library_impl(ctx) + main_go = ctx.outputs.main_go + + go_import = ctx.label.package + "/" + ctx.label.name + + # Would be nice to use transitive info provider to get at sources of + # a dependent library. + sources = ctx.files.srcs + args = (["--package", go_import, "--output", ctx.outputs.main_go.path] + + cmd_helper.template(set(sources), "%{path}")) + + ctx.action( + inputs = sources, + executable = ctx.executable.test_generator, + outputs = [main_go], + mnemonic = "GoTestGenTest", + arguments = args) + + ctx.action( + inputs = [main_go, ctx.outputs.lib], + outputs = [ctx.outputs.main_lib], + command = go_compile_command(ctx, set([main_go]), ctx.outputs.main_lib), + env = { + "GOROOT": ctx.files.go_root[0].path, + }, + mnemonic = "GoCompileTest") + + go_link_action(ctx, ctx.outputs.main_lib, ctx.outputs.executable) + + runfiles = ctx.runfiles(collect_data = True, files = [ctx.outputs.executable]) + return struct(runfiles=runfiles) + +go_library_attrs = { + "data": attr.label_list(allow_files=True, cfg=DATA_CFG), + "srcs": attr.label_list(allow_files=go_filetype), + "deps": attr.label_list( + providers=["go_library_object"]), + "go_root": attr.label( + default=Label("//tools/go:go_root"), + allow_files=True, + cfg=HOST_CFG), + } + +go_library_outputs = { + "lib": "%{name}.a", + } + +go_library = rule( + go_library_impl, + attrs = go_library_attrs, + outputs =go_library_outputs) + +go_binary = rule( + go_binary_impl, + executable = True, + attrs = go_library_attrs, + outputs = go_library_outputs) + +go_test = rule( + go_test_impl, + executable = True, + test = True, + attrs = go_library_attrs + { + "test_generator": attr.label( + default=Label("//tools/go:generate_test_main"), + cfg=HOST_CFG, flags=["EXECUTABLE"]) + }, + outputs = { + "lib" : "%{name}.a", + "main_lib": "%{name}_main_test.a", + "main_go": "%{name}_main_test.go", + }) diff --git a/tools/build_rules/java_rules_oss.bzl b/tools/build_rules/java_rules_oss.bzl new file mode 100644 index 0000000000..dcd2329ebc --- /dev/null +++ b/tools/build_rules/java_rules_oss.bzl @@ -0,0 +1,233 @@ +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +java_filetype = FileType([".java"]) +jar_filetype = FileType([".jar"]) +srcjar_filetype = FileType([".jar", ".srcjar"]) + +JAVA_PATH='tools/jdk/jdk/bin/' + +def is_windows(config): + return config.fragment(cpp).compiler.startswith("windows_") + +def path_separator(ctx): + if is_windows(ctx.configuration): + return ";" + else: + return ":" + +# This is a quick and dirty rule to make Bazel compile itself. It's not +# production ready. + +def java_library_impl(ctx): + class_jar = ctx.outputs.class_jar + compile_time_jars = set(order="link") + runtime_jars = set(order="link") + for dep in ctx.targets.deps: + compile_time_jars += dep.compile_time_jars + runtime_jars += dep.runtime_jars + + jars = jar_filetype.filter(ctx.files.jars) + compile_time_jars += jars + runtime_jars += jars + compile_time_jars_list = list(compile_time_jars) # TODO: This is weird. + + build_output = class_jar.path + ".build_output" + sources = ctx.files.srcs + + sources_param_file = ctx.new_file( + ctx.configuration.bin_dir, class_jar, "-2.params") + ctx.file_action( + output = sources_param_file, + content = cmd_helper.join_paths("\n", set(sources)), + executable = False) + + # Cleaning build output directory + cmd = "set -e;rm -rf " + build_output + ";mkdir " + build_output + "\n" + if ctx.files.srcs: + cmd += JAVA_PATH + "javac" + if compile_time_jars: + cmd += " -classpath '" + cmd_helper.join_paths(path_separator(ctx), compile_time_jars) + "'" + cmd += " -d " + build_output + " @" + sources_param_file.path + "\n" + + # We haven't got a good story for where these should end up, so + # stick them in the root of the jar. + for r in ctx.files.resources: + cmd += "cp %s %s\n" % (r.path, build_output) + cmd += (JAVA_PATH + "jar cf " + class_jar.path + " -C " + build_output + " .\n" + + "touch " + build_output + "\n") + ctx.action( + inputs = (sources + compile_time_jars_list + [sources_param_file] + + ctx.files.resources), + outputs = [class_jar], + mnemonic='Javac', + command=cmd, + use_default_shell_env=True) + + runfiles = ctx.runfiles(collect_data = True) + + return struct(files = set([class_jar]), + compile_time_jars = compile_time_jars + [class_jar], + runtime_jars = runtime_jars + [class_jar], + runfiles = runfiles) + + +def java_binary_impl(ctx): + library_result = java_library_impl(ctx) + + deploy_jar = ctx.outputs.deploy_jar + manifest = ctx.outputs.manifest + build_output = deploy_jar.path + ".build_output" + main_class = ctx.attr.main_class + ctx.file_action( + output = manifest, + content = "Main-Class: " + main_class + "\n", + executable = False) + + # Cleaning build output directory + cmd = "set -e;rm -rf " + build_output + ";mkdir " + build_output + "\n" + for jar in library_result.runtime_jars: + cmd += "unzip -qn " + jar.path + " -d " + build_output + "\n" + cmd += (JAVA_PATH + "jar cmf " + manifest.path + " " + + deploy_jar.path + " -C " + build_output + " .\n" + + "touch " + build_output + "\n") + + ctx.action( + inputs=list(library_result.runtime_jars) + [manifest], + outputs=[deploy_jar], + mnemonic='Deployjar', + command=cmd, + use_default_shell_env=True) + + # Write the wrapper. + executable = ctx.outputs.executable + ctx.file_action( + output = executable, + content = '\n'.join([ + "#!/bin/bash", + "# autogenerated - do not edit.", + "case \"$0\" in", + "/*) self=\"$0\" ;;", + "*) self=\"$PWD/$0\";;", + "esac", + "", + "if [[ -z \"$JAVA_RUNFILES\" ]]; then", + " if [[ -e \"${self}.runfiles\" ]]; then", + " export JAVA_RUNFILES=\"${self}.runfiles\"", + " fi", + " if [[ -n \"$JAVA_RUNFILES\" ]]; then", + " export TEST_SRCDIR=${TEST_SRCDIR:-$JAVA_RUNFILES}", + " fi", + "fi", + "", + + "jvm_bin=%s" % (ctx.file.javabin.path), + "if [[ ! -x ${jvm_bin} ]]; then", + " jvm_bin=$(which java)", + "fi", + + # We extract the .so into a temp dir. If only we could mmap + # directly from the zip file. + "DEPLOY=$(dirname $self)/$(basename %s)" % deploy_jar.path, + + # This works both on Darwin and Linux, with the darwin path + # looking like tmp.XXXXXXXX.{random} + "SO_DIR=$(mktemp -d -t tmp.XXXXXXXXX)", + "function cleanup() {", + " rm -rf ${SO_DIR}", + "}", + "trap cleanup EXIT", + "unzip -q -d ${SO_DIR} ${DEPLOY} \"*.so\" \"*.dll\" \"*.dylib\" >& /dev/null", + ("${jvm_bin} -Djava.library.path=${SO_DIR} %s -jar $DEPLOY \"$@\"" + % ' '.join(ctx.attr.jvm_flags)) , + "", + ]), + executable = True) + + runfiles = ctx.runfiles(files = [ + deploy_jar, executable] + ctx.files.jvm, collect_data = True) + files_to_build = set([deploy_jar, manifest, executable]) + files_to_build += library_result.files + + return struct(files = files_to_build, runfiles = runfiles) + + +def java_import_impl(ctx): + # TODO(bazel-team): Why do we need to filter here? The attribute + # already says only jars are allowed. + jars = set(jar_filetype.filter(ctx.files.jars)) + runfiles = ctx.runfiles(collect_data = True) + return struct(files = jars, + compile_time_jars = jars, + runtime_jars = jars, + runfiles = runfiles) + + +java_library_attrs = { + "data": attr.label_list(allow_files=True, cfg=DATA_CFG), + "resources": attr.label_list(allow_files=True), + "srcs": attr.label_list(allow_files=java_filetype), + "jars": attr.label_list(allow_files=jar_filetype), + "deps": attr.label_list( + allow_files=False, + providers = ["compile_time_jars", "runtime_jars"]), + } + +java_library = rule( + java_library_impl, + attrs = java_library_attrs, + outputs = { + "class_jar": "lib%{name}.jar", + }) + +java_binary_attrs_common = java_library_attrs + { + "jvm_flags": attr.string_list(), + "jvm": attr.label(default=Label("//tools/jdk:jdk"), allow_files=True), + "javabin": attr.label(default=Label("//tools/jdk:java"), single_file=True), + "args": attr.string_list(), +} + +java_binary_attrs = java_binary_attrs_common + { + "main_class": attr.string(mandatory=True), +} + +java_binary_outputs = { + "class_jar": "lib%{name}.jar", + "deploy_jar": "%{name}_deploy.jar", + "manifest": "%{name}_MANIFEST.MF" +} + +java_binary = rule(java_binary_impl, + executable = True, + attrs = java_binary_attrs, + outputs = java_binary_outputs) + +java_test = rule(java_binary_impl, + executable = True, + attrs = java_binary_attrs_common + { + "main_class": attr.string(default="org.junit.runner.JUnitCore"), + # TODO(bazel-team): it would be better if we could offer a + # test_class attribute, but the "args" attribute is hard + # coded in the bazel infrastructure. + }, + outputs = java_binary_outputs, + test = True, +) + +java_import = rule( + java_import_impl, + attrs = { + "jars": attr.label_list(allow_files=jar_filetype), + "srcjar": attr.label(allow_files=srcjar_filetype), + }) diff --git a/tools/build_rules/py_rules.bzl b/tools/build_rules/py_rules.bzl new file mode 100644 index 0000000000..ddd43df75d --- /dev/null +++ b/tools/build_rules/py_rules.bzl @@ -0,0 +1,122 @@ +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ZIP_PATH = "/usr/bin/zip" + +py_file_types = FileType([".py"]) + + +def collect_transitive_sources(ctx): + source_files = set(order="compile") + for dep in ctx.targets.deps: + source_files += dep.transitive_py_files + + source_files += py_file_types.filter(ctx.files.srcs) + return source_files + + +def py_library_impl(ctx): + transitive_sources = collect_transitive_sources(ctx) + return struct( + files = set(), + transitive_py_files = transitive_sources) + + +def py_binary_impl(ctx): + main_file = py_file_types.filter(ctx.files.srcs)[0] + transitive_sources = collect_transitive_sources(ctx) + deploy_zip = ctx.outputs.deploy_zip + + deploy_zip_nomain = ctx.new_file( + ctx.configuration.bin_dir, deploy_zip, ".nomain.zip") + + # This is not very scalable, because we just construct a huge string instead + # of using a nested set. We need to do it this way because Skylark currently + # does not support actions with non-artifact executables but with an + # argument list (instead of just a single command) + command = ZIP_PATH +" -q " + deploy_zip_nomain.path + " " + " ".join([f.path for f in transitive_sources]) + ctx.action( + inputs = list(transitive_sources), + outputs = [ deploy_zip_nomain ], + mnemonic = "PyZip", + command = command, + use_default_shell_env = False) + + dirs = [f.path[:f.path.rfind('/')] for f in transitive_sources] + outdir = deploy_zip.path + ".out" + + # Add __init__.py files and the __main__.py driver. + main_cmd = ("mkdir %s && " % outdir + + " cp %s %s/__main__.py && " % (main_file.path, outdir) + + " cp %s %s/main.zip && " % (deploy_zip_nomain.path, outdir) + + " (cd %s && " % outdir + + " mkdir -p %s && " % " ".join(dirs) + + " find -type d -exec touch -t 198001010000 '{}'/__init__.py ';' && " + + " chmod +w main.zip && " + + " %s -qR main.zip $(find -type f ) ) && " % (ZIP_PATH) + + " mv %s/main.zip %s " % (outdir, deploy_zip.path)) + + ctx.action( + inputs = [ deploy_zip_nomain, main_file ], + outputs = [ deploy_zip ], + mnemonic = "PyZipMain", + command = main_cmd) + + executable = ctx.outputs.executable + ctx.action( + inputs = [ deploy_zip, ], + outputs = [ executable, ], + command = "echo '#!/usr/bin/env python' | cat - %s > %s && chmod +x %s" % ( + deploy_zip.path, executable.path, executable.path)) + + runfiles_files = transitive_sources + [executable] + + runfiles = ctx.runfiles(transitive_files = runfiles_files, + collect_default = True) + + files_to_build = set([deploy_zip, executable]) + return struct(files = files_to_build, runfiles = runfiles) + + +py_srcs_attr = attr.label_list( + flags=["DIRECT_COMPILE_TIME_INPUT"], + allow_files = py_file_types) + +py_deps_attr = attr.label_list( + providers = ["transitive_py_files"], + allow_files = False) + +py_attrs = { + "srcs": py_srcs_attr, + "deps": py_deps_attr } + +py_library = rule( + py_library_impl, + attrs = py_attrs) + +py_binary_outputs = { + "deploy_zip": "%{name}.zip" + } + +py_binary = rule( + py_binary_impl, + executable = True, + attrs = py_attrs, + outputs = py_binary_outputs) + +py_test = rule( + py_binary_impl, + executable = True, + attrs = py_attrs, + outputs = py_binary_outputs) diff --git a/tools/cpp/BUILD b/tools/cpp/BUILD new file mode 100644 index 0000000000..af72b660ea --- /dev/null +++ b/tools/cpp/BUILD @@ -0,0 +1,70 @@ +package(default_visibility = ["//visibility:public"]) + +# TODO(bazel-team): The MacOS tools give an error if there is no object file on +# the command line to libtool, so we use an empty .cc file here. We should find +# a better way to handle this case. +cc_library( + name = "malloc", + srcs = ["empty.cc"], +) + +cc_library( + name = "stl", + srcs = ["empty.cc"], +) + +filegroup( + name = "empty", + srcs = [], +) + +filegroup( + name = "toolchain", + srcs = [ + ":cc-compiler-darwin", + ":cc-compiler-local", + ":empty", + ], +) + +cc_toolchain( + name = "cc-compiler-local", + all_files = ":empty", + compiler_files = ":empty", + cpu = "local", + dwp_files = ":empty", + dynamic_runtime_libs = [":empty"], + linker_files = ":empty", + objcopy_files = ":empty", + static_runtime_libs = [":empty"], + strip_files = ":empty", + supports_param_files = 0, +) + +cc_toolchain( + name = "cc-compiler-k8", + all_files = ":empty", + compiler_files = ":empty", + cpu = "local", + dwp_files = ":empty", + dynamic_runtime_libs = [":empty"], + linker_files = ":empty", + objcopy_files = ":empty", + static_runtime_libs = [":empty"], + strip_files = ":empty", + supports_param_files = 0, +) + +cc_toolchain( + name = "cc-compiler-darwin", + all_files = ":empty", + compiler_files = ":empty", + cpu = "darwin", + dwp_files = ":empty", + dynamic_runtime_libs = [":empty"], + linker_files = ":empty", + objcopy_files = ":empty", + static_runtime_libs = [":empty"], + strip_files = ":empty", + supports_param_files = 0, +) diff --git a/tools/cpp/CROSSTOOL b/tools/cpp/CROSSTOOL new file mode 100644 index 0000000000..7287bc49ba --- /dev/null +++ b/tools/cpp/CROSSTOOL @@ -0,0 +1,193 @@ +major_version: "local" +minor_version: "" +default_target_cpu: "k8" +default_toolchain { + cpu: "k8" + toolchain_identifier: "local_linux" +} +default_toolchain { + cpu: "darwin" + toolchain_identifier: "local_darwin" +} + +toolchain { + abi_version: "local" + abi_libc_version: "local" + builtin_sysroot: "" + compiler: "compiler" + host_system_name: "local" + needsPic: true + supports_gold_linker: false + supports_incremental_linker: false + supports_fission: false + supports_interface_shared_objects: false + supports_normalizing_ar: false + supports_start_end_lib: false + supports_thin_archives: false + target_libc: "local" + target_cpu: "local" + target_system_name: "local" + toolchain_identifier: "local_linux" + + tool_path { name: "ar" path: "/usr/bin/ar" } + tool_path { name: "compat-ld" path: "/usr/bin/ld" } + tool_path { name: "cpp" path: "/usr/bin/cpp" } + tool_path { name: "dwp" path: "/usr/bin/dwp" } + tool_path { name: "gcc" path: "/usr/bin/gcc" } + cxx_flag: "-std=c++0x" + linker_flag: "-lstdc++" + # TODO(bazel-team): In theory, the path here ought to exactly match the path + # used by gcc. That works because bazel currently doesn't track files at + # absolute locations and has no remote execution, yet. However, this will need + # to be fixed, maybe with auto-detection? + cxx_builtin_include_directory: "/usr/lib/gcc/" + cxx_builtin_include_directory: "/usr/local/include" + cxx_builtin_include_directory: "/usr/include" + tool_path { name: "gcov" path: "/usr/bin/gcov" } + tool_path { name: "ld" path: "/usr/bin/ld" } + tool_path { name: "nm" path: "/usr/bin/nm" } + tool_path { name: "objcopy" path: "/usr/bin/objcopy" } + objcopy_embed_flag: "-I" + objcopy_embed_flag: "binary" + tool_path { name: "objdump" path: "/usr/bin/objdump" } + tool_path { name: "strip" path: "/usr/bin/strip" } +} + +toolchain { + abi_version: "local" + abi_libc_version: "local" + builtin_sysroot: "" + compiler: "compiler" + host_system_name: "local" + needsPic: true + target_libc: "macosx" + target_cpu: "darwin" + target_system_name: "local" + toolchain_identifier: "local_darwin" + + tool_path { name: "ar" path: "/usr/bin/libtool" } + tool_path { name: "compat-ld" path: "/usr/bin/ld" } + tool_path { name: "cpp" path: "/usr/bin/cpp" } + tool_path { name: "dwp" path: "/usr/bin/dwp" } + tool_path { name: "gcc" path: "/usr/bin/gcc" } + cxx_flag: "-std=c++0x" + ar_flag: "-static" + ar_flag: "-s" + ar_flag: "-o" + linker_flag: "-lstdc++" + cxx_builtin_include_directory: "/usr/include" + cxx_builtin_include_directory: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain" + cxx_builtin_include_directory: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs" + cxx_builtin_include_directory: "/opt/local/include" + cxx_builtin_include_directory: "/Library/Developer/CommandLineTools" + tool_path { name: "gcov" path: "/usr/bin/gcov" } + tool_path { name: "ld" path: "/usr/bin/ld" } + tool_path { name: "nm" path: "/usr/bin/nm" } + tool_path { name: "objcopy" path: "/usr/bin/objcopy" } + objcopy_embed_flag: "-I" + objcopy_embed_flag: "binary" + tool_path { name: "objdump" path: "/usr/bin/objdump" } + tool_path { name: "strip" path: "/usr/bin/strip" } +} + +toolchain { + abi_version: "local" + abi_libc_version: "local" + builtin_sysroot: "" + compiler: "windows_mingw" + host_system_name: "local" + needsPic: false + target_libc: "local" + target_cpu: "k8" + target_system_name: "local" + toolchain_identifier: "local_windows_mingw" + + tool_path { name: "ar" path: "C:/mingw/bin/ar" } + tool_path { name: "compat-ld" path: "C:/mingw/bin/ld" } + tool_path { name: "cpp" path: "C:/mingw/bin/cpp" } + tool_path { name: "dwp" path: "C:/mingw/bin/dwp" } + tool_path { name: "gcc" path: "C:/mingw/bin/gcc" } + cxx_flag: "-std=c++0x" + # TODO(bazel-team): In theory, the path here ought to exactly match the path + # used by gcc. That works because bazel currently doesn't track files at + # absolute locations and has no remote execution, yet. However, this will need + # to be fixed, maybe with auto-detection? + cxx_builtin_include_directory: "C:/mingw/include" + cxx_builtin_include_directory: "C:/mingw/lib/gcc" + tool_path { name: "gcov" path: "C:/mingw/bin/gcov" } + tool_path { name: "ld" path: "C:/mingw/bin/ld" } + tool_path { name: "nm" path: "C:/mingw/bin/nm" } + tool_path { name: "objcopy" path: "C:/mingw/bin/objcopy" } + objcopy_embed_flag: "-I" + objcopy_embed_flag: "binary" + tool_path { name: "objdump" path: "C:/mingw/bin/objdump" } + tool_path { name: "strip" path: "C:/mingw/bin/strip" } +} + +toolchain { + abi_version: "local" + abi_libc_version: "local" + builtin_sysroot: "" + compiler: "windows_msys64_mingw64" + host_system_name: "local" + needsPic: false + target_libc: "local" + target_cpu: "k8" + target_system_name: "local" + toolchain_identifier: "local_windows_msys64_mingw64" + + tool_path { name: "ar" path: "C:/msys64/mingw64/bin/ar" } + tool_path { name: "compat-ld" path: "C:/msys64/mingw64/bin/ld" } + tool_path { name: "cpp" path: "C:/msys64/mingw64/bin/cpp" } + tool_path { name: "dwp" path: "C:/msys64/mingw64/bin/dwp" } + tool_path { name: "gcc" path: "C:/msys64/mingw64/bin/gcc" } + cxx_flag: "-std=c++0x" + # TODO(bazel-team): In theory, the path here ought to exactly match the path + # used by gcc. That works because bazel currently doesn't track files at + # absolute locations and has no remote execution, yet. However, this will need + # to be fixed, maybe with auto-detection? + cxx_builtin_include_directory: "C:/msys64/mingw64/x86_64-w64-mingw32/include" + tool_path { name: "gcov" path: "C:/msys64/mingw64/bin/gcov" } + tool_path { name: "ld" path: "C:/msys64/mingw64/bin/ld" } + tool_path { name: "nm" path: "C:/msys64/mingw64/bin/nm" } + tool_path { name: "objcopy" path: "C:/msys64/mingw64/bin/objcopy" } + objcopy_embed_flag: "-I" + objcopy_embed_flag: "binary" + tool_path { name: "objdump" path: "C:/msys64/mingw64/bin/objdump" } + tool_path { name: "strip" path: "C:/msys64/mingw64/bin/strip" } +} + +toolchain { + abi_version: "local" + abi_libc_version: "local" + builtin_sysroot: "" + compiler: "windows_clang" + host_system_name: "local" + needsPic: false + target_libc: "local" + target_cpu: "k8" + target_system_name: "local" + toolchain_identifier: "local_windows_clang" + + tool_path { name: "ar" path: "C:/mingw/bin/ar" } + tool_path { name: "compat-ld" path: "C:/Program Files (x86)/LLVM/bin/ld" } + tool_path { name: "cpp" path: "C:/Program Files (x86)/LLVM/bin/cpp" } + tool_path { name: "dwp" path: "C:/Program Files (x86)/LLVM/bin/dwp" } + tool_path { name: "gcc" path: "C:/Program Files (x86)/LLVM/bin/clang" } + cxx_flag: "-std=c++0x" + # TODO(bazel-team): In theory, the path here ought to exactly match the path + # used by gcc. That works because bazel currently doesn't track files at + # absolute locations and has no remote execution, yet. However, this will need + # to be fixed, maybe with auto-detection? + cxx_builtin_include_directory: "/usr/lib/gcc/" + cxx_builtin_include_directory: "/usr/local/include" + cxx_builtin_include_directory: "/usr/include" + tool_path { name: "gcov" path: "C:/Program Files (x86)/LLVM/bin/gcov" } + tool_path { name: "ld" path: "C:/Program Files (x86)/LLVM/bin/ld" } + tool_path { name: "nm" path: "C:/Program Files (x86)/LLVM/bin/nm" } + tool_path { name: "objcopy" path: "C:/Program Files (x86)/LLVM/bin/objcopy" } + objcopy_embed_flag: "-I" + objcopy_embed_flag: "binary" + tool_path { name: "objdump" path: "C:/Program Files (x86)/LLVM/bin/objdump" } + tool_path { name: "strip" path: "C:/Program Files (x86)/LLVM/bin/strip" } +} diff --git a/tools/cpp/empty.cc b/tools/cpp/empty.cc new file mode 100644 index 0000000000..7309f1cff2 --- /dev/null +++ b/tools/cpp/empty.cc @@ -0,0 +1,19 @@ +// Copyright 2014 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// +// Workaround for the problem that MacOS tools give an error if there is no +// object file on the command line. +// diff --git a/tools/defaults/BUILD b/tools/defaults/BUILD new file mode 100644 index 0000000000..fab37b3da7 --- /dev/null +++ b/tools/defaults/BUILD @@ -0,0 +1,2 @@ +# At runtime, a package is synthesized in memory that corresponds +# the command-line flag settings. diff --git a/tools/genrule/BUILD b/tools/genrule/BUILD new file mode 100644 index 0000000000..318ebb0410 --- /dev/null +++ b/tools/genrule/BUILD @@ -0,0 +1 @@ +exports_files(["genrule-setup.sh"]) diff --git a/tools/genrule/genrule-setup.sh b/tools/genrule/genrule-setup.sh new file mode 100755 index 0000000000..e69de29bb2 diff --git a/tools/go/BUILD b/tools/go/BUILD new file mode 100644 index 0000000000..de99b06eac --- /dev/null +++ b/tools/go/BUILD @@ -0,0 +1,11 @@ +package(default_visibility = ["//visibility:public"]) + +load("tools/build_rules/go_rules", "go_binary", "go_library") + +# This should be a symlink to a GOROOT holding bin/ and pkg/ +exports_files(srcs = ["go_root"]) + +go_binary( + name = "generate_test_main", + srcs = ["generate_test_main.go"], +) diff --git a/tools/go/generate_test_main.go b/tools/go/generate_test_main.go new file mode 100644 index 0000000000..6316802dde --- /dev/null +++ b/tools/go/generate_test_main.go @@ -0,0 +1,91 @@ +// Bare bones Go testing support for Bazel. + +package main + +import ( + "flag" + "go/ast" + "go/parser" + "go/token" + "log" + "os" + "strings" + "text/template" +) + +// Cases holds template data. +type Cases struct { + Package string + Names []string +} + +func main() { + pkg := flag.String("package", "", "package from which to import test methods.") + out := flag.String("output", "", "output file to write. Defaults to stdout.") + flag.Parse() + + if *pkg == "" { + log.Fatal("must set --package.") + } + + outFile := os.Stdout + if *out != "" { + var err error + outFile, err = os.Create(*out) + if err != nil { + log.Fatalf("os.Create(%q): %v", *out, err) + } + defer outFile.Close() + } + + cases := Cases{ + Package: *pkg, + } + testFileSet := token.NewFileSet() + for _, f := range flag.Args() { + parse, err := parser.ParseFile(testFileSet, f, nil, parser.ParseComments) + if err != nil { + log.Fatalf("ParseFile(%q): %v", f, err) + } + + for _, d := range parse.Decls { + fn, ok := d.(*ast.FuncDecl) + if !ok { + continue + } + if fn.Recv != nil { + continue + } + if !strings.HasPrefix(fn.Name.Name, "Test") { + continue + } + cases.Names = append(cases.Names, fn.Name.Name) + } + } + + tpl := template.Must(template.New("source").Parse(` +package main +import ( + "testing" + + undertest "{{.Package}}" +) + +func everything(pat, str string) (bool, error) { + return true, nil +} + +var tests = []testing.InternalTest{ +{{range .Names}} + {"{{.}}", undertest.{{.}} }, +{{end}} +} + +func main() { + testing.Main(everything, tests, nil, nil) +} +`)) + if err := tpl.Execute(outFile, &cases); err != nil { + log.Fatalf("template.Execute(%v): %v", cases, err) + } +} diff --git a/tools/jdk/BUILD b/tools/jdk/BUILD new file mode 100644 index 0000000000..89241c1aa5 --- /dev/null +++ b/tools/jdk/BUILD @@ -0,0 +1,75 @@ +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "jni_header", + srcs = ["jdk/include/jni.h"], +) + +filegroup( + name = "jni_md_header-darwin", + srcs = ["jdk/include/darwin/jni_md.h"], +) + +filegroup( + name = "jni_md_header-linux", + srcs = ["jdk/include/linux/jni_md.h"], +) + +filegroup( + name = "java", + srcs = ["jdk/jre/bin/java"], +) + +BOOTCLASS_JARS = [ + "rt.jar", + "resources.jar", + "jsse.jar", + "jce.jar", + "charsets.jar", +] + +filegroup( + name = "bootclasspath", + srcs = ["jdk/jre/lib/%s" % jar for jar in BOOTCLASS_JARS], +) + +filegroup( + name = "langtools", + srcs = ["jdk/lib/tools.jar"], +) + +java_import( + name = "langtools-neverlink", + jars = ["jdk/lib/tools.jar"], + neverlink = 1, +) + +# This one is just needed because of how filegroup redirection works. +filegroup(name = "jdk-null") + +filegroup( + name = "jdk-default", + srcs = [":java"], + path = "jdk/jre", +) + +filegroup( + name = "jdk", + srcs = [ + ":jdk-default", + ":jdk-null", + ], +) + +java_toolchain( + name = "toolchain", + encoding = "UTF-8", + source_version = "8", + target_version = "8", +) + +exports_files([ + "JavaBuilder_deploy.jar", + "ijar", + "SingleJar_deploy.jar", +]) diff --git a/tools/test/BUILD b/tools/test/BUILD new file mode 100644 index 0000000000..db26d3bb78 --- /dev/null +++ b/tools/test/BUILD @@ -0,0 +1,6 @@ +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "runtime", + srcs = ["test-setup.sh"], +) diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh new file mode 100755 index 0000000000..35bb6c6284 --- /dev/null +++ b/tools/test/test-setup.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# shift stderr to stdout. +exec 2>&1 + +# Executing the test log will page it. +echo 'exec ${PAGER:-/usr/bin/less} "$0" || exit 1' + +DIR="$TEST_SRCDIR" + +# normal commands are run in the exec-root where they have access to +# the entire source tree. By chdir'ing to the runfiles root, tests only +# have direct access to their declared dependencies. +cd "$DIR" || { echo "Could not chdir $DIR"; exit 1; } + +"$@" -- cgit v1.2.3