Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 1 | # Copyright 2015 The Bazel 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 | |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 15 | JAVA_DOCS = "-link https://docs.oracle.com/en/java/javase/11/docs/api/" |
Thomas Vachuska | c3226e9 | 2018-07-25 12:00:57 -0700 | [diff] [blame] | 16 | |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 17 | def _impl(ctx): |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 18 | dir = ctx.label.name |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 19 | outjar = ctx.outputs.jar |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 20 | |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 21 | dep_list = [] |
| 22 | for dep in ctx.files.deps: |
| 23 | dep_list += [dep.path] |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 24 | |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 25 | src_list = [] |
| 26 | for src in ctx.files.srcs: |
| 27 | src_list += [src.path] |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 28 | |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 29 | java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo] |
| 30 | jar_exe_path = "%s/bin/jar" % java_runtime.java_home |
| 31 | |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 32 | cmd = [ |
| 33 | "mkdir %s" % dir, |
| 34 | "javadoc -encoding UTF-8 -quiet -tag onos.rsModel:a:\"onos model\" %s -d %s -cp %s %s" % |
| 35 | (JAVA_DOCS, dir, ":".join(dep_list), " ".join(src_list)), |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 36 | "%s cf %s -C %s ." % (jar_exe_path, outjar.path, dir), |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 37 | ] |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 38 | |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 39 | ctx.action( |
| 40 | inputs = ctx.files.srcs + ctx.files.deps, |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 41 | outputs = [outjar], |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 42 | progress_message = "Generating javadocs jar for %s" % ctx.attr.name, |
| 43 | command = ";\n".join(cmd), |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 44 | tools = java_runtime.files, |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 45 | ) |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 46 | |
| 47 | javadoc = rule( |
| 48 | attrs = { |
| 49 | "deps": attr.label_list(allow_files = True), |
| 50 | "srcs": attr.label_list(allow_files = True), |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 51 | "_jdk": attr.label( |
| 52 | default = Label("@bazel_tools//tools/jdk:current_java_runtime"), |
| 53 | providers = [java_common.JavaRuntimeInfo], |
| 54 | ), |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 55 | }, |
| 56 | implementation = _impl, |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 57 | outputs = {"jar": "%{name}.jar"}, |
Thomas Vachuska | 0f7d7a4 | 2018-07-18 15:23:40 -0700 | [diff] [blame] | 58 | ) |