aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Justine Tunney <jart@google.com>2017-06-13 19:29:45 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-06-13 22:04:47 -0700
commit9263faf2a7c413e4f7a5fdc6a56152ec9c2c316b (patch)
tree3b0f3e265134858f10784c53a44545ced80f69c5
parentb6039c875290cdd5c9a62e01393b75b928827504 (diff)
Use correct NumericJS in open source
The GitHub source turns out to be very different from what's on the web server. Because the source code has a lot of </script> tags in the comments, which are difficult for jsoup to escape, I had to add a basic minifier feature to Vulcanize. So as a bonus, this change makes the TensorBoard binary much smaller too. PiperOrigin-RevId: 158932524
-rw-r--r--tensorflow/tensorboard/components/tf_imports/dagre.html2
-rw-r--r--tensorflow/tensorboard/components/tf_imports/graphlib.html2
-rw-r--r--tensorflow/tensorboard/components/tf_imports/lodash.html2
-rw-r--r--tensorflow/tensorboard/components/tf_imports/numericjs.html2
-rw-r--r--tensorflow/tensorboard/java/org/tensorflow/tensorboard/vulcanize/Vulcanize.java29
-rw-r--r--tensorflow/tensorboard/java/org/tensorflow/tensorboard/vulcanize/externs.js1
-rw-r--r--third_party/js.bzl7
7 files changed, 37 insertions, 8 deletions
diff --git a/tensorflow/tensorboard/components/tf_imports/dagre.html b/tensorflow/tensorboard/components/tf_imports/dagre.html
index b90dc58e39..49522db38a 100644
--- a/tensorflow/tensorboard/components/tf_imports/dagre.html
+++ b/tensorflow/tensorboard/components/tf_imports/dagre.html
@@ -42,4 +42,4 @@ THE SOFTWARE.
<link rel="import" href="lodash.html">
<link rel="import" href="graphlib.html">
-<script jscomp-nocompile src="dagre.core.js"></script>
+<script jscomp-minify src="dagre.core.js"></script>
diff --git a/tensorflow/tensorboard/components/tf_imports/graphlib.html b/tensorflow/tensorboard/components/tf_imports/graphlib.html
index 664b855f17..aa868b00b4 100644
--- a/tensorflow/tensorboard/components/tf_imports/graphlib.html
+++ b/tensorflow/tensorboard/components/tf_imports/graphlib.html
@@ -17,4 +17,4 @@ limitations under the License.
<link rel="import" href="lodash.html">
-<script jscomp-nocompile src="graphlib.core.js"></script>
+<script jscomp-minify src="graphlib.core.js"></script>
diff --git a/tensorflow/tensorboard/components/tf_imports/lodash.html b/tensorflow/tensorboard/components/tf_imports/lodash.html
index 65ff6a4b03..192e61cc99 100644
--- a/tensorflow/tensorboard/components/tf_imports/lodash.html
+++ b/tensorflow/tensorboard/components/tf_imports/lodash.html
@@ -15,4 +15,4 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
-<script jscomp-nocompile src="../lodash/lodash.js"></script>
+<script jscomp-minify src="../lodash/lodash.js"></script>
diff --git a/tensorflow/tensorboard/components/tf_imports/numericjs.html b/tensorflow/tensorboard/components/tf_imports/numericjs.html
index 81fa949168..69e948eb99 100644
--- a/tensorflow/tensorboard/components/tf_imports/numericjs.html
+++ b/tensorflow/tensorboard/components/tf_imports/numericjs.html
@@ -40,4 +40,4 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
-<script jscomp-suppress src="numeric.js"></script>
+<script jscomp-minify src="numeric.js"></script>
diff --git a/tensorflow/tensorboard/java/org/tensorflow/tensorboard/vulcanize/Vulcanize.java b/tensorflow/tensorboard/java/org/tensorflow/tensorboard/vulcanize/Vulcanize.java
index 533907dd64..80e48124eb 100644
--- a/tensorflow/tensorboard/java/org/tensorflow/tensorboard/vulcanize/Vulcanize.java
+++ b/tensorflow/tensorboard/java/org/tensorflow/tensorboard/vulcanize/Vulcanize.java
@@ -24,6 +24,7 @@ import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Splitter;
import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@@ -259,12 +260,18 @@ public final class Vulcanize {
path = me().lookup(Webpath.get(node.attr("src")));
script = new String(Files.readAllBytes(getWebfile(path)), UTF_8);
}
+ boolean wantsMinify = getAttrTransitive(node, "jscomp-minify").isPresent();
if (node.attr("src").endsWith(".min.js")
- || getAttrTransitive(node, "jscomp-nocompile").isPresent()) {
+ || getAttrTransitive(node, "jscomp-nocompile").isPresent()
+ || wantsMinify) {
+ if (wantsMinify) {
+ script = minify(path, script);
+ }
Node newScript =
new Element(Tag.valueOf("script"), node.baseUri(), node.attributes())
.appendChild(new DataNode(script, node.baseUri()))
.removeAttr("src")
+ .removeAttr("jscomp-minify")
.removeAttr("jscomp-nocompile");
if (firstCompiledScript != null) {
firstCompiledScript.before(newScript);
@@ -458,6 +465,26 @@ public final class Vulcanize {
.appendChild(new DataNode(script, tag.baseUri())));
}
+ private static String minify(Webpath path, String script) {
+ CompilerOptions options = new CompilerOptions();
+ options.skipAllCompilerPasses();
+ options.setLanguageIn(CompilerOptions.LanguageMode.ECMASCRIPT_2016);
+ options.setLanguageOut(CompilerOptions.LanguageMode.ECMASCRIPT5);
+ options.setContinueAfterErrors(true);
+ CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
+ if (testOnly) {
+ options.setPrettyPrint(true);
+ options.setGeneratePseudoNames(true);
+ }
+ Compiler compiler = new Compiler();
+ compiler.disableThreads();
+ compiler.compile(
+ ImmutableList.<SourceFile>of(),
+ ImmutableList.of(SourceFile.fromCode(path.toString(), script)),
+ options);
+ return compiler.toSource();
+ }
+
private static void handleLicense(String text) {
if (legalese.add(CharMatcher.whitespace().removeFrom(text))) {
licenses.add(CharMatcher.anyOf("\r\n").trimFrom(text));
diff --git a/tensorflow/tensorboard/java/org/tensorflow/tensorboard/vulcanize/externs.js b/tensorflow/tensorboard/java/org/tensorflow/tensorboard/vulcanize/externs.js
index 2e56562c1c..85d0ea80c0 100644
--- a/tensorflow/tensorboard/java/org/tensorflow/tensorboard/vulcanize/externs.js
+++ b/tensorflow/tensorboard/java/org/tensorflow/tensorboard/vulcanize/externs.js
@@ -20,6 +20,7 @@
/** @type {!Object} */ var _;
/** @type {!Object} */ var d3;
/** @type {!Object} */ var dagre;
+/** @type {!Object} */ var numeric;
/** @type {!Object} */ var weblas;
/** @type {!Object} */ var graphlib;
/** @type {!Object} */ var Plottable;
diff --git a/third_party/js.bzl b/third_party/js.bzl
index 46466c3f31..b5395a0b0c 100644
--- a/third_party/js.bzl
+++ b/third_party/js.bzl
@@ -189,11 +189,12 @@ def tensorboard_js_workspace():
"http://mirror.bazel.build/raw.githubusercontent.com/sloisel/numeric/v1.2.6/license.txt",
"https://raw.githubusercontent.com/sloisel/numeric/v1.2.6/license.txt",
],
- "dfaca3b8485bee735788cc6eebca82ea25719adc1fb8911c7799c6bd5a95df3b": [
- "http://mirror.bazel.build/raw.githubusercontent.com/sloisel/numeric/v1.2.6/src/numeric.js",
- "https://raw.githubusercontent.com/sloisel/numeric/v1.2.6/src/numeric.js",
+ "5dcaba2016fd237091e3a17b0dc272fb21f0e2b15d7628f95a0ad0cd4cdf4020": [
+ "http://mirror.bazel.build/www.numericjs.com/lib/numeric-1.2.6.js",
+ "http://www.numericjs.com/lib/numeric-1.2.6.js",
],
},
+ rename = {"numeric-1.2.6.js": "numeric.js"},
)
filegroup_external(