• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 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# ==============================================================================
15"""Generate Java reference docs for TensorFlow.org."""
16import pathlib
17import shutil
18import subprocess
19import tempfile
20
21from absl import app
22from absl import flags
23
24from tensorflow_docs.api_generator import gen_java
25
26FLAGS = flags.FLAGS
27
28# These flags are required by infrastructure, not all of them are used.
29flags.DEFINE_string('output_dir', None,
30                    ("Use this branch as the root version and don't"
31                     ' create in version directory'))
32
33flags.DEFINE_string('site_path', 'api_docs/java',
34                    'Path prefix in the _toc.yaml')
35
36flags.DEFINE_string('code_url_prefix', None,
37                    '[UNUSED] The url prefix for links to code.')
38
39flags.DEFINE_bool(
40    'search_hints', True,
41    '[UNUSED] Include metadata search hints in the generated files')
42
43# Use this flag to disable bazel generation if you're not setup for it.
44flags.DEFINE_bool('gen_ops', True, 'enable/disable bazel-generated ops')
45
46# __file__ is the path to this file
47DOCS_TOOLS_DIR = pathlib.Path(__file__).resolve().parent
48TENSORFLOW_ROOT = DOCS_TOOLS_DIR.parents[2]
49SOURCE_PATH = TENSORFLOW_ROOT / 'tensorflow/java/src/main/java'
50OP_SOURCE_PATH = (
51    TENSORFLOW_ROOT /
52    'bazel-bin/tensorflow/java/ops/src/main/java/org/tensorflow/op')
53
54
55def main(unused_argv):
56  merged_source = pathlib.Path(tempfile.mkdtemp())
57  shutil.copytree(SOURCE_PATH, merged_source / 'java')
58
59  if FLAGS.gen_ops:
60    # `$ yes | configure`
61    yes = subprocess.Popen(['yes', ''], stdout=subprocess.PIPE)
62    configure = subprocess.Popen([TENSORFLOW_ROOT / 'configure'],
63                                 stdin=yes.stdout,
64                                 cwd=TENSORFLOW_ROOT)
65    configure.communicate()
66
67    subprocess.check_call(
68        ['bazel', 'build', '//tensorflow/java:java_op_gen_sources'],
69        cwd=TENSORFLOW_ROOT)
70    shutil.copytree(OP_SOURCE_PATH, merged_source / 'java/org/tensorflow/ops')
71
72  gen_java.gen_java_docs(
73      package='org.tensorflow',
74      source_path=merged_source / 'java',
75      output_dir=pathlib.Path(FLAGS.output_dir),
76      site_path=pathlib.Path(FLAGS.site_path))
77
78
79if __name__ == '__main__':
80  flags.mark_flags_as_required(['output_dir'])
81  app.run(main)
82