tensorflow / tensorboard-plugin-example

Apache License 2.0
135 stars 59 forks source link

How the "import system" works? #4

Closed BinhangYuan closed 7 years ago

BinhangYuan commented 7 years ago

Hi, I have a question about how to import tensorboard components in my own plugin. Or in other words, how the current "import system" works?

When I check the greeter plugin, I found something like

<link rel="import" href="../tf-backend/tf-backend.html">

in greeter-plugin.html file. However, there is no such file in the local path. So I am wondering how the build system figure out where to get these dependence files? Here is my guess. Is this specified by the WORKSPACE file, say http_archive, so that every-time it runs the build, it will first download the tensorboard repository from github or somewhere else from the Internet to get the tensorboard dependence and then build the local file.

Any suggestion is highly appreciated!

wchargin commented 7 years ago

(I edited your question to switch > <link …> to `<link …>`, because GitHub interprets the former as actual HTML and sanitizes it away.)

Good question, and a good way to get to know the build system.

The first thing to remember is that that ../tf-backend/tf-backend.html is a webfiles path, not a local path: it uses paths created by ts_web_library rules. The webfiles module tf-backend is defined in tensorboard:tensorboard/components/tf_backend/BUILD, and it exposes a file ts-backend.html, so this is what is being included.

So, how does the file greeter-dashboard.html find this file to import? The file greeter-dashboard.html is defined in tensorboard-plugin-example:greeter_plugin/BUILD, and this web library depends on @org_tensorflow_tensorboard//tensorboard/components/tf_backend. Thus, it imports the webfiles module described in the previous paragraph—which contains ts-backend.html—and so can depend on its webfiles.

The final question is, how does the build system know whence to retrieve the contents of @org_tensorflow_tensorboard//tensorboard/components/tf_backend? As you suspected, this comes from the WORKSPACE file. An http_archive rule defines the org_tensorflow_tensorboard namespace to point to the TensorBoard repository. Finally, the relevant tf_backend build target is marked visibility:public, so the import in tensorboard-plugin-example can proceed and the circle is complete.

Just one correction: Bazel doesn't need to re-download this file every time that it runs the build. It downloads them once and saves the contents locally.

Does this answer your question?

BinhangYuan commented 7 years ago

@wchargin Thank you so much! It resolves all my confusion.