Refactoring features rule and generation
Change-Id: Id3eb8b595f858c7d362414c7b7ff5db0ae269c1d
Showing
2 changed files
with
165 additions
and
26 deletions
... | @@ -51,31 +51,47 @@ def mvnUrl(bundle): | ... | @@ -51,31 +51,47 @@ def mvnUrl(bundle): |
51 | parts[4] = parts[4][len(NON_OSGI_TAG):] | 51 | parts[4] = parts[4][len(NON_OSGI_TAG):] |
52 | return prefix + '/'.join(parts) + suffix | 52 | return prefix + '/'.join(parts) + suffix |
53 | 53 | ||
54 | -def generateFeatureFile(feature_name, | 54 | +def generateFeatureFile(feature_repo_name, |
55 | - version, | ||
56 | - title, | ||
57 | - feature_repo_name, | ||
58 | features = [], | 55 | features = [], |
59 | - bundles = [], | ||
60 | **kwargs): | 56 | **kwargs): |
61 | values = { | 57 | values = { |
58 | + 'feature_repo_name' : '-'.join(feature_repo_name.split(':')[1:3]), | ||
59 | + } | ||
60 | + | ||
61 | + output = FEATURES_HEADER % values | ||
62 | + | ||
63 | + for feature in features: | ||
64 | + output += feature | ||
65 | + | ||
66 | + output += FEATURES_FOOTER | ||
67 | + return output | ||
68 | + | ||
69 | +def generateFeature(feature_name, | ||
70 | + version, | ||
71 | + title, | ||
72 | + features = [], | ||
73 | + bundles = [], | ||
74 | + **kwargs): | ||
75 | + values = { | ||
62 | 'feature_name' : feature_name, | 76 | 'feature_name' : feature_name, |
63 | 'version' : version, | 77 | 'version' : version, |
64 | 'title' : title, | 78 | 'title' : title, |
65 | - 'feature_repo_name' : '-'.join(feature_repo_name.split(':')[1:3]), | ||
66 | } | 79 | } |
67 | 80 | ||
68 | - output = FEATURES_HEADER % values + FEATURE_HEADER % values | 81 | + output = FEATURE_HEADER % values |
69 | 82 | ||
70 | - for feature in features: | 83 | + if features: |
71 | - output += EXISTING_FEATURE % feature | 84 | + for feature in features: |
85 | + output += EXISTING_FEATURE % feature | ||
72 | 86 | ||
73 | - for bundle in bundles: | 87 | + if bundles: |
74 | - output += BUNDLE % mvnUrl(bundle) | 88 | + for bundle in bundles: |
89 | + output += BUNDLE % mvnUrl(bundle) | ||
75 | 90 | ||
76 | - output += FEATURE_FOOTER + FEATURES_FOOTER | 91 | + output += FEATURE_FOOTER |
77 | return output | 92 | return output |
78 | 93 | ||
94 | + | ||
79 | def generateAppFile(app_name, | 95 | def generateAppFile(app_name, |
80 | origin, | 96 | origin, |
81 | version, | 97 | version, |
... | @@ -139,12 +155,14 @@ if __name__ == '__main__': | ... | @@ -139,12 +155,14 @@ if __name__ == '__main__': |
139 | 155 | ||
140 | parser.add_option("-A", "--write-app", dest="write_app", action="store_true") | 156 | parser.add_option("-A", "--write-app", dest="write_app", action="store_true") |
141 | parser.add_option("-F", "--write-features", dest="write_features", action="store_true") | 157 | parser.add_option("-F", "--write-features", dest="write_features", action="store_true") |
158 | + parser.add_option("-E", "--write-feature", dest="write_feature", action="store_true") | ||
142 | 159 | ||
143 | (options, args) = parser.parse_args() | 160 | (options, args) = parser.parse_args() |
144 | 161 | ||
145 | values = {} | 162 | values = {} |
146 | if options.feature_coords and options.version and options.title: | 163 | if options.feature_coords and options.version and options.title: |
147 | - values['feature_name'] = options.feature_coords.split(':')[1] | 164 | + parts = options.feature_coords.split(':') |
165 | + values['feature_name'] = parts[1] if len(parts) > 1 else parts[0] | ||
148 | values['version'] = options.version | 166 | values['version'] = options.version |
149 | values['title'] = options.title | 167 | values['title'] = options.title |
150 | else: | 168 | else: |
... | @@ -165,15 +183,22 @@ if __name__ == '__main__': | ... | @@ -165,15 +183,22 @@ if __name__ == '__main__': |
165 | values['feature_repo_name'] = options.repo_name if options.repo_name \ | 183 | values['feature_repo_name'] = options.repo_name if options.repo_name \ |
166 | else options.feature_coords | 184 | else options.feature_coords |
167 | 185 | ||
186 | + bundles = [] | ||
187 | + if options.included_bundles: | ||
188 | + bundles += options.included_bundles | ||
189 | + if options.excluded_bundles: | ||
190 | + bundles += options.excluded_bundles | ||
191 | + feature = generateFeature(bundles=bundles, | ||
192 | + features=options.features, | ||
193 | + **values) | ||
194 | + | ||
195 | + if options.write_feature: | ||
196 | + print feature | ||
197 | + | ||
168 | if options.write_features: | 198 | if options.write_features: |
169 | - bundles = [] | 199 | + print generateFeatureFile(features=[ feature ], |
170 | - if options.included_bundles: | ||
171 | - bundles += options.included_bundles | ||
172 | - if options.excluded_bundles: | ||
173 | - bundles += options.excluded_bundles | ||
174 | - print generateFeatureFile(bundles=bundles, | ||
175 | - features=options.features, | ||
176 | **values) | 200 | **values) |
201 | + | ||
177 | if options.write_app: | 202 | if options.write_app: |
178 | print generateAppFile(artifacts=options.included_bundles, | 203 | print generateAppFile(artifacts=options.included_bundles, |
179 | apps=options.apps, | 204 | apps=options.apps, | ... | ... |
... | @@ -16,6 +16,107 @@ def _get_app_name(): | ... | @@ -16,6 +16,107 @@ def _get_app_name(): |
16 | base_path = get_base_path() | 16 | base_path = get_base_path() |
17 | return APP_PREFIX + os.path.basename(base_path) | 17 | return APP_PREFIX + os.path.basename(base_path) |
18 | 18 | ||
19 | +def 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 | + | ||
64 | +FEATURES_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 | + | ||
72 | +FEATURES_FOOTER = '</features>' | ||
73 | + | ||
74 | +def 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 | ||
93 | +def 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 | + | ||
19 | def onos_app( | 120 | def onos_app( |
20 | app_name = None, | 121 | app_name = None, |
21 | name = None, | 122 | name = None, |
... | @@ -66,13 +167,26 @@ def onos_app( | ... | @@ -66,13 +167,26 @@ def onos_app( |
66 | args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ] | 167 | args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ] |
67 | args += [ '-d %s' % a for a in required_apps ] | 168 | args += [ '-d %s' % a for a in required_apps ] |
68 | 169 | ||
69 | - cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT' | 170 | + # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT' |
70 | - genrule( | 171 | + # genrule( |
71 | - name = name + '-features', | 172 | + # name = name + '-feature', |
72 | - bash = cmd, | 173 | + # bash = cmd, |
73 | - out = 'features.xml', | 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, | ||
74 | visibility = [], | 186 | visibility = [], |
187 | + stage_repo = False, | ||
75 | ) | 188 | ) |
189 | + | ||
76 | cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT' | 190 | cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT' |
77 | genrule( | 191 | genrule( |
78 | name = name + '-app-xml', | 192 | name = name + '-app-xml', |
... | @@ -82,7 +196,7 @@ def onos_app( | ... | @@ -82,7 +196,7 @@ def onos_app( |
82 | ) | 196 | ) |
83 | 197 | ||
84 | sources = [ | 198 | sources = [ |
85 | - '$(location :%s-features) %s' % (name, feature_coords), | 199 | + '$(location :%s-feature) %s' % (name, feature_coords), |
86 | '$(location :%s-app-xml) NONE' % name, | 200 | '$(location :%s-app-xml) NONE' % name, |
87 | ] | 201 | ] |
88 | sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles] | 202 | sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles] | ... | ... |
-
Please register or login to post a comment