mirror of
https://github.com/google/nomulus.git
synced 2025-07-02 01:03:33 +02:00
Import code from internal repository to git
This commit is contained in:
commit
0ef0c933d2
2490 changed files with 281594 additions and 0 deletions
10
third_party/closure/compiler/BUILD
vendored
Normal file
10
third_party/closure/compiler/BUILD
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"]) # Apache License 2.0
|
||||
|
||||
java_binary(
|
||||
name = "compiler",
|
||||
jvm_flags = ["-client"],
|
||||
main_class = "com.google.javascript.jscomp.CommandLineRunner",
|
||||
runtime_deps = ["@closure_compiler//jar"],
|
||||
)
|
96
third_party/closure/compiler/closure_js_binary.bzl
vendored
Normal file
96
third_party/closure/compiler/closure_js_binary.bzl
vendored
Normal file
|
@ -0,0 +1,96 @@
|
|||
# -*- mode: python; -*-
|
||||
#
|
||||
# Copyright 2016 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.
|
||||
|
||||
"""Rule for building JavaScript binaries with Closure Compiler.
|
||||
"""
|
||||
|
||||
load("//third_party/closure/compiler/private:defs.bzl",
|
||||
"JS_LANGUAGE_DEFAULT",
|
||||
"JS_LIBRARY_ATTRS",
|
||||
"JS_PEDANTIC_ARGS",
|
||||
"JS_HIDE_WARNING_ARGS",
|
||||
"check_js_language",
|
||||
"collect_js_srcs",
|
||||
"determine_js_language",
|
||||
"is_using_closure_library")
|
||||
|
||||
def _impl(ctx):
|
||||
srcs, externs = collect_js_srcs(ctx)
|
||||
check_js_language(ctx.attr.language_in)
|
||||
check_js_language(ctx.attr.language_out)
|
||||
dependent_language = determine_js_language(ctx)
|
||||
if ctx.attr.language_in != dependent_language:
|
||||
fail("language_in was %s but dependencies use %s" % (
|
||||
ctx.attr.language_in, dependent_language))
|
||||
args = [
|
||||
"--js_output_file=%s" % ctx.outputs.out.path,
|
||||
"--create_source_map=%s" % ctx.outputs.srcmap.path,
|
||||
"--language_in=%s" % ctx.attr.language_in,
|
||||
"--language_out=%s" % ctx.attr.language_out,
|
||||
"--compilation_level=" + ctx.attr.compilation_level,
|
||||
"--warning_level=VERBOSE",
|
||||
"--new_type_inf",
|
||||
"--generate_exports",
|
||||
]
|
||||
args += JS_HIDE_WARNING_ARGS
|
||||
if ctx.attr.formatting:
|
||||
args += ["--formatting=" + ctx.attr.formatting]
|
||||
if ctx.attr.debug:
|
||||
args += ["--debug"]
|
||||
else:
|
||||
if is_using_closure_library(srcs):
|
||||
args += ["--define=goog.DEBUG=false"]
|
||||
if ctx.attr.main:
|
||||
args += [
|
||||
"--dependency_mode=STRICT",
|
||||
"--entry_point=goog:%s" % ctx.attr.main,
|
||||
]
|
||||
else:
|
||||
args += ["--dependency_mode=LOOSE"]
|
||||
if ctx.attr.pedantic:
|
||||
args += JS_PEDANTIC_ARGS
|
||||
args += ["--use_types_for_optimization"]
|
||||
args += ctx.attr.defs
|
||||
args += ["--externs=%s" % extern.path for extern in externs]
|
||||
args += ["--js=%s" % src.path for src in srcs]
|
||||
ctx.action(
|
||||
inputs=list(srcs) + list(externs),
|
||||
outputs=[ctx.outputs.out, ctx.outputs.srcmap],
|
||||
executable=ctx.executable._compiler,
|
||||
arguments=args,
|
||||
mnemonic="JSCompile",
|
||||
progress_message="Compiling %d JavaScript files to %s" % (
|
||||
len(srcs) + len(externs),
|
||||
ctx.outputs.out.short_path))
|
||||
return struct(files=set([ctx.outputs.out]))
|
||||
|
||||
closure_js_binary = rule(
|
||||
implementation=_impl,
|
||||
attrs=JS_LIBRARY_ATTRS + {
|
||||
"main": attr.string(),
|
||||
"compilation_level": attr.string(default="ADVANCED"),
|
||||
"defs": attr.string_list(),
|
||||
"pedantic": attr.bool(default=False),
|
||||
"debug": attr.bool(default=False),
|
||||
"formatting": attr.string(),
|
||||
"language_in": attr.string(default=JS_LANGUAGE_DEFAULT),
|
||||
"language_out": attr.string(default="ECMASCRIPT3"),
|
||||
"_compiler": attr.label(
|
||||
default=Label("//third_party/closure/compiler"),
|
||||
executable=True),
|
||||
},
|
||||
outputs={"out": "%{name}.js",
|
||||
"srcmap": "%{name}.sourcemap"})
|
69
third_party/closure/compiler/closure_js_check_test.bzl
vendored
Normal file
69
third_party/closure/compiler/closure_js_check_test.bzl
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
# -*- mode: python; -*-
|
||||
#
|
||||
# Copyright 2016 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.
|
||||
|
||||
"""Test rule for validating JavaScript types but not producing a compiled file.
|
||||
"""
|
||||
|
||||
load("//third_party/closure/compiler/private:defs.bzl",
|
||||
"JS_LANGUAGE_DEFAULT",
|
||||
"JS_LIBRARY_ATTRS",
|
||||
"JS_PEDANTIC_ARGS",
|
||||
"JS_HIDE_WARNING_ARGS",
|
||||
"check_js_language",
|
||||
"collect_js_srcs",
|
||||
"determine_js_language",
|
||||
"is_using_closure_library")
|
||||
|
||||
def _impl(ctx):
|
||||
srcs, externs = collect_js_srcs(ctx)
|
||||
args = [
|
||||
"third_party/closure/compiler/compiler",
|
||||
"--checks-only",
|
||||
"--language_in=%s" % determine_js_language(ctx),
|
||||
"--compilation_level=" + ctx.attr.compilation_level,
|
||||
"--warning_level=VERBOSE",
|
||||
"--new_type_inf",
|
||||
]
|
||||
if is_using_closure_library(srcs):
|
||||
args += ["--dependency_mode=LOOSE"]
|
||||
if ctx.attr.pedantic:
|
||||
args += JS_PEDANTIC_ARGS
|
||||
args += JS_HIDE_WARNING_ARGS
|
||||
args += ctx.attr.defs
|
||||
args += ["--externs='%s'" % extern.path for extern in externs]
|
||||
args += ["--js='%s'" % src.path for src in srcs]
|
||||
ctx.file_action(
|
||||
executable=True,
|
||||
output=ctx.outputs.executable,
|
||||
content="#!/bin/sh\nexec " + " \\\n ".join(args) + "\n")
|
||||
return struct(files=set([ctx.outputs.executable]),
|
||||
runfiles=ctx.runfiles(
|
||||
files=list(srcs) + list(externs),
|
||||
transitive_files=ctx.attr._compiler.data_runfiles.files,
|
||||
collect_data=True))
|
||||
|
||||
closure_js_check_test = rule(
|
||||
test=True,
|
||||
implementation=_impl,
|
||||
attrs=JS_LIBRARY_ATTRS + {
|
||||
"compilation_level": attr.string(default="ADVANCED"),
|
||||
"defs": attr.string_list(),
|
||||
"pedantic": attr.bool(default=False),
|
||||
"language": attr.string(default=JS_LANGUAGE_DEFAULT),
|
||||
"_compiler": attr.label(
|
||||
default=Label("//third_party/closure/compiler"),
|
||||
executable=True),
|
||||
})
|
54
third_party/closure/compiler/closure_js_deps.bzl
vendored
Normal file
54
third_party/closure/compiler/closure_js_deps.bzl
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
# -*- mode: python; -*-
|
||||
#
|
||||
# Copyright 2016 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.
|
||||
|
||||
"""Build definitions for JavaScript dependency files.
|
||||
|
||||
Generating this file is important because the deps-runfiles.js file tells the
|
||||
Closure Library how to send requests to the web server to load goog.require'd
|
||||
namespaces.
|
||||
"""
|
||||
|
||||
load("//third_party/closure/compiler/private:defs.bzl",
|
||||
"JS_FILE_TYPE",
|
||||
"make_js_deps_runfiles")
|
||||
|
||||
def _impl(ctx):
|
||||
srcs = set(order="compile")
|
||||
for src in ctx.attr.srcs:
|
||||
srcs += src.transitive_js_srcs
|
||||
ctx.action(
|
||||
inputs=list(srcs),
|
||||
outputs=[ctx.outputs.out],
|
||||
arguments=(["--output_file=%s" % (ctx.outputs.out.path)] +
|
||||
[src.path for src in srcs]),
|
||||
executable=ctx.executable._depswriter,
|
||||
progress_message="Calculating %d JavaScript deps to %s" % (
|
||||
len(srcs), ctx.outputs.out.short_path))
|
||||
make_js_deps_runfiles(ctx, srcs)
|
||||
return struct(files=set([ctx.outputs.out, ctx.outputs.runfiles]))
|
||||
|
||||
closure_js_deps = rule(
|
||||
implementation=_impl,
|
||||
attrs={
|
||||
"srcs": attr.label_list(
|
||||
allow_files=False,
|
||||
providers=["transitive_js_srcs"]),
|
||||
"_depswriter": attr.label(
|
||||
default=Label("@closure_library//:depswriter"),
|
||||
executable=True),
|
||||
},
|
||||
outputs={"out": "%{name}.js",
|
||||
"runfiles": "%{name}-runfiles.js"})
|
40
third_party/closure/compiler/closure_js_library.bzl
vendored
Normal file
40
third_party/closure/compiler/closure_js_library.bzl
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
# -*- mode: python; -*-
|
||||
#
|
||||
# Copyright 2016 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.
|
||||
|
||||
"""Build definitions for Closure JavaScript libraries.
|
||||
"""
|
||||
|
||||
load("//third_party/closure/compiler/private:defs.bzl",
|
||||
"JS_LANGUAGE_DEFAULT",
|
||||
"JS_DEPS_ATTR",
|
||||
"JS_LIBRARY_ATTRS",
|
||||
"collect_js_srcs",
|
||||
"determine_js_language")
|
||||
|
||||
def _impl(ctx):
|
||||
srcs, externs = collect_js_srcs(ctx)
|
||||
return struct(files=set(ctx.files.srcs),
|
||||
js_language=determine_js_language(ctx),
|
||||
js_exports=ctx.files.exports,
|
||||
transitive_js_srcs=srcs,
|
||||
transitive_js_externs=externs)
|
||||
|
||||
closure_js_library = rule(
|
||||
implementation=_impl,
|
||||
attrs=JS_LIBRARY_ATTRS + {
|
||||
"exports": JS_DEPS_ATTR,
|
||||
"language": attr.string(default=JS_LANGUAGE_DEFAULT),
|
||||
})
|
1
third_party/closure/compiler/private/BUILD
vendored
Normal file
1
third_party/closure/compiler/private/BUILD
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
package(default_visibility = ["//third_party/closure:__subpackages__"])
|
173
third_party/closure/compiler/private/defs.bzl
vendored
Normal file
173
third_party/closure/compiler/private/defs.bzl
vendored
Normal file
|
@ -0,0 +1,173 @@
|
|||
# -*- mode: python; -*-
|
||||
#
|
||||
# Copyright 2016 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.
|
||||
|
||||
"""Common build definitions for Closure Compiler build definitions.
|
||||
"""
|
||||
|
||||
JS_LANGUAGE_DEFAULT = "ECMASCRIPT6_STRICT"
|
||||
JS_FILE_TYPE = FileType([".js"])
|
||||
JS_TEST_FILE_TYPE = FileType(["_test.js"])
|
||||
_CLOSURE_ROOT = "external/closure_library/closure/goog"
|
||||
_CLOSURE_REL = "../../../.."
|
||||
|
||||
JS_LANGUAGES = set([
|
||||
"ANY",
|
||||
"ECMASCRIPT3",
|
||||
"ECMASCRIPT5",
|
||||
"ECMASCRIPT5_STRICT",
|
||||
"ECMASCRIPT6",
|
||||
"ECMASCRIPT6_STRICT",
|
||||
"ECMASCRIPT6_TYPED",
|
||||
])
|
||||
|
||||
JS_DEPS_ATTR = attr.label_list(
|
||||
allow_files=False,
|
||||
providers=["js_language",
|
||||
"js_exports",
|
||||
"transitive_js_srcs",
|
||||
"transitive_js_externs"])
|
||||
|
||||
JS_LIBRARY_ATTRS = {
|
||||
"srcs": attr.label_list(allow_files=JS_FILE_TYPE),
|
||||
"externs_list": attr.label_list(allow_files=JS_FILE_TYPE),
|
||||
"deps": JS_DEPS_ATTR,
|
||||
}
|
||||
|
||||
JS_PEDANTIC_ARGS = [
|
||||
"--jscomp_error=*",
|
||||
"--jscomp_warning=deprecated",
|
||||
"--jscomp_warning=unnecessaryCasts",
|
||||
]
|
||||
|
||||
JS_HIDE_WARNING_ARGS = [
|
||||
"--hide_warnings_for=.soy.js",
|
||||
"--hide_warnings_for=external/closure_library/",
|
||||
"--hide_warnings_for=external/soyutils_usegoog/",
|
||||
]
|
||||
|
||||
def collect_js_srcs(ctx):
|
||||
srcs = set(order="compile")
|
||||
externs = set(order="compile")
|
||||
for dep in ctx.attr.deps:
|
||||
srcs += dep.js_exports
|
||||
srcs += dep.transitive_js_srcs
|
||||
externs += dep.transitive_js_externs
|
||||
srcs += JS_FILE_TYPE.filter(ctx.files.srcs)
|
||||
externs += JS_FILE_TYPE.filter(ctx.files.externs_list)
|
||||
return srcs, externs
|
||||
|
||||
def check_js_language(language):
|
||||
if language not in JS_LANGUAGES:
|
||||
fail("Invalid JS language '%s', expected one of %s" % (
|
||||
language, ', '.join(list(JS_LANGUAGES))))
|
||||
return language
|
||||
|
||||
def determine_js_language(ctx):
|
||||
language = None
|
||||
if hasattr(ctx.attr, 'language'):
|
||||
language = check_js_language(ctx.attr.language)
|
||||
for dep in ctx.attr.deps:
|
||||
language = _mix_js_languages(language, dep.js_language)
|
||||
if hasattr(ctx.attr, 'exports'):
|
||||
for dep in ctx.attr.deps:
|
||||
language = _mix_js_languages(language, dep.js_language)
|
||||
return language or JS_LANGUAGE_DEFAULT
|
||||
|
||||
def make_js_deps_runfiles(ctx, srcs):
|
||||
ctx.action(
|
||||
inputs=list(srcs),
|
||||
outputs=[ctx.outputs.runfiles],
|
||||
arguments=(["--output_file=%s" % ctx.outputs.runfiles.path] +
|
||||
["--root_with_prefix=%s %s" % (r, _make_prefix(p))
|
||||
for r, p in _find_roots(
|
||||
[(src.dirname, src.short_path) for src in srcs])]),
|
||||
executable=ctx.executable._depswriter,
|
||||
progress_message="Calculating %d JavaScript runfile deps to %s" % (
|
||||
len(srcs), ctx.outputs.runfiles.short_path))
|
||||
|
||||
def is_using_closure_library(srcs):
|
||||
return _contains_file(srcs, "external/closure_library/closure/goog/base.js")
|
||||
|
||||
_JS_LANGUAGE_COMPATIBILITY = set([
|
||||
("ECMASCRIPT5", "ECMASCRIPT3"),
|
||||
("ECMASCRIPT5", "ECMASCRIPT5_STRICT"),
|
||||
("ECMASCRIPT6", "ECMASCRIPT3"),
|
||||
("ECMASCRIPT6", "ECMASCRIPT5"),
|
||||
("ECMASCRIPT6", "ECMASCRIPT5_STRICT"),
|
||||
("ECMASCRIPT6", "ECMASCRIPT6_STRICT"),
|
||||
("ECMASCRIPT6_STRICT", "ECMASCRIPT5_STRICT"),
|
||||
("ECMASCRIPT6_TYPED", "ECMASCRIPT6_STRICT"),
|
||||
("ECMASCRIPT6_TYPED", "ECMASCRIPT5_STRICT"),
|
||||
])
|
||||
|
||||
_JS_LANGUAGE_DECAY = {
|
||||
("ECMASCRIPT5_STRICT", "ECMASCRIPT3"): "ECMASCRIPT5",
|
||||
("ECMASCRIPT5_STRICT", "ECMASCRIPT5"): "ECMASCRIPT5",
|
||||
("ECMASCRIPT6_STRICT", "ECMASCRIPT3"): "ECMASCRIPT6",
|
||||
("ECMASCRIPT6_STRICT", "ECMASCRIPT5"): "ECMASCRIPT6",
|
||||
("ECMASCRIPT6_STRICT", "ECMASCRIPT6"): "ECMASCRIPT6",
|
||||
}
|
||||
|
||||
def _mix_js_languages(current, dependent):
|
||||
if not current:
|
||||
return dependent
|
||||
if current == dependent:
|
||||
return current
|
||||
if current == "ANY":
|
||||
return dependent
|
||||
if dependent == "ANY":
|
||||
return current
|
||||
if (current, dependent) in _JS_LANGUAGE_COMPATIBILITY:
|
||||
return current
|
||||
decay = _JS_LANGUAGE_DECAY[(current, dependent)]
|
||||
if decay:
|
||||
print("Dependency causing JS strictness to decay from %s to %s :(" % (
|
||||
current, decay))
|
||||
return dependent
|
||||
decay = _JS_LANGUAGE_DECAY[(dependent, current)]
|
||||
if decay:
|
||||
return dependent
|
||||
fail("Can not link an %s library against an %s one." % (dependent, current))
|
||||
|
||||
def _find_roots(dirs):
|
||||
roots = {}
|
||||
for _, d, p in sorted([(len(d.split("/")), d, p) for d, p in dirs]):
|
||||
parts = d.split("/")
|
||||
want = True
|
||||
for i in range(len(parts)):
|
||||
if "/".join(parts[:i + 1]) in roots:
|
||||
want = False
|
||||
break
|
||||
if want:
|
||||
roots[d] = p
|
||||
return roots.items()
|
||||
|
||||
def _make_prefix(prefix):
|
||||
prefix = "/".join(prefix.split("/")[:-1])
|
||||
if not prefix:
|
||||
return _CLOSURE_REL
|
||||
elif prefix == _CLOSURE_ROOT:
|
||||
return "."
|
||||
elif prefix.startswith(_CLOSURE_ROOT + "/"):
|
||||
return prefix[len(_CLOSURE_ROOT) + 1:]
|
||||
else:
|
||||
return _CLOSURE_REL + "/" + prefix
|
||||
|
||||
def _contains_file(srcs, path):
|
||||
for src in srcs:
|
||||
if src.short_path == path:
|
||||
return True
|
||||
return False
|
Loading…
Add table
Add a link
Reference in a new issue