blob: 20c6ce5109084ee923c24d04a18b9c90517c7fe0 [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 = [],
74 visibility = [ 'PUBLIC' ],
75 ):
76
77 cmd = "(echo '%s'; " % FEATURES_HEADER
78 cmd += ''.join(['cat $(location %s-feature); ' % s for s in features])
79 cmd += "echo '%s') > $OUT" % FEATURES_FOOTER
80
81 genrule(
82 name = name,
83 bash = cmd,
84 visibility = visibility,
85 out = 'features.xml',
86 )
87
88
89#TODO rename this
90def osgi_feature_group(
91 name,
92 description = 'TEST',
93 version = ONOS_VERSION,
94 exported_deps = [],
95 visibility = ['PUBLIC'],
96 **kwargs
97 ):
98 java_library(
99 name = name,
100 exported_deps = exported_deps, #compile only
101 visibility = visibility,
102 )
103
104 osgi_feature(
105 name = name,
106 feature_coords = name,
107 version = version,
108 title = description,
109 required_features = [],
110 included_bundles = exported_deps,
111 generate_file = False,
112 visibility = visibility,
113 )
114
115
116
Brian O'Connor1f165982016-04-06 21:36:09 -0700117def onos_app(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700118 app_name = None,
119 name = None,
120 title = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700121 version = ONOS_VERSION,
122 origin = ONOS_ORIGIN,
123 category = DEFAULT_APP_CATEGORY,
124 url = None,
125 description = None, #TODO make this a file
126 #TODO icon,
Brian O'Connore124f3d2016-04-06 23:54:26 -0700127 feature_coords = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700128 required_features = [ 'onos-api' ],
129 required_apps = [],
Brian O'Connore4da59d2016-04-08 00:32:18 -0700130 included_bundles = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700131 excluded_bundles = [],
Brian O'Connore4da59d2016-04-08 00:32:18 -0700132 visibility = [ 'PUBLIC' ],
Brian O'Connor1f165982016-04-06 21:36:09 -0700133 **kwargs):
Brian O'Connore4da59d2016-04-08 00:32:18 -0700134 if name is None:
135 name = _get_name()
136
137 if app_name is None:
138 app_name = _get_app_name()
139
140 if title is None:
141 print "Missing title for %s" % _get_name()
142 title = _get_app_name()
143
144 if included_bundles is None:
145 target = ':' + _get_name()
146 included_bundles = [ target ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700147
Brian O'Connore124f3d2016-04-06 23:54:26 -0700148 if not feature_coords and len(included_bundles) == 1:
149 feature_coords = '$(maven_coords %s)' % included_bundles[0]
Brian O'Connor1f165982016-04-06 21:36:09 -0700150
Brian O'Connore4da59d2016-04-08 00:32:18 -0700151 if not feature_coords:
Ray Milkey24439fe2016-04-08 21:50:55 -0700152 feature_coords = '%s:%s:%s' % ( ONOS_GROUP_ID, _get_name(), ONOS_VERSION )
Brian O'Connore4da59d2016-04-08 00:32:18 -0700153
Brian O'Connore124f3d2016-04-06 23:54:26 -0700154 args = [ '-n %s' % feature_coords,
Brian O'Connor1f165982016-04-06 21:36:09 -0700155 '-v %s' % version,
156 '-t "%s"' % title,
157 '-o "%s"' % origin,
158 '-c "%s"' % category,
159 '-a "%s"' % app_name,
160 '-u %s' % url,
161 ]
162 args += [ '-f %s' % f for f in required_features ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700163 args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
164 args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700165 args += [ '-d %s' % a for a in required_apps ]
166
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700167 # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT'
168 # genrule(
169 # name = name + '-feature',
170 # bash = cmd,
171 # out = 'features.xml',
172 # visibility = [],
173 # )
174 osgi_feature(
175 name = name,
176 feature_coords = feature_coords,
177 version = version,
178 title = title,
179 required_features = required_features,
180 included_bundles = included_bundles,
181 excluded_bundles = excluded_bundles,
182 generate_file = True,
Brian O'Connor1f165982016-04-06 21:36:09 -0700183 visibility = [],
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700184 stage_repo = False,
Brian O'Connor1f165982016-04-06 21:36:09 -0700185 )
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700186
Brian O'Connor1f165982016-04-06 21:36:09 -0700187 cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT'
188 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700189 name = name + '-app-xml',
Brian O'Connor1f165982016-04-06 21:36:09 -0700190 bash = cmd,
191 out = 'app.xml',
192 visibility = [],
193 )
194
195 sources = [
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700196 '$(location :%s-feature) %s' % (name, feature_coords),
Brian O'Connore4da59d2016-04-08 00:32:18 -0700197 '$(location :%s-app-xml) NONE' % name,
Brian O'Connor1f165982016-04-06 21:36:09 -0700198 ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700199 sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
Brian O'Connor1f165982016-04-06 21:36:09 -0700200 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700201 name = name + '-oar',
Brian O'Connor1f165982016-04-06 21:36:09 -0700202 out = 'app.oar',
Brian O'Connore4da59d2016-04-08 00:32:18 -0700203 bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources),
204 visibility = visibility,
Brian O'Connor1f165982016-04-06 21:36:09 -0700205 )