STT-tensorflow/tensorflow/tools/docs/build_java_api_docs.py
Mark Daoust cd893cfb6a Update java generator.
- Add a "package" argument so it can be used for packages other than tensorflow.
- Use [-subpackages](https://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javadoc.html) arg to make generaion recursive.
- Merge bazel generated op-source so ops docs are generated.

$> tree /tmp/gen_java

org/
└── tensorflow
    ├── DataType.html
    ├── EagerSession.DevicePlacementPolicy.html
    ├── EagerSession.html
    ├── EagerSession.Options.html
    ├── EagerSession.ResourceCleanupStrategy.html
    ├── examples
    │   ├── LabelImage.html
    │   └── package-summary.html
    ├── ExecutionEnvironment.html
    ├── Graph.html
    ├── GraphOperationBuilder.html
    ├── GraphOperation.html
    ├── Graph.WhileSubgraphBuilder.html
    ├── op
    │   ├── annotation
    │   │   ├── Operator.html
    │   │   └── package-summary.html
    │   ├── core
    │   │   ├── Abort.html
    │   │   ├── Abort.Options.html
    │   │   ├── All.html
    │   │   ├── All.Options.html
    │   │   ├── AllToAll.html
    │   │   ├── AnonymousIteratorV2.html
    │   │   ├── AnonymousMemoryCache.html
    │   │   ├── AnonymousMultiDeviceIterator.html
    │   │   ├── AnonymousRandomSeedGenerator.html
    │   │   ├── AnonymousSeedGenerator.html
    │   │   ├── Any.html
    │   │   ├── Any.Options.html
    │   │   ├── ApplyAdagradV2.html
    │   │   ├── ApplyAdagradV2.Options.html
    │   │   ├── AssertCardinalityDataset.html
    │   │   ├── AssertNextDataset.html
    │   │   ├── AssertThat.html
    │   │   ├── AssertThat.Options.html
   ...

PiperOrigin-RevId: 308898353
Change-Id: Idedd2283d205ae08d32c3dc48b3ec5adb6c15ac4
2020-04-28 14:35:17 -07:00

80 lines
2.7 KiB
Python

# Lint as: python3
# Copyright 2018 The TensorFlow Authors. 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.
# ==============================================================================
"""Generate Java reference docs for TensorFlow.org."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import pathlib
import shutil
import subprocess
import tempfile
from absl import app
from absl import flags
from tensorflow_docs.api_generator import gen_java
FLAGS = flags.FLAGS
# These flags are required by infrastructure, not all of them are used.
flags.DEFINE_string('output_dir', None,
("Use this branch as the root version and don't"
' create in version directory'))
flags.DEFINE_string('site_path', 'api_docs/java',
'Path prefix in the _toc.yaml')
flags.DEFINE_string('code_url_prefix', None,
'[UNUSED] The url prefix for links to code.')
flags.DEFINE_bool(
'search_hints', True,
'[UNUSED] Include metadata search hints in the generated files')
# Use this flag to disable bazel generation if you're not setup for it.
flags.DEFINE_bool('gen_ops', True, 'enable/disable bazel-generated ops')
# __file__ is the path to this file
DOCS_TOOLS_DIR = pathlib.Path(__file__).resolve().parent
TENSORFLOW_ROOT = DOCS_TOOLS_DIR.parents[2]
SOURCE_PATH = TENSORFLOW_ROOT / 'tensorflow/java/src/main/java'
OP_SOURCE_PATH = (
TENSORFLOW_ROOT /
'bazel-bin/tensorflow/java/ops/src/main/java/org/tensorflow/op')
def main(unused_argv):
merged_source = pathlib.Path(tempfile.mkdtemp())
shutil.copytree(SOURCE_PATH, merged_source / 'java')
if FLAGS.gen_ops:
subprocess.check_call(
['bazel', 'build', '//tensorflow/java:java_op_gen_sources'],
cwd=TENSORFLOW_ROOT)
shutil.copytree(OP_SOURCE_PATH, merged_source / 'java/org/tensorflow/ops')
gen_java.gen_java_docs(
package='org.tensorflow',
source_path=merged_source / 'java',
output_dir=pathlib.Path(FLAGS.output_dir),
site_path=pathlib.Path(FLAGS.site_path))
if __name__ == '__main__':
flags.mark_flags_as_required(['output_dir'])
app.run(main)