Skip to content

Commit 5aa82d7

Browse files
authored
Revert "cleanup: Delete unused rules and arguments in build toolchain (#5981)" (#5982)
The tensorboard_typescript_bundle macro is used internally so we can't delete it yet.
1 parent 007f54b commit 5aa82d7

File tree

3 files changed

+92
-3
lines changed

3 files changed

+92
-3
lines changed

tensorboard/defs/defs.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ def tf_ts_library(strict_checks = True, **kwargs):
9898

9999
if strict_checks == False:
100100
tsconfig = "//:tsconfig-lax"
101+
elif "test_only" in kwargs and kwargs.get("test_only"):
102+
tsconfig = "//:tsconfig-test"
101103
kwargs.setdefault("deps", []).extend(["@npm//tslib", "//tensorboard/defs:strict_types"])
102104

103105
ts_library(tsconfig = tsconfig, supports_workers = True, **kwargs)
104106

105-
def tf_ng_web_test_suite(deps = [], **kwargs):
107+
def tf_ng_web_test_suite(runtime_deps = [], bootstrap = [], deps = [], **kwargs):
106108
"""TensorBoard wrapper for the rule for a Karma web test suite.
107109
108110
It has Angular specific configurations that we want as defaults.
@@ -113,12 +115,12 @@ def tf_ng_web_test_suite(deps = [], **kwargs):
113115
srcs = [
114116
"//tensorboard/webapp/testing:require_js_karma_config.js",
115117
],
116-
bootstrap = [
118+
bootstrap = bootstrap + [
117119
"@npm//:node_modules/zone.js/dist/zone-testing-bundle.js",
118120
"@npm//:node_modules/reflect-metadata/Reflect.js",
119121
"@npm//:node_modules/@angular/localize/bundles/localize-init.umd.js",
120122
],
121-
runtime_deps = [
123+
runtime_deps = runtime_deps + [
122124
"//tensorboard/webapp/testing:initialize_testbed",
123125
],
124126
deps = deps + [

tensorboard/defs/hacks.bzl

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Compatibility hacks."""
15+
16+
# TODO(@jart): Merge this file into defs.bzl once that file is sync unified.
17+
18+
def tensorboard_typescript_bundle(
19+
name,
20+
out,
21+
namespace_srcs,
22+
namespace_symbol_aliases={},
23+
namespace_symbol_aliases_public={},
24+
):
25+
"""Rolls TypeScript ES6 modules into one vanilla source file without imports.
26+
27+
This is a genrule wrapper that concatenates TypeScripts sources inside
28+
namespace blocks while removing ^import lines. Because the sources themselves
29+
are not parsed, the structure of the modules must be passed to this macro as
30+
a Skylark data structure.
31+
32+
Args:
33+
name: Name of this build rule target.
34+
out: Path of outputted TypeScript source file.
35+
namespace_srcs: Multimap of namespace strings to build file targets. The
36+
ordering of the dictionary and nested lists does not matter when
37+
generating a typings file, but *does* matter when generating a source
38+
file.
39+
namespace_symbol_aliases: Map of namespace strings where each value is a
40+
map of symbol names to fully qualified symbol names.
41+
namespace_symbol_aliases_public: Same as namespace_symbol_aliases but the
42+
symbol will be visible to other namespaces.
43+
"""
44+
cmd = ["(", "echo // GENERATED BY TENSORBOARD_TYPESCRIPT_BUNDLE"]
45+
inputs_depsets = []
46+
for namespace, srcs in namespace_srcs.items():
47+
cmd.append("echo")
48+
if out[-5:] == ".d.ts":
49+
cmd.append("echo 'declare namespace %s {'" % namespace)
50+
elif out[-3:] == ".ts":
51+
cmd.append("echo 'module %s {'" % namespace)
52+
else:
53+
fail("'out' must end with .ts or .d.ts: " + out)
54+
for symbol, canon in namespace_symbol_aliases.get(namespace, {}).items():
55+
cmd.append("echo 'import %s = %s;'" % (symbol, canon))
56+
for symbol, canon in namespace_symbol_aliases_public.get(namespace,
57+
{}).items():
58+
cmd.append("echo 'export import %s = %s;'" % (symbol, canon))
59+
inputs_depsets.append(depset(srcs))
60+
for src in srcs:
61+
cmd.append("for f in $(locations %s); do" % src)
62+
cmd.append(" echo")
63+
cmd.append(" echo /////////////////////////////////////////////////////")
64+
cmd.append(" echo // " + namespace)
65+
cmd.append(" echo // $$f")
66+
cmd.append(" echo /////////////////////////////////////////////////////")
67+
cmd.append(" echo")
68+
cmd.append(" sed 's!^import !// import !' $$f \\")
69+
cmd.append(" | sed 's!^export declare !export !' \\")
70+
cmd.append(" | sed '/^export .* from /d' \\")
71+
cmd.append(" | sed '/^export {.*};$$/d'")
72+
cmd.append("done")
73+
cmd.append("echo '}'")
74+
cmd.append(") >$@")
75+
native.genrule(
76+
name = name,
77+
srcs = depset(transitive=inputs_depsets).to_list(),
78+
outs = [out],
79+
cmd = "\n".join(cmd),
80+
)

tsconfig-test.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"importHelpers": true,
5+
"types": ["jasmine"]
6+
}
7+
}

0 commit comments

Comments
 (0)