blob: a50b2005546df5260a15f1c5ff46e0fc9cac2c4b [file] [log] [blame]
Brian O'Connor1f165982016-04-06 21:36:09 -07001ONOS_ORIGIN = 'ON.Lab'
Ray Milkey24439fe2016-04-08 21:50:55 -07002ONOS_GROUP_ID = 'org.onosproject'
Brian O'Connore642f7c2016-05-23 18:33:04 -07003ONOS_VERSION = '1.7.0-SNAPSHOT'
Brian O'Connor1f165982016-04-06 21:36:09 -07004DEFAULT_APP_CATEGORY = 'Utility'
Brian O'Connore4da59d2016-04-08 00:32:18 -07005ONOS_ARTIFACT_BASE = 'onos-'
Ray Milkey24439fe2016-04-08 21:50:55 -07006APP_PREFIX = ONOS_GROUP_ID + '.'
Brian O'Connore4da59d2016-04-08 00:32:18 -07007
8import os.path
9
10# FIXME Factor this into common place
11def _get_name():
12 base_path = get_base_path()
13 return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
14
15def _get_app_name():
16 base_path = get_base_path()
17 return APP_PREFIX + os.path.basename(base_path)
Brian O'Connor1f165982016-04-06 21:36:09 -070018
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -070019def osgi_feature(
20 name,
21 title,
22 feature_coords = None,
23 version = ONOS_VERSION,
24 required_features = [ 'onos-api' ],
25 required_apps = [],
26 included_bundles = None,
27 excluded_bundles = [],
28 generate_file = False,
29 visibility = [ 'PUBLIC' ],
30 stage_repo = True,
31 ):
32
33 if not feature_coords:
34 feature_coords = name
35 args = [ '-n %s' % feature_coords,
36 '-v %s' % version,
37 '-t "%s"' % title,
38 ]
39 args += [ '-f %s' % f for f in required_features ]
40 args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
41 args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
42 args += [ '-d %s' % a for a in required_apps ]
43
44 feature_cmd = '-F' if generate_file else '-E'
45
46 cmd = '$(exe //buck-tools:onos-app-writer) %s ' % feature_cmd
47 cmd += ' '.join(args) + ' > $OUT'
48 genrule(
49 name = name + '-feature',
50 bash = cmd,
51 out = 'features.xml',
52 visibility = visibility,
53 )
54
55 if stage_repo:
56 sources = ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
57 genrule(
58 name = name + '-repo',
59 out = name + '-repo.zip.part',
60 bash = '$(exe //buck-tools:onos-feature) $OUT ' + ' '.join(sources),
61 visibility = visibility,
62 )
63
64FEATURES_HEADER = '''\
65<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
66<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
67 name="onos-%s">
68 <repository>mvn:org.apache.karaf.features/standard/3.0.5/xml/features</repository>
69
70''' % ONOS_VERSION
71
72FEATURES_FOOTER = '</features>'
73
74def compile_features(
75 name,
76 features = [],
77 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',
89 )
90
91
92#TODO rename this
93def osgi_feature_group(
94 name,
95 description = 'TEST',
96 version = ONOS_VERSION,
97 exported_deps = [],
98 visibility = ['PUBLIC'],
99 **kwargs
100 ):
101 java_library(
102 name = name,
103 exported_deps = exported_deps, #compile only
104 visibility = visibility,
105 )
106
107 osgi_feature(
108 name = name,
109 feature_coords = name,
110 version = version,
111 title = description,
112 required_features = [],
113 included_bundles = exported_deps,
114 generate_file = False,
115 visibility = visibility,
116 )
117
118
119
Brian O'Connor1f165982016-04-06 21:36:09 -0700120def onos_app(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700121 app_name = None,
122 name = None,
123 title = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700124 version = ONOS_VERSION,
125 origin = ONOS_ORIGIN,
126 category = DEFAULT_APP_CATEGORY,
127 url = None,
128 description = None, #TODO make this a file
129 #TODO icon,
Brian O'Connore124f3d2016-04-06 23:54:26 -0700130 feature_coords = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700131 required_features = [ 'onos-api' ],
132 required_apps = [],
Brian O'Connore4da59d2016-04-08 00:32:18 -0700133 included_bundles = None,
Brian O'Connor1f165982016-04-06 21:36:09 -0700134 excluded_bundles = [],
Brian O'Connore4da59d2016-04-08 00:32:18 -0700135 visibility = [ 'PUBLIC' ],
Brian O'Connor1f165982016-04-06 21:36:09 -0700136 **kwargs):
Brian O'Connore4da59d2016-04-08 00:32:18 -0700137 if name is None:
138 name = _get_name()
139
140 if app_name is None:
141 app_name = _get_app_name()
142
143 if title is None:
144 print "Missing title for %s" % _get_name()
145 title = _get_app_name()
146
147 if included_bundles is None:
148 target = ':' + _get_name()
149 included_bundles = [ target ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700150
Brian O'Connore124f3d2016-04-06 23:54:26 -0700151 if not feature_coords and len(included_bundles) == 1:
152 feature_coords = '$(maven_coords %s)' % included_bundles[0]
Brian O'Connor1f165982016-04-06 21:36:09 -0700153
Brian O'Connore4da59d2016-04-08 00:32:18 -0700154 if not feature_coords:
Ray Milkey24439fe2016-04-08 21:50:55 -0700155 feature_coords = '%s:%s:%s' % ( ONOS_GROUP_ID, _get_name(), ONOS_VERSION )
Brian O'Connore4da59d2016-04-08 00:32:18 -0700156
Brian O'Connore124f3d2016-04-06 23:54:26 -0700157 args = [ '-n %s' % feature_coords,
Brian O'Connor1f165982016-04-06 21:36:09 -0700158 '-v %s' % version,
159 '-t "%s"' % title,
160 '-o "%s"' % origin,
161 '-c "%s"' % category,
162 '-a "%s"' % app_name,
163 '-u %s' % url,
164 ]
165 args += [ '-f %s' % f for f in required_features ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700166 args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
167 args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
Brian O'Connor1f165982016-04-06 21:36:09 -0700168 args += [ '-d %s' % a for a in required_apps ]
169
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700170 # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT'
171 # genrule(
172 # name = name + '-feature',
173 # bash = cmd,
174 # out = 'features.xml',
175 # visibility = [],
176 # )
177 osgi_feature(
178 name = name,
179 feature_coords = feature_coords,
180 version = version,
181 title = title,
182 required_features = required_features,
183 included_bundles = included_bundles,
184 excluded_bundles = excluded_bundles,
185 generate_file = True,
Brian O'Connor1f165982016-04-06 21:36:09 -0700186 visibility = [],
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700187 stage_repo = False,
Brian O'Connor1f165982016-04-06 21:36:09 -0700188 )
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700189
Brian O'Connor1f165982016-04-06 21:36:09 -0700190 cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT'
191 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700192 name = name + '-app-xml',
Brian O'Connor1f165982016-04-06 21:36:09 -0700193 bash = cmd,
194 out = 'app.xml',
195 visibility = [],
196 )
197
198 sources = [
Brian O'Connorfc7f5fc2016-04-29 17:04:06 -0700199 '$(location :%s-feature) %s' % (name, feature_coords),
Brian O'Connore4da59d2016-04-08 00:32:18 -0700200 '$(location :%s-app-xml) NONE' % name,
Brian O'Connor1f165982016-04-06 21:36:09 -0700201 ]
Brian O'Connore124f3d2016-04-06 23:54:26 -0700202 sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
Brian O'Connor1f165982016-04-06 21:36:09 -0700203 genrule(
Brian O'Connore4da59d2016-04-08 00:32:18 -0700204 name = name + '-oar',
Brian O'Connor1f165982016-04-06 21:36:09 -0700205 out = 'app.oar',
Brian O'Connore4da59d2016-04-08 00:32:18 -0700206 bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources),
207 visibility = visibility,
Brian O'Connor1f165982016-04-06 21:36:09 -0700208 )