blob: fa3147991b3c675b3a50254bf013fdaae5113b89 [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,
28 ):
29
30 if not feature_coords:
31 feature_coords = name
32 args = [ '-n %s' % feature_coords,
33 '-v %s' % version,
34 '-t "%s"' % title,
35 ]
36 args += [ '-f %s' % f for f in required_features ]
37 args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
38 args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
39 args += [ '-d %s' % a for a in required_apps ]
40
41 feature_cmd = '-F' if generate_file else '-E'
42
43 cmd = '$(exe //buck-tools:onos-app-writer) %s ' % feature_cmd
44 cmd += ' '.join(args) + ' > $OUT'
45 genrule(
46 name = name + '-feature',
47 bash = cmd,
48 out = 'features.xml',
49 visibility = visibility,
50 )
51
52 if stage_repo:
53 sources = ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
54 genrule(
55 name = name + '-repo',
56 out = name + '-repo.zip.part',
57 bash = '$(exe //buck-tools:onos-feature) $OUT ' + ' '.join(sources),
58 visibility = visibility,
59 )
60
61FEATURES_HEADER = '''\
62<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
63<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
64 name="onos-%s">
65 <repository>mvn:org.apache.karaf.features/standard/3.0.5/xml/features</repository>
66
67''' % ONOS_VERSION
68
69FEATURES_FOOTER = '</features>'
70
71def compile_features(
72 name,
73 features = [],
Brian O'Connor8cc10ec2016-09-13 16:29:36 -070074 maven_coords = None,
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -070075 visibility = [ 'PUBLIC' ],
76 ):
77
78 cmd = "(echo '%s'; " % FEATURES_HEADER
79 cmd += ''.join(['cat $(location %s-feature); ' % s for s in features])
80 cmd += "echo '%s') > $OUT" % FEATURES_FOOTER
81
82 genrule(
83 name = name,
84 bash = cmd,
85 visibility = visibility,
86 out = 'features.xml',
Brian O'Connor8cc10ec2016-09-13 16:29:36 -070087 maven_coords = maven_coords,
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -070088 )
89
90
91#TODO rename this
92def osgi_feature_group(
93 name,
94 description = 'TEST',
95 version = ONOS_VERSION,
96 exported_deps = [],
97 visibility = ['PUBLIC'],
98 **kwargs
99 ):
100 java_library(
101 name = name,
102 exported_deps = exported_deps, #compile only
103 visibility = visibility,
104 )
105
106 osgi_feature(
107 name = name,
108 feature_coords = name,
109 version = version,
110 title = description,
111 required_features = [],
112 included_bundles = exported_deps,
113 generate_file = False,
114 visibility = visibility,
115 )
116
117
118
Brian O'Connor1f165982016-04-06 21:36:09 -0700119def onos_app(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700120 app_name = None,
121 name = None,
122 title = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700123 version = ONOS_VERSION,
124 origin = ONOS_ORIGIN,
125 category = DEFAULT_APP_CATEGORY,
126 url = None,
127 description = None, #TODO make this a file
128 #TODO icon,
Brian O'Connore124f3d2016-04-06 23:54:26 -0700129 feature_coords = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700130 required_features = [ 'onos-api' ],
131 required_apps = [],
Brian O'Connore4da59d2016-04-08 00:32:18 -0700132 included_bundles = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700133 excluded_bundles = [],
Brian O'Connore4da59d2016-04-08 00:32:18 -0700134 visibility = [ 'PUBLIC' ],
Brian O'Connor1f165982016-04-06 21:36:09 -0700135 **kwargs):
Brian O'Connore4da59d2016-04-08 00:32:18 -0700136 if name is None:
137 name = _get_name()
138
139 if app_name is None:
140 app_name = _get_app_name()
141
Brian O'Connor8cc10ec2016-09-13 16:29:36 -0700142 maven_coords = '%s:%s:oar:%s' % ( ONOS_GROUP_ID, name, ONOS_VERSION )
143
Brian O'Connore4da59d2016-04-08 00:32:18 -0700144 if title is None:
145 print "Missing title for %s" % _get_name()
146 title = _get_app_name()
147
148 if included_bundles is None:
149 target = ':' + _get_name()
150 included_bundles = [ target ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700151
Brian O'Connore124f3d2016-04-06 23:54:26 -0700152 if not feature_coords and len(included_bundles) == 1:
153 feature_coords = '$(maven_coords %s)' % included_bundles[0]
Brian O'Connor1f165982016-04-06 21:36:09 -0700154
Brian O'Connore4da59d2016-04-08 00:32:18 -0700155 if not feature_coords:
Ray Milkey24439fe2016-04-08 21:50:55 -0700156 feature_coords = '%s:%s:%s' % ( ONOS_GROUP_ID, _get_name(), ONOS_VERSION )
Brian O'Connore4da59d2016-04-08 00:32:18 -0700157
Brian O'Connore124f3d2016-04-06 23:54:26 -0700158 args = [ '-n %s' % feature_coords,
Brian O'Connor1f165982016-04-06 21:36:09 -0700159 '-v %s' % version,
160 '-t "%s"' % title,
161 '-o "%s"' % origin,
162 '-c "%s"' % category,
163 '-a "%s"' % app_name,
164 '-u %s' % url,
165 ]
166 args += [ '-f %s' % f for f in required_features ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700167 args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
168 args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700169 args += [ '-d %s' % a for a in required_apps ]
170
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700171 # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT'
172 # genrule(
173 # name = name + '-feature',
174 # bash = cmd,
175 # out = 'features.xml',
176 # visibility = [],
177 # )
178 osgi_feature(
179 name = name,
180 feature_coords = feature_coords,
181 version = version,
182 title = title,
183 required_features = required_features,
184 included_bundles = included_bundles,
185 excluded_bundles = excluded_bundles,
186 generate_file = True,
Brian O'Connor1f165982016-04-06 21:36:09 -0700187 visibility = [],
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700188 stage_repo = False,
Brian O'Connor1f165982016-04-06 21:36:09 -0700189 )
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700190
Brian O'Connor1f165982016-04-06 21:36:09 -0700191 cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT'
192 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700193 name = name + '-app-xml',
Brian O'Connor1f165982016-04-06 21:36:09 -0700194 bash = cmd,
195 out = 'app.xml',
196 visibility = [],
197 )
198
199 sources = [
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700200 '$(location :%s-feature) %s' % (name, feature_coords),
Brian O'Connore4da59d2016-04-08 00:32:18 -0700201 '$(location :%s-app-xml) NONE' % name,
Brian O'Connor1f165982016-04-06 21:36:09 -0700202 ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700203 sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
Brian O'Connor1f165982016-04-06 21:36:09 -0700204 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700205 name = name + '-oar',
Brian O'Connor1f165982016-04-06 21:36:09 -0700206 out = 'app.oar',
Brian O'Connore4da59d2016-04-08 00:32:18 -0700207 bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources),
Brian O'Connor8cc10ec2016-09-13 16:29:36 -0700208 maven_coords = maven_coords,
Brian O'Connore4da59d2016-04-08 00:32:18 -0700209 visibility = visibility,
Brian O'Connor1f165982016-04-06 21:36:09 -0700210 )