Thomas Vachuska | ac9e524 | 2018-07-19 16:15:39 -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 | |
| 15 | load("//tools/build/bazel:generate_workspace.bzl", "maven_coordinates") |
| 16 | |
| 17 | def _impl(ctx): |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 18 | arguments = [ |
| 19 | ctx.outputs.pom.path, |
| 20 | maven_coordinates(ctx.attr.artifact), |
| 21 | ] |
Thomas Vachuska | ac9e524 | 2018-07-19 16:15:39 -0700 | [diff] [blame] | 22 | |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 23 | for dep in ctx.attr.deps: |
| 24 | arguments += [maven_coordinates(dep.label)] |
Thomas Vachuska | ac9e524 | 2018-07-19 16:15:39 -0700 | [diff] [blame] | 25 | |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 26 | ctx.actions.run( |
| 27 | inputs = ctx.files.deps, |
| 28 | outputs = [ctx.outputs.pom], |
| 29 | progress_message = "Generating pom file for %s" % ctx.attr.name, |
| 30 | arguments = arguments, |
| 31 | executable = ctx.executable._pom_generator, |
| 32 | ) |
Thomas Vachuska | ac9e524 | 2018-07-19 16:15:39 -0700 | [diff] [blame] | 33 | |
| 34 | pom_file = rule( |
| 35 | attrs = { |
| 36 | "artifact": attr.string(), |
| 37 | "deps": attr.label_list(allow_files = True), |
| 38 | "_pom_generator": attr.label( |
| 39 | executable = True, |
| 40 | cfg = "host", |
| 41 | allow_files = True, |
| 42 | default = Label("//tools/build/bazel:pom_generator"), |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 43 | ), |
Thomas Vachuska | ac9e524 | 2018-07-19 16:15:39 -0700 | [diff] [blame] | 44 | }, |
| 45 | implementation = _impl, |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 46 | outputs = {"pom": "%{name}.pom"}, |
Thomas Vachuska | ac9e524 | 2018-07-19 16:15:39 -0700 | [diff] [blame] | 47 | ) |