aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/build_rules/closure
diff options
context:
space:
mode:
Diffstat (limited to 'tools/build_rules/closure')
-rw-r--r--tools/build_rules/closure/BUILD26
-rw-r--r--tools/build_rules/closure/README.md128
-rw-r--r--tools/build_rules/closure/closure_js_binary.bzl124
-rw-r--r--tools/build_rules/closure/closure_js_library.bzl49
-rw-r--r--tools/build_rules/closure/closure_repositories.bzl114
-rw-r--r--tools/build_rules/closure/closure_stylesheet_library.bzl82
-rw-r--r--tools/build_rules/closure/closure_template_library.bzl59
7 files changed, 0 insertions, 582 deletions
diff --git a/tools/build_rules/closure/BUILD b/tools/build_rules/closure/BUILD
deleted file mode 100644
index 486a8aadd8..0000000000
--- a/tools/build_rules/closure/BUILD
+++ /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.
-
-java_binary(
- name = "closure_stylesheets",
- main_class = "com.google.common.css.compiler.commandline.ClosureCommandLineCompiler",
- visibility = ["//visibility:public"],
- runtime_deps = ["@closure_stylesheets//jar"],
-)
-
-filegroup(
- name = "srcs",
- srcs = glob(["**"]),
- visibility = ["//tools:__pkg__"],
-)
diff --git a/tools/build_rules/closure/README.md b/tools/build_rules/closure/README.md
deleted file mode 100644
index 0f7c979443..0000000000
--- a/tools/build_rules/closure/README.md
+++ /dev/null
@@ -1,128 +0,0 @@
-# Closure Tools for Bazel
-
-## Deprecation notice
-
-Please note, Closure Tools for Bazel is deprecated, and will be moved soon.
-Please see [github.com/bazelbuild/rules_closure](https://github.com/bazelbuild/rules_closure/)
-for the new rules.
-
-## Overview
-
-These rules define targets for JavaScript, stylesheets, and templates that will
-be compiled with the Closure Tools toolchain.
-
-* `closure_js_binary`
-* `closure_js_library`
-* `closure_stylesheet_library`
-* `closure_template_library`
-
-## Setup
-
-Add the following to your `WORKSPACE` file to add the external repositories
-for the various Closure Tools binaries and the Closure Library:
-
-```python
-load("@bazel_tools//tools/build_rules/closure:closure_repositories.bzl", "closure_repositories")
-
-closure_repositories()
-```
-
-## Usage
-
-Suppose we are building a web application with template, stylesheet, and
-JavaScript files: `hello.soy`, `hello.gss`, and `hello.js`.
-
-`hello.soy`
-
-```
-{namespace hello.templates autoescape="strict"}
-
-/**
- * Renders an element containing the text "hello".
- */
-{template .hello}
- <div class="{css hello-container}">Hello.</div>
-{/template}
-```
-
-`hello.gss`
-
-```css
-.hello-container {
- color: red;
- font-weight: bold;
-}
-```
-
-`hello.js`
-
-```javascript
-goog.provide('hello');
-
-goog.require('goog.soy');
-goog.require('hello.templates');
-
-goog.soy.renderElement(document.body, hello.templates.hello);
-```
-
-We can create a BUILD file to compile these and produce two files:
-
-* `hello_combined.css`
-* `hello_combined.js`
-
-`BUILD`
-
-```python
-load("@bazel_tools//tools/build_rules/closure:closure_js_binary.bzl", "closure_js_binary")
-load("@bazel_tools//tools/build_rules/closure:closure_js_library.bzl", "closure_js_library")
-load("@bazel_tools//tools/build_rules/closure:closure_stylesheet_library.bzl", "closure_stylesheet_library")
-load("@bazel_tools//tools/build_rules/closure:closure_template_library.bzl", "closure_template_library")
-
-closure_js_binary(
- name = "hello",
- main = "hello",
- deps = [":hello_lib"],
-)
-
-closure_js_library(
- name = "hello_lib",
- srcs = ["hello.js"],
- deps = [
- "@closure_library//:closure_library",
- "@closure_templates//:closure_templates_js",
- ":hello_css",
- ":hello_soy",
- ]
-)
-
-closure_stylesheet_library(
- name = "hello_css",
- srcs = ["hello.gss"],
- deps = ["@closure_library//:closure_library_css"],
-)
-
-closure_template_library(
- name = "hello_soy",
- srcs = ["hello.soy"],
-)
-```
-
-## Known Issues
-
-The version of the Closure Templates compiler that is used will emit warnings
-about protected property access and about a missing enum value. These issues
-have been fixed in the source, but are not yet available as a downloadable
-archive. These warnings are safe to ignore.
-
-You may define a new_local_repository target if you wish to check out the source
-from Github yourself. Otherwise you may wish to wait until the Closure tools are
-available as Bazel workspaces. e.g.
-
-```python
-new_local_repository(
- name = "closure_templates",
- build_file = "tools/build_rules/closure/closure_templates.BUILD",
- path = "/home/user/src/github/google/closure-templates/target",
-)
-```
-
diff --git a/tools/build_rules/closure/closure_js_binary.bzl b/tools/build_rules/closure/closure_js_binary.bzl
deleted file mode 100644
index c4453ffb10..0000000000
--- a/tools/build_rules/closure/closure_js_binary.bzl
+++ /dev/null
@@ -1,124 +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.
-
-"""Build definitions for JavaScript binaries compiled with the Closure Compiler.
-
-A single file is produced with the _compiled.js suffix.
-
-By default, the name of the entry point is assumed to be the same as that of the
-build target. This behaviour may be overridden with the "main" attribute.
-
-The optimization level may be set with the "compilation_level" attribute.
-Supported values are: unobfuscated, simple, and advanced.
-
-Example:
-
- closure_js_binary(
- name = "hello",
- compilation_level = "simple",
- language_in = "ecmascript6",
- language_out = "ecmascript3",
- externs = ["//third_party/javascript/google_cast/cast.js"],
- deps = [
- "@closure_library//:closure_library",
- ":hello_lib",
- ],
- )
-
-This rule will produce hello_combined.js.
-"""
-
-_COMPILATION_LEVELS = {
- "whitespace_only": [
- "--compilation_level=WHITESPACE_ONLY",
- "--formatting=PRETTY_PRINT"
- ],
- "simple": ["--compilation_level=SIMPLE"],
- "advanced": ["--compilation_level=ADVANCED"]
-}
-
-_SUPPORTED_LANGUAGES = {
- "es3": ["ES3"],
- "ecmascript3": ["ECMASCRIPT3"],
- "es5": ["ES5"],
- "ecmascript5": ["ECMASCRIPT5"],
- "es5_strict": ["ES5_STRICT"],
- "ecmascript5_strict": ["ECMASCRIPT5_STRICT"],
- "es6": ["ES6"],
- "ecmascript6": ["ECMASCRIPT6"],
- "es6_strict": ["ES6_STRICT"],
- "ecmascript6_strict": ["ECMASCRIPT6_STRICT"],
- "es6_typed": ["ES6_TYPED"],
- "ecmascript6_typed": ["ECMASCRIPT6_TYPED"],
-}
-
-def _impl(ctx):
- externs = set(order="compile")
- srcs = set(order="compile")
- for dep in ctx.attr.deps:
- externs += dep.transitive_js_externs
- srcs += dep.transitive_js_srcs
-
- args = [
- "--entry_point=goog:%s" % ctx.attr.main,
- "--js_output_file=%s" % ctx.outputs.out.path,
- "--dependency_mode=LOOSE",
- "--warning_level=VERBOSE",
- ] + (["--js=%s" % src.path for src in srcs] +
- ["--externs=%s" % extern.path for extern in externs])
-
- # Set the compilation level.
- if ctx.attr.compilation_level in _COMPILATION_LEVELS:
- args += _COMPILATION_LEVELS[ctx.attr.compilation_level]
- else:
- fail("Invalid compilation_level '%s', expected one of %s" %
- (ctx.attr.compilation_level, _COMPILATION_LEVELS.keys()))
-
- # Set the language in.
- if ctx.attr.language_in in _SUPPORTED_LANGUAGES:
- args += "--language_in=" + _SUPPORTED_LANGUAGES[ctx.attr.language_in]
- else:
- fail("Invalid language_in '%s', expected one of %s" %
- (ctx.attr.language_in, _SUPPORTED_LANGUAGES.keys()))
-
- # Set the language out.
- if ctx.attr.language_out in _SUPPORTED_LANGUAGES:
- args += "--language_out=" + _SUPPORTED_LANGUAGES[ctx.attr.language_out]
- else:
- fail("Invalid language_out '%s', expected one of %s" %
- (ctx.attr.language_out, _SUPPORTED_LANGUAGES.keys()))
-
- ctx.action(
- inputs=list(srcs) + list(externs),
- outputs=[ctx.outputs.out],
- arguments=args,
- executable=ctx.executable._closure_compiler)
-
- return struct(files=set([ctx.outputs.out]))
-
-closure_js_binary = rule(
- implementation=_impl,
- attrs={
- "deps": attr.label_list(
- allow_files=False,
- providers=["transitive_js_externs", "transitive_js_srcs"]),
- "main": attr.string(default="%{name}"),
- "compilation_level": attr.string(default="advanced"),
- "language_in": attr.string(default="ecmascript6"),
- "language_out": attr.string(default="ecmascript3"),
- "_closure_compiler": attr.label(
- default=Label("//external:closure_compiler_"),
- executable=True),
- },
- outputs={"out": "%{name}_combined.js"})
diff --git a/tools/build_rules/closure/closure_js_library.bzl b/tools/build_rules/closure/closure_js_library.bzl
deleted file mode 100644
index b759b4989a..0000000000
--- a/tools/build_rules/closure/closure_js_library.bzl
+++ /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.
-
-"""Build definitions for JavaScript libraries. The library targets may be used
-in closure_js_binary rules.
-
-Example:
-
- closure_js_library(
- name = "hello_lib",
- srcs = ["hello.js"],
- deps = ["//third_party/javascript/closure_library"],
- )
-"""
-
-_JS_FILE_TYPE = FileType([".js"])
-
-def _impl(ctx):
- externs = set(order="compile")
- srcs = set(order="compile")
- for dep in ctx.attr.deps:
- externs += dep.transitive_js_externs
- srcs += dep.transitive_js_srcs
-
- externs += _JS_FILE_TYPE.filter(ctx.files.externs)
- srcs += _JS_FILE_TYPE.filter(ctx.files.srcs)
-
- return struct(
- files=set(), transitive_js_externs=externs, transitive_js_srcs=srcs)
-
-closure_js_library = rule(
- implementation=_impl,
- attrs={
- "externs": attr.label_list(allow_files=_JS_FILE_TYPE),
- "srcs": attr.label_list(allow_files=_JS_FILE_TYPE),
- "deps": attr.label_list(
- providers=["transitive_js_externs", "transitive_js_srcs"])
- })
diff --git a/tools/build_rules/closure/closure_repositories.bzl b/tools/build_rules/closure/closure_repositories.bzl
deleted file mode 100644
index f67f76f7d4..0000000000
--- a/tools/build_rules/closure/closure_repositories.bzl
+++ /dev/null
@@ -1,114 +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.
-
-CLOSURE_COMPILER_BUILD_FILE = """
-java_import(
- name = "closure_compiler_jar",
- jars = ["compiler.jar"],
-)
-
-java_binary(
- name = "closure_compiler",
- main_class = "com.google.javascript.jscomp.CommandLineRunner",
- visibility = ["//visibility:public"],
- runtime_deps = [":closure_compiler_jar"],
-)
-"""
-
-CLOSURE_LIBRARY_BUILD_FILE = """
-load("@bazel_tools//tools/build_rules/closure:closure_js_library.bzl", "closure_js_library")
-load("@bazel_tools//tools/build_rules/closure:closure_stylesheet_library.bzl", "closure_stylesheet_library")
-
-closure_js_library(
- name = "closure_library",
- srcs = glob(
- [
- "closure/goog/**/*.js",
- "third_party/closure/goog/**/*.js",
- ],
- exclude = [
- "closure/goog/**/*_test.js",
- "closure/goog/demos/**/*.js",
- "third_party/closure/goog/**/*_test.js",
- ],
- ),
- visibility = ["//visibility:public"],
-)
-
-closure_stylesheet_library(
- name = "closure_library_css",
- srcs = glob(["closure/goog/css/**/*.css"]),
- visibility = ["//visibility:public"],
-)
-"""
-
-CLOSURE_TEMPLATES_BUILD_FILE = """
-load("@bazel_tools//tools/build_rules/closure:closure_js_library.bzl", "closure_js_library")
-
-java_import(
- name = "closure_templates_jar",
- jars = ["SoyToJsSrcCompiler.jar"],
-)
-
-java_binary(
- name = "closure_templates",
- main_class = "com.google.template.soy.SoyToJsSrcCompiler",
- visibility = ["//visibility:public"],
- runtime_deps = [":closure_templates_jar"],
-)
-
-closure_js_library(
- name = "closure_templates_js",
- srcs = ["soyutils_usegoog.js"],
- visibility = ["//visibility:public"],
-)
-"""
-
-def closure_repositories():
- native.new_http_archive(
- name = "closure_compiler",
- build_file_content = CLOSURE_COMPILER_BUILD_FILE,
- sha256 = "215ba5df026e5d92bda6634463a9c634d38a1aa4b6dab336da5c52e884cbde95",
- url = "https://dl.google.com/closure-compiler/compiler-20160208.zip",
- )
-
- native.new_http_archive(
- name = "closure_library",
- build_file_content = CLOSURE_LIBRARY_BUILD_FILE,
- sha256 = "8f610300e4930190137505a574a54d12346426f2a7b4f179026e41674e452a86",
- url = "https://github.com/google/closure-library/archive/20160208.zip",
- )
-
- native.http_jar(
- name = "closure_stylesheets",
- sha256 = "5308cb46f7677b9995237ade57770d27592aff69359d29be571220a2bf10e724",
- url = "https://github.com/google/closure-stylesheets/releases/download/v1.1.0/closure-stylesheets.jar",
- )
-
- native.new_http_archive(
- name = "closure_templates",
- build_file_content = CLOSURE_TEMPLATES_BUILD_FILE,
- sha256 = "cdd94123cd0d1c3a183c15e855739c0aa5390297c22dddc731b8d7b23815e8a2",
- url = "http://dl.google.com/closure-templates/closure-templates-for-javascript-latest.zip",
- )
-
- native.bind(
- name = "closure_compiler_",
- actual = "@closure_compiler//:closure_compiler",
- )
-
- native.bind(
- name = "closure_templates_",
- actual = "@closure_templates//:closure_templates",
- )
diff --git a/tools/build_rules/closure/closure_stylesheet_library.bzl b/tools/build_rules/closure/closure_stylesheet_library.bzl
deleted file mode 100644
index c1532c0547..0000000000
--- a/tools/build_rules/closure/closure_stylesheet_library.bzl
+++ /dev/null
@@ -1,82 +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.
-
-"""Build definitions for Closure stylesheets. Two files are produced: a minified
-and obfuscated CSS file and a JS file defining a map between CSS classes and the
-obfuscated class name. The stylesheet targets may be used in closure_js_binary
-rules.
-
-Both CSS and GSS files may be used with this rule.
-
-Example:
-
- closure_stylesheet_library(
- name = "hello_css",
- srcs = ["hello.gss"].
- )
-
-This rule will produce hello_css_combined.css and hello_css_renaming.js.
-"""
-
-_GSS_FILE_TYPE = FileType([".css", ".gss"])
-
-def _impl(ctx):
- srcs = set(order="compile")
- for dep in ctx.attr.deps:
- srcs += dep.transitive_gss_srcs
-
- srcs += _GSS_FILE_TYPE.filter(ctx.files.srcs)
-
- args = [
- "--output-file",
- ctx.outputs.out.path,
- "--output-renaming-map",
- ctx.outputs.out_renaming.path,
- "--output-renaming-map-format",
- "CLOSURE_COMPILED",
- "--rename",
- "CLOSURE"
- ] + [src.path for src in srcs]
-
- ctx.action(
- inputs=list(srcs),
- outputs=[ctx.outputs.out, ctx.outputs.out_renaming],
- arguments=args,
- executable=ctx.executable._closure_stylesheets)
-
- return struct(
- files=set([ctx.outputs.out]),
- transitive_gss_srcs=srcs,
- transitive_js_externs=set(),
- transitive_js_srcs=[ctx.outputs.out_renaming])
-
-# There are two outputs:
-# - %{name}_combined.css: A minified and obfuscated CSS file.
-# - %{name}_renaming.js: A map from the original CSS class name to the
-# obfuscated name. This file is used by
-# closure_js_binary rules.
-closure_stylesheet_library = rule(
- implementation=_impl,
- attrs={
- "srcs": attr.label_list(allow_files=_GSS_FILE_TYPE),
- "deps": attr.label_list(
- providers=["transitive_gss_srcs", "transitive_js_srcs"]),
- "_closure_stylesheets": attr.label(
- default=Label("//tools/build_rules/closure:closure_stylesheets"),
- executable=True),
- },
- outputs={
- "out": "%{name}_combined.css",
- "out_renaming": "%{name}_renaming.js"
- })
diff --git a/tools/build_rules/closure/closure_template_library.bzl b/tools/build_rules/closure/closure_template_library.bzl
deleted file mode 100644
index 94f246aa2a..0000000000
--- a/tools/build_rules/closure/closure_template_library.bzl
+++ /dev/null
@@ -1,59 +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.
-
-"""Build definitions for Closure templates. The template targets may be used in
-closure_js_binary rules.
-
-Example:
-
- closure_template_library(
- name = "hello_soy",
- srcs = ["hello.soy"],
- )
-
-This rule will produce hello_soy.js.
-"""
-
-_SOY_FILE_TYPE = FileType([".soy"])
-
-def _impl(ctx):
- srcs = ctx.files.srcs
- args = [
- "--outputPathFormat",
- ctx.outputs.out.path,
- "--shouldGenerateJsdoc",
- "--shouldProvideRequireSoyNamespaces",
- "--srcs",
- ",".join([src.path for src in srcs])
- ]
-
- ctx.action(
- inputs=list(srcs),
- outputs=[ctx.outputs.out],
- arguments=args,
- executable=ctx.executable._closure_templates)
-
- return struct(
- files=set(), transitive_js_externs=set(),
- transitive_js_srcs=set([ctx.outputs.out]))
-
-closure_template_library = rule(
- implementation=_impl,
- attrs={
- "srcs": attr.label_list(allow_files=_SOY_FILE_TYPE),
- "_closure_templates": attr.label(
- default=Label("//external:closure_templates_"),
- executable=True),
- },
- outputs={"out": "%{name}.js"})