blob: c291d4c2ecce464e19e4211581f391eb2bfff208 [file] [log] [blame]
Thomas Vachuskaac9e5242018-07-19 16:15:39 -07001# 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
15load("//tools/build/bazel:generate_workspace.bzl", "maven_coordinates")
16
Carmelo Cascone87b893e2019-11-12 10:34:05 -080017def _impl_pom_file(ctx):
Ray Milkey5063f5b2018-08-15 16:22:30 -070018 arguments = [
19 ctx.outputs.pom.path,
20 maven_coordinates(ctx.attr.artifact),
21 ]
Thomas Vachuskaac9e5242018-07-19 16:15:39 -070022
Ray Milkey5063f5b2018-08-15 16:22:30 -070023 for dep in ctx.attr.deps:
24 arguments += [maven_coordinates(dep.label)]
Thomas Vachuskaac9e5242018-07-19 16:15:39 -070025
Ray Milkey5063f5b2018-08-15 16:22:30 -070026 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 Vachuskaac9e5242018-07-19 16:15:39 -070033
34pom_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 Milkey5063f5b2018-08-15 16:22:30 -070043 ),
Thomas Vachuskaac9e5242018-07-19 16:15:39 -070044 },
Carmelo Cascone87b893e2019-11-12 10:34:05 -080045 implementation = _impl_pom_file,
46 outputs = {"pom": "%{name}.pom"},
47)
48
49def _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
72dependencies_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 Milkey5063f5b2018-08-15 16:22:30 -070087 outputs = {"pom": "%{name}.pom"},
Thomas Vachuskaac9e5242018-07-19 16:15:39 -070088)