blob: bc6ec4fc69dfcb46336ebefaa3f6017feb2503e1 [file] [log] [blame]
Thomas Vachuskaaab45d12018-06-05 16:39:46 -07001"""
2 Copyright 2018-present Open Networking Foundation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15"""
16
17load("//tools/build/bazel:generate_workspace.bzl", "COMPILE", "TEST", "maven_coordinates")
18load("//tools/build/bazel:variables.bzl", "ONOS_VERSION", "ONOS_GROUP_ID")
19
20def dump(obj):
21 for attr in dir(obj):
22 print("obj.%s = %r" % (attr, getattr(obj, attr)))
23
24# Implementation of a rule to produce an OSGi feature XML snippet
25def _osgi_feature_impl(ctx):
26 output = ctx.outputs.feature_xml
27
28 args = [ "-O", output.path,
29 "-n", ctx.attr.name,
30 "-v", ctx.attr.version,
31 "-t", ctx.attr.description,
32 ]
33
34 inputs = []
35 for dep in ctx.attr.included_bundles:
36 args += [ "-b", maven_coordinates(dep.label) ]
37 for f in dep.java.outputs.jars:
38 inputs += [ f.class_jar ]
39
40 for dep in ctx.attr.excluded_bundles:
41 args += [ "-e", maven_coordinates(dep.label) ]
42 for f in dep.java.outputs.jars:
43 inputs += [ f.class_jar ]
44
45 for f in ctx.attr.required_features:
46 args += [ "-f", f ]
47
48 args += [ "-F" if ctx.attr.generate_file else "-E" ]
49
50 ctx.actions.run(
51 inputs = inputs,
52 outputs = [ output ],
53 arguments = args,
54 progress_message = "Generating feature %s" % ctx.attr.name,
55 executable = ctx.executable._writer
56 )
57
58osgi_feature = rule(
59 attrs = {
60 "description": attr.string(),
61 "version": attr.string(default = ONOS_VERSION),
62 "required_features": attr.string_list(default = [ "onos-api" ]),
63 "included_bundles": attr.label_list(),
64 "excluded_bundles": attr.label_list(default = []),
65 "generate_file": attr.bool(default = False),
66 "_writer": attr.label(executable=True, cfg="host", allow_files=True,
67 default=Label("//tools/build/bazel:onos_app_writer")),
68 },
69 outputs = {
70 "feature_xml": "feature-%{name}.xml",
71 },
72 implementation = _osgi_feature_impl,
73)
74
75# OSGi feature XML header & footer constants
76FEATURES_HEADER = '''\
77<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
78<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
79 name="onos-%s">
80 <repository>mvn:org.apache.karaf.features/standard/3.0.8/xml/features</repository>
81''' % ONOS_VERSION
82
83FEATURES_FOOTER = '</features>'
84
85# Implementation of a rule to produce an OSGi feature repo XML file
86def _osgi_feature_repo_impl(ctx):
87 output = ctx.outputs.feature_repo_xml
88
89 cmd = "(echo '%s';" % FEATURES_HEADER
90 inputs = []
91 for dep in ctx.attr.exported_features:
92 for f in dep.files.to_list():
93 inputs += [ f ]
94 cmd += "cat %s;" % f.path
95 cmd += "echo '%s') > %s;" % (FEATURES_FOOTER, output.path)
96
97 ctx.actions.run_shell(
98 inputs = inputs,
99 outputs = [ output ],
100 progress_message = "Generating feature repo %s" % ctx.attr.name,
101 command = cmd,
102 )
103
104osgi_feature_repo = rule(
105 attrs = {
106 "description": attr.string(),
107 "version": attr.string(default = ONOS_VERSION),
108 "exported_features": attr.label_list(),
109 },
110 outputs = {
111 "feature_repo_xml": "feature-repo-%{name}.xml",
112 },
113 implementation = _osgi_feature_repo_impl,
114)