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 | |
Carmelo Cascone | 87b893e | 2019-11-12 10:34:05 -0800 | [diff] [blame] | 17 | def _impl_pom_file(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 | }, |
Carmelo Cascone | 87b893e | 2019-11-12 10:34:05 -0800 | [diff] [blame] | 45 | implementation = _impl_pom_file, |
| 46 | outputs = {"pom": "%{name}.pom"}, |
| 47 | ) |
| 48 | |
| 49 | def _impl_dependencies_pom(ctx): |
| 50 | arguments = [ |
| 51 | "-o", |
| 52 | ctx.outputs.pom.path, |
| 53 | "-p", |
| 54 | ctx.file.pom_template.path, |
| 55 | "-d", |
| 56 | ] + [maven_coordinates(d.label) for d in ctx.attr.deps] + [ |
| 57 | "-c", |
| 58 | ] + [maven_coordinates(d.label) for d in ctx.attr.deps_provided] + [ |
| 59 | "-t", |
| 60 | ] + [maven_coordinates(d.label) for d in ctx.attr.deps_test] + [ |
| 61 | "-v", |
| 62 | ] + ctx.attr.vars |
| 63 | |
| 64 | ctx.actions.run( |
| 65 | inputs = [ctx.file.pom_template], |
| 66 | outputs = [ctx.outputs.pom], |
| 67 | progress_message = "Generating dependencies pom for %s" % ctx.attr.name, |
| 68 | arguments = arguments, |
| 69 | executable = ctx.executable._pom_generator, |
| 70 | ) |
| 71 | |
| 72 | dependencies_pom = rule( |
| 73 | attrs = { |
| 74 | "pom_template": attr.label(allow_single_file = True), |
| 75 | "deps_provided": attr.label_list(), |
| 76 | "deps_test": attr.label_list(), |
| 77 | "deps": attr.label_list(), |
| 78 | "vars": attr.string_list(), |
| 79 | "_pom_generator": attr.label( |
| 80 | executable = True, |
| 81 | cfg = "host", |
| 82 | allow_files = True, |
| 83 | default = Label("//tools/build/bazel:dependencies_pom_generator"), |
| 84 | ), |
| 85 | }, |
| 86 | implementation = _impl_dependencies_pom, |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 87 | outputs = {"pom": "%{name}.pom"}, |
Thomas Vachuska | ac9e524 | 2018-07-19 16:15:39 -0700 | [diff] [blame] | 88 | ) |