blob: 14e1d72ae3713ece6f2a74b54053bc8266b92f35 [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 ]
Thomas Vachuska7c45e282017-08-23 17:55:53 -0700175 if description is not None:
176 args += [ '-D "%s"' % description ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700177
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700178 # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT'
179 # genrule(
180 # name = name + '-feature',
181 # bash = cmd,
182 # out = 'features.xml',
183 # visibility = [],
184 # )
185 osgi_feature(
186 name = name,
187 feature_coords = feature_coords,
188 version = version,
189 title = title,
190 required_features = required_features,
191 included_bundles = included_bundles,
192 excluded_bundles = excluded_bundles,
193 generate_file = True,
Brian O'Connor1f165982016-04-06 21:36:09 -0700194 visibility = [],
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700195 stage_repo = False,
Ray Milkey033b9f92016-12-09 16:21:55 -0800196 maven_coords = feature_xml_coords,
Brian O'Connor1f165982016-04-06 21:36:09 -0700197 )
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700198
Brian O'Connor1f165982016-04-06 21:36:09 -0700199 cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT'
200 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700201 name = name + '-app-xml',
Brian O'Connor1f165982016-04-06 21:36:09 -0700202 bash = cmd,
203 out = 'app.xml',
204 visibility = [],
205 )
206
207 sources = [
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700208 '$(location :%s-feature) %s' % (name, feature_coords),
Brian O'Connore4da59d2016-04-08 00:32:18 -0700209 '$(location :%s-app-xml) NONE' % name,
Brian O'Connor1f165982016-04-06 21:36:09 -0700210 ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700211 sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
Brian O'Connor1f165982016-04-06 21:36:09 -0700212 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700213 name = name + '-oar',
Brian O'Connor1f165982016-04-06 21:36:09 -0700214 out = 'app.oar',
Brian O'Connore4da59d2016-04-08 00:32:18 -0700215 bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources),
Brian O'Connor8cc10ec2016-09-13 16:29:36 -0700216 maven_coords = maven_coords,
Brian O'Connore4da59d2016-04-08 00:32:18 -0700217 visibility = visibility,
Brian O'Connor1f165982016-04-06 21:36:09 -0700218 )