blob: 64dd9d7e3a2a677441bd8bc5024cc02ddd8331e0 [file] [log] [blame]
Ray Milkey171b89a2016-07-28 15:22:26 -07001include_defs('//onos.defs')
2
Brian O'Connor1f165982016-04-06 21:36:09 -07003DEFAULT_APP_CATEGORY = 'Utility'
Brian O'Connore4da59d2016-04-08 00:32:18 -07004
5import os.path
6
7# FIXME Factor this into common place
8def _get_name():
9 base_path = get_base_path()
10 return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
11
12def _get_app_name():
13 base_path = get_base_path()
14 return APP_PREFIX + os.path.basename(base_path)
Brian O'Connor1f165982016-04-06 21:36:09 -070015
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -070016def osgi_feature(
17 name,
18 title,
19 feature_coords = None,
20 version = ONOS_VERSION,
21 required_features = [ 'onos-api' ],
22 required_apps = [],
23 included_bundles = None,
24 excluded_bundles = [],
25 generate_file = False,
26 visibility = [ 'PUBLIC' ],
27 stage_repo = True,
Ray Milkey033b9f92016-12-09 16:21:55 -080028 maven_coords = None,
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -070029 ):
30
31 if not feature_coords:
32 feature_coords = name
33 args = [ '-n %s' % feature_coords,
34 '-v %s' % version,
35 '-t "%s"' % title,
36 ]
37 args += [ '-f %s' % f for f in required_features ]
38 args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
39 args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
40 args += [ '-d %s' % a for a in required_apps ]
41
42 feature_cmd = '-F' if generate_file else '-E'
43
44 cmd = '$(exe //buck-tools:onos-app-writer) %s ' % feature_cmd
45 cmd += ' '.join(args) + ' > $OUT'
46 genrule(
47 name = name + '-feature',
48 bash = cmd,
49 out = 'features.xml',
50 visibility = visibility,
Ray Milkey033b9f92016-12-09 16:21:55 -080051 maven_coords = maven_coords,
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -070052 )
53
54 if stage_repo:
55 sources = ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
56 genrule(
57 name = name + '-repo',
58 out = name + '-repo.zip.part',
59 bash = '$(exe //buck-tools:onos-feature) $OUT ' + ' '.join(sources),
60 visibility = visibility,
61 )
62
63FEATURES_HEADER = '''\
64<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
65<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
66 name="onos-%s">
Jon Hallb84df5d2017-01-31 11:19:48 -080067 <repository>mvn:org.apache.karaf.features/standard/3.0.8/xml/features</repository>
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -070068
69''' % ONOS_VERSION
70
71FEATURES_FOOTER = '</features>'
72
73def compile_features(
74 name,
75 features = [],
Brian O'Connor8cc10ec2016-09-13 16:29:36 -070076 maven_coords = None,
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -070077 visibility = [ 'PUBLIC' ],
78 ):
79
80 cmd = "(echo '%s'; " % FEATURES_HEADER
81 cmd += ''.join(['cat $(location %s-feature); ' % s for s in features])
82 cmd += "echo '%s') > $OUT" % FEATURES_FOOTER
83
84 genrule(
85 name = name,
86 bash = cmd,
87 visibility = visibility,
88 out = 'features.xml',
Brian O'Connor8cc10ec2016-09-13 16:29:36 -070089 maven_coords = maven_coords,
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -070090 )
91
92
93#TODO rename this
94def osgi_feature_group(
95 name,
96 description = 'TEST',
97 version = ONOS_VERSION,
98 exported_deps = [],
99 visibility = ['PUBLIC'],
Ray Milkey033b9f92016-12-09 16:21:55 -0800100 maven_coords = None,
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700101 **kwargs
102 ):
103 java_library(
104 name = name,
105 exported_deps = exported_deps, #compile only
106 visibility = visibility,
107 )
108
109 osgi_feature(
110 name = name,
111 feature_coords = name,
112 version = version,
113 title = description,
114 required_features = [],
115 included_bundles = exported_deps,
116 generate_file = False,
117 visibility = visibility,
Ray Milkey033b9f92016-12-09 16:21:55 -0800118 maven_coords = maven_coords,
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700119 )
120
121
122
Brian O'Connor1f165982016-04-06 21:36:09 -0700123def onos_app(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700124 app_name = None,
125 name = None,
126 title = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700127 version = ONOS_VERSION,
128 origin = ONOS_ORIGIN,
129 category = DEFAULT_APP_CATEGORY,
130 url = None,
131 description = None, #TODO make this a file
132 #TODO icon,
Brian O'Connore124f3d2016-04-06 23:54:26 -0700133 feature_coords = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700134 required_features = [ 'onos-api' ],
135 required_apps = [],
Brian O'Connore4da59d2016-04-08 00:32:18 -0700136 included_bundles = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700137 excluded_bundles = [],
Brian O'Connore4da59d2016-04-08 00:32:18 -0700138 visibility = [ 'PUBLIC' ],
Brian O'Connor1f165982016-04-06 21:36:09 -0700139 **kwargs):
Brian O'Connore4da59d2016-04-08 00:32:18 -0700140 if name is None:
141 name = _get_name()
142
143 if app_name is None:
144 app_name = _get_app_name()
145
Brian O'Connor8cc10ec2016-09-13 16:29:36 -0700146 maven_coords = '%s:%s:oar:%s' % ( ONOS_GROUP_ID, name, ONOS_VERSION )
Ray Milkey033b9f92016-12-09 16:21:55 -0800147 feature_xml_coords = '%s:%s:xml:features:%s' % ( ONOS_GROUP_ID, name, ONOS_VERSION )
Brian O'Connor8cc10ec2016-09-13 16:29:36 -0700148
Brian O'Connore4da59d2016-04-08 00:32:18 -0700149 if title is None:
150 print "Missing title for %s" % _get_name()
151 title = _get_app_name()
152
153 if included_bundles is None:
154 target = ':' + _get_name()
155 included_bundles = [ target ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700156
Brian O'Connore124f3d2016-04-06 23:54:26 -0700157 if not feature_coords and len(included_bundles) == 1:
158 feature_coords = '$(maven_coords %s)' % included_bundles[0]
Brian O'Connor1f165982016-04-06 21:36:09 -0700159
Brian O'Connore4da59d2016-04-08 00:32:18 -0700160 if not feature_coords:
Ray Milkey24439fe2016-04-08 21:50:55 -0700161 feature_coords = '%s:%s:%s' % ( ONOS_GROUP_ID, _get_name(), ONOS_VERSION )
Brian O'Connore4da59d2016-04-08 00:32:18 -0700162
Brian O'Connore124f3d2016-04-06 23:54:26 -0700163 args = [ '-n %s' % feature_coords,
Brian O'Connor1f165982016-04-06 21:36:09 -0700164 '-v %s' % version,
165 '-t "%s"' % title,
166 '-o "%s"' % origin,
167 '-c "%s"' % category,
168 '-a "%s"' % app_name,
169 '-u %s' % url,
170 ]
171 args += [ '-f %s' % f for f in required_features ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700172 args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
173 args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700174 args += [ '-d %s' % a for a in required_apps ]
175
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700176 # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT'
177 # genrule(
178 # name = name + '-feature',
179 # bash = cmd,
180 # out = 'features.xml',
181 # visibility = [],
182 # )
183 osgi_feature(
184 name = name,
185 feature_coords = feature_coords,
186 version = version,
187 title = title,
188 required_features = required_features,
189 included_bundles = included_bundles,
190 excluded_bundles = excluded_bundles,
191 generate_file = True,
Brian O'Connor1f165982016-04-06 21:36:09 -0700192 visibility = [],
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700193 stage_repo = False,
Ray Milkey033b9f92016-12-09 16:21:55 -0800194 maven_coords = feature_xml_coords,
Brian O'Connor1f165982016-04-06 21:36:09 -0700195 )
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700196
Brian O'Connor1f165982016-04-06 21:36:09 -0700197 cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT'
198 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700199 name = name + '-app-xml',
Brian O'Connor1f165982016-04-06 21:36:09 -0700200 bash = cmd,
201 out = 'app.xml',
202 visibility = [],
203 )
204
205 sources = [
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700206 '$(location :%s-feature) %s' % (name, feature_coords),
Brian O'Connore4da59d2016-04-08 00:32:18 -0700207 '$(location :%s-app-xml) NONE' % name,
Brian O'Connor1f165982016-04-06 21:36:09 -0700208 ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700209 sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
Brian O'Connor1f165982016-04-06 21:36:09 -0700210 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700211 name = name + '-oar',
Brian O'Connor1f165982016-04-06 21:36:09 -0700212 out = 'app.oar',
Brian O'Connore4da59d2016-04-08 00:32:18 -0700213 bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources),
Brian O'Connor8cc10ec2016-09-13 16:29:36 -0700214 maven_coords = maven_coords,
Brian O'Connore4da59d2016-04-08 00:32:18 -0700215 visibility = visibility,
Brian O'Connor1f165982016-04-06 21:36:09 -0700216 )