onos_app.bucklet
5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
ONOS_ORIGIN = 'ON.Lab'
ONOS_GROUP_ID = 'org.onosproject'
ONOS_VERSION = '1.6.1-SNAPSHOT'
DEFAULT_APP_CATEGORY = 'Utility'
ONOS_ARTIFACT_BASE = 'onos-'
APP_PREFIX = ONOS_GROUP_ID + '.'
import os.path
# FIXME Factor this into common place
def _get_name():
base_path = get_base_path()
return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
def _get_app_name():
base_path = get_base_path()
return APP_PREFIX + os.path.basename(base_path)
def osgi_feature(
name,
title,
feature_coords = None,
version = ONOS_VERSION,
required_features = [ 'onos-api' ],
required_apps = [],
included_bundles = None,
excluded_bundles = [],
generate_file = False,
visibility = [ 'PUBLIC' ],
stage_repo = True,
):
if not feature_coords:
feature_coords = name
args = [ '-n %s' % feature_coords,
'-v %s' % version,
'-t "%s"' % title,
]
args += [ '-f %s' % f for f in required_features ]
args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
args += [ '-d %s' % a for a in required_apps ]
feature_cmd = '-F' if generate_file else '-E'
cmd = '$(exe //buck-tools:onos-app-writer) %s ' % feature_cmd
cmd += ' '.join(args) + ' > $OUT'
genrule(
name = name + '-feature',
bash = cmd,
out = 'features.xml',
visibility = visibility,
)
if stage_repo:
sources = ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
genrule(
name = name + '-repo',
out = name + '-repo.zip.part',
bash = '$(exe //buck-tools:onos-feature) $OUT ' + ' '.join(sources),
visibility = visibility,
)
FEATURES_HEADER = '''\
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
name="onos-%s">
<repository>mvn:org.apache.karaf.features/standard/3.0.5/xml/features</repository>
''' % ONOS_VERSION
FEATURES_FOOTER = '</features>'
def compile_features(
name,
features = [],
visibility = [ 'PUBLIC' ],
):
cmd = "(echo '%s'; " % FEATURES_HEADER
cmd += ''.join(['cat $(location %s-feature); ' % s for s in features])
cmd += "echo '%s') > $OUT" % FEATURES_FOOTER
genrule(
name = name,
bash = cmd,
visibility = visibility,
out = 'features.xml',
)
#TODO rename this
def osgi_feature_group(
name,
description = 'TEST',
version = ONOS_VERSION,
exported_deps = [],
visibility = ['PUBLIC'],
**kwargs
):
java_library(
name = name,
exported_deps = exported_deps, #compile only
visibility = visibility,
)
osgi_feature(
name = name,
feature_coords = name,
version = version,
title = description,
required_features = [],
included_bundles = exported_deps,
generate_file = False,
visibility = visibility,
)
def onos_app(
app_name = None,
name = None,
title = None,
version = ONOS_VERSION,
origin = ONOS_ORIGIN,
category = DEFAULT_APP_CATEGORY,
url = None,
description = None, #TODO make this a file
#TODO icon,
feature_coords = None,
required_features = [ 'onos-api' ],
required_apps = [],
included_bundles = None,
excluded_bundles = [],
visibility = [ 'PUBLIC' ],
**kwargs):
if name is None:
name = _get_name()
if app_name is None:
app_name = _get_app_name()
if title is None:
print "Missing title for %s" % _get_name()
title = _get_app_name()
if included_bundles is None:
target = ':' + _get_name()
included_bundles = [ target ]
if not feature_coords and len(included_bundles) == 1:
feature_coords = '$(maven_coords %s)' % included_bundles[0]
if not feature_coords:
feature_coords = '%s:%s:%s' % ( ONOS_GROUP_ID, _get_name(), ONOS_VERSION )
args = [ '-n %s' % feature_coords,
'-v %s' % version,
'-t "%s"' % title,
'-o "%s"' % origin,
'-c "%s"' % category,
'-a "%s"' % app_name,
'-u %s' % url,
]
args += [ '-f %s' % f for f in required_features ]
args += [ '-b $(maven_coords %s)' % b for b in included_bundles ]
args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ]
args += [ '-d %s' % a for a in required_apps ]
# cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT'
# genrule(
# name = name + '-feature',
# bash = cmd,
# out = 'features.xml',
# visibility = [],
# )
osgi_feature(
name = name,
feature_coords = feature_coords,
version = version,
title = title,
required_features = required_features,
included_bundles = included_bundles,
excluded_bundles = excluded_bundles,
generate_file = True,
visibility = [],
stage_repo = False,
)
cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT'
genrule(
name = name + '-app-xml',
bash = cmd,
out = 'app.xml',
visibility = [],
)
sources = [
'$(location :%s-feature) %s' % (name, feature_coords),
'$(location :%s-app-xml) NONE' % name,
]
sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
genrule(
name = name + '-oar',
out = 'app.oar',
bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources),
visibility = visibility,
)