blob: 193574b5cfa17098abadcdfcca1a2f37b99de435 [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' ],
Heedo Kang3cda3f32017-09-07 22:27:38 +0900139 security = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700140 **kwargs):
Brian O'Connore4da59d2016-04-08 00:32:18 -0700141 if name is None:
142 name = _get_name()
143
144 if app_name is None:
145 app_name = _get_app_name()
146
Brian O'Connor8cc10ec2016-09-13 16:29:36 -0700147 maven_coords = '%s:%s:oar:%s' % ( ONOS_GROUP_ID, name, ONOS_VERSION )
Ray Milkey033b9f92016-12-09 16:21:55 -0800148 feature_xml_coords = '%s:%s:xml:features:%s' % ( ONOS_GROUP_ID, name, ONOS_VERSION )
Brian O'Connor8cc10ec2016-09-13 16:29:36 -0700149
Brian O'Connore4da59d2016-04-08 00:32:18 -0700150 if title is None:
151 print "Missing title for %s" % _get_name()
152 title = _get_app_name()
153
154 if included_bundles is None:
155 target = ':' + _get_name()
156 included_bundles = [ target ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700157
Brian O'Connore124f3d2016-04-06 23:54:26 -0700158 if not feature_coords and len(included_bundles) == 1:
159 feature_coords = '$(maven_coords %s)' % included_bundles[0]
Brian O'Connor1f165982016-04-06 21:36:09 -0700160
Brian O'Connore4da59d2016-04-08 00:32:18 -0700161 if not feature_coords:
Ray Milkey24439fe2016-04-08 21:50:55 -0700162 feature_coords = '%s:%s:%s' % ( ONOS_GROUP_ID, _get_name(), ONOS_VERSION )
Brian O'Connore4da59d2016-04-08 00:32:18 -0700163
Brian O'Connore124f3d2016-04-06 23:54:26 -0700164 args = [ '-n %s' % feature_coords,
Brian O'Connor1f165982016-04-06 21:36:09 -0700165 '-v %s' % version,
166 '-t "%s"' % title,
167 '-o "%s"' % origin,
168 '-c "%s"' % category,
169 '-a "%s"' % app_name,
170 '-u %s' % url,
171 ]
172 args += [ '-f %s' % f for f in required_features ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700173 args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
174 args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700175 args += [ '-d %s' % a for a in required_apps ]
Thomas Vachuskab0029682017-08-23 17:55:53 -0700176 if description is not None:
177 args += [ '-D "%s"' % description ]
Heedo Kang3cda3f32017-09-07 22:27:38 +0900178 if security is not None:
179 args += [ '-s "%s"' % security ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700180
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700181 # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT'
182 # genrule(
183 # name = name + '-feature',
184 # bash = cmd,
185 # out = 'features.xml',
186 # visibility = [],
187 # )
188 osgi_feature(
189 name = name,
190 feature_coords = feature_coords,
191 version = version,
192 title = title,
193 required_features = required_features,
194 included_bundles = included_bundles,
195 excluded_bundles = excluded_bundles,
196 generate_file = True,
Brian O'Connor1f165982016-04-06 21:36:09 -0700197 visibility = [],
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700198 stage_repo = False,
Ray Milkey033b9f92016-12-09 16:21:55 -0800199 maven_coords = feature_xml_coords,
Brian O'Connor1f165982016-04-06 21:36:09 -0700200 )
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700201
Brian O'Connor1f165982016-04-06 21:36:09 -0700202 cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT'
203 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700204 name = name + '-app-xml',
Brian O'Connor1f165982016-04-06 21:36:09 -0700205 bash = cmd,
206 out = 'app.xml',
207 visibility = [],
208 )
209
210 sources = [
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700211 '$(location :%s-feature) %s' % (name, feature_coords),
Brian O'Connore4da59d2016-04-08 00:32:18 -0700212 '$(location :%s-app-xml) NONE' % name,
Brian O'Connor1f165982016-04-06 21:36:09 -0700213 ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700214 sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
Brian O'Connor1f165982016-04-06 21:36:09 -0700215 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700216 name = name + '-oar',
Brian O'Connor1f165982016-04-06 21:36:09 -0700217 out = 'app.oar',
Brian O'Connore4da59d2016-04-08 00:32:18 -0700218 bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources),
Brian O'Connor8cc10ec2016-09-13 16:29:36 -0700219 maven_coords = maven_coords,
Brian O'Connore4da59d2016-04-08 00:32:18 -0700220 visibility = visibility,
Brian O'Connor1f165982016-04-06 21:36:09 -0700221 )