blob: d95427ed5bb49811e315f679b77f9b80e17e971b [file] [log] [blame]
Brian O'Connor1f165982016-04-06 21:36:09 -07001ONOS_ORIGIN = 'ON.Lab'
2ONOS_VERSION = '1.6.0-SNAPSHOT'
3DEFAULT_APP_CATEGORY = 'Utility'
Brian O'Connore4da59d2016-04-08 00:32:18 -07004ONOS_ARTIFACT_BASE = 'onos-'
5APP_PREFIX = 'org.onosproject.'
6
7import os.path
8
9# FIXME Factor this into common place
10def _get_name():
11 base_path = get_base_path()
12 return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
13
14def _get_app_name():
15 base_path = get_base_path()
16 return APP_PREFIX + os.path.basename(base_path)
Brian O'Connor1f165982016-04-06 21:36:09 -070017
18def onos_app(
Brian O'Connore4da59d2016-04-08 00:32:18 -070019 app_name = None,
20 name = None,
21 title = None,
Brian O'Connor1f165982016-04-06 21:36:09 -070022 version = ONOS_VERSION,
23 origin = ONOS_ORIGIN,
24 category = DEFAULT_APP_CATEGORY,
25 url = None,
26 description = None, #TODO make this a file
27 #TODO icon,
Brian O'Connore124f3d2016-04-06 23:54:26 -070028 feature_coords = None,
Brian O'Connor1f165982016-04-06 21:36:09 -070029 required_features = [ 'onos-api' ],
30 required_apps = [],
Brian O'Connore4da59d2016-04-08 00:32:18 -070031 included_bundles = None,
Brian O'Connor1f165982016-04-06 21:36:09 -070032 excluded_bundles = [],
Brian O'Connore4da59d2016-04-08 00:32:18 -070033 visibility = [ 'PUBLIC' ],
Brian O'Connor1f165982016-04-06 21:36:09 -070034 **kwargs):
Brian O'Connore4da59d2016-04-08 00:32:18 -070035 if name is None:
36 name = _get_name()
37
38 if app_name is None:
39 app_name = _get_app_name()
40
41 if title is None:
42 print "Missing title for %s" % _get_name()
43 title = _get_app_name()
44
45 if included_bundles is None:
46 target = ':' + _get_name()
47 included_bundles = [ target ]
Brian O'Connor1f165982016-04-06 21:36:09 -070048
Brian O'Connore124f3d2016-04-06 23:54:26 -070049 if not feature_coords and len(included_bundles) == 1:
50 feature_coords = '$(maven_coords %s)' % included_bundles[0]
Brian O'Connor1f165982016-04-06 21:36:09 -070051
Brian O'Connore4da59d2016-04-08 00:32:18 -070052 if not feature_coords:
53 print 'Missing maven coordinates for %s app feature.' % name
54 return
55
Brian O'Connore124f3d2016-04-06 23:54:26 -070056 args = [ '-n %s' % feature_coords,
Brian O'Connor1f165982016-04-06 21:36:09 -070057 '-v %s' % version,
58 '-t "%s"' % title,
59 '-o "%s"' % origin,
60 '-c "%s"' % category,
61 '-a "%s"' % app_name,
62 '-u %s' % url,
63 ]
64 args += [ '-f %s' % f for f in required_features ]
Brian O'Connore124f3d2016-04-06 23:54:26 -070065 args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
66 args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
Brian O'Connor1f165982016-04-06 21:36:09 -070067 args += [ '-d %s' % a for a in required_apps ]
68
69 cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT'
70 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -070071 name = name + '-features',
Brian O'Connor1f165982016-04-06 21:36:09 -070072 bash = cmd,
Brian O'Connore124f3d2016-04-06 23:54:26 -070073 out = 'features.xml',
Brian O'Connor1f165982016-04-06 21:36:09 -070074 visibility = [],
75 )
76 cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT'
77 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -070078 name = name + '-app-xml',
Brian O'Connor1f165982016-04-06 21:36:09 -070079 bash = cmd,
80 out = 'app.xml',
81 visibility = [],
82 )
83
84 sources = [
Brian O'Connore4da59d2016-04-08 00:32:18 -070085 '$(location :%s-features) %s' % (name, feature_coords),
86 '$(location :%s-app-xml) NONE' % name,
Brian O'Connor1f165982016-04-06 21:36:09 -070087 ]
Brian O'Connore124f3d2016-04-06 23:54:26 -070088 sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
Brian O'Connor1f165982016-04-06 21:36:09 -070089 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -070090 name = name + '-oar',
Brian O'Connor1f165982016-04-06 21:36:09 -070091 out = 'app.oar',
Brian O'Connore4da59d2016-04-08 00:32:18 -070092 bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources),
93 visibility = visibility,
Brian O'Connor1f165982016-04-06 21:36:09 -070094 )