Ray Milkey | 171b89a | 2016-07-28 15:22:26 -0700 | [diff] [blame] | 1 | include_defs('//onos.defs') |
| 2 | |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 3 | DEFAULT_APP_CATEGORY = 'Utility' |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 4 | |
| 5 | import os.path |
| 6 | |
| 7 | # FIXME Factor this into common place |
| 8 | def _get_name(): |
| 9 | base_path = get_base_path() |
| 10 | return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator |
| 11 | |
| 12 | def _get_app_name(): |
| 13 | base_path = get_base_path() |
| 14 | return APP_PREFIX + os.path.basename(base_path) |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 15 | |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 16 | def 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, |
Ray Milkey | 033b9f9 | 2016-12-09 16:21:55 -0800 | [diff] [blame] | 28 | maven_coords = None, |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 29 | ): |
| 30 | |
| 31 | if not feature_coords: |
| 32 | feature_coords = name |
| 33 | args = [ '-n %s' % feature_coords, |
| 34 | '-v %s' % version, |
| 35 | '-t "%s"' % title, |
| 36 | ] |
| 37 | args += [ '-f %s' % f for f in required_features ] |
| 38 | args += [ '-b $(maven_coords %s)' % b for b in included_bundles ] |
| 39 | args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ] |
| 40 | args += [ '-d %s' % a for a in required_apps ] |
| 41 | |
| 42 | feature_cmd = '-F' if generate_file else '-E' |
| 43 | |
| 44 | cmd = '$(exe //buck-tools:onos-app-writer) %s ' % feature_cmd |
| 45 | cmd += ' '.join(args) + ' > $OUT' |
| 46 | genrule( |
| 47 | name = name + '-feature', |
| 48 | bash = cmd, |
| 49 | out = 'features.xml', |
| 50 | visibility = visibility, |
Ray Milkey | 033b9f9 | 2016-12-09 16:21:55 -0800 | [diff] [blame] | 51 | maven_coords = maven_coords, |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 52 | ) |
| 53 | |
| 54 | if stage_repo: |
| 55 | sources = ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles] |
| 56 | genrule( |
| 57 | name = name + '-repo', |
| 58 | out = name + '-repo.zip.part', |
| 59 | bash = '$(exe //buck-tools:onos-feature) $OUT ' + ' '.join(sources), |
| 60 | visibility = visibility, |
| 61 | ) |
| 62 | |
| 63 | FEATURES_HEADER = '''\ |
| 64 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
| 65 | <features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" |
| 66 | name="onos-%s"> |
Jon Hall | b84df5d | 2017-01-31 11:19:48 -0800 | [diff] [blame] | 67 | <repository>mvn:org.apache.karaf.features/standard/3.0.8/xml/features</repository> |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 68 | |
| 69 | ''' % ONOS_VERSION |
| 70 | |
| 71 | FEATURES_FOOTER = '</features>' |
| 72 | |
| 73 | def compile_features( |
| 74 | name, |
| 75 | features = [], |
Brian O'Connor | 8cc10ec | 2016-09-13 16:29:36 -0700 | [diff] [blame] | 76 | maven_coords = None, |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 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', |
Brian O'Connor | 8cc10ec | 2016-09-13 16:29:36 -0700 | [diff] [blame] | 89 | maven_coords = maven_coords, |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 90 | ) |
| 91 | |
| 92 | |
| 93 | #TODO rename this |
| 94 | def osgi_feature_group( |
| 95 | name, |
| 96 | description = 'TEST', |
| 97 | version = ONOS_VERSION, |
| 98 | exported_deps = [], |
| 99 | visibility = ['PUBLIC'], |
Ray Milkey | 033b9f9 | 2016-12-09 16:21:55 -0800 | [diff] [blame] | 100 | maven_coords = None, |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 101 | **kwargs |
| 102 | ): |
| 103 | java_library( |
| 104 | name = name, |
| 105 | exported_deps = exported_deps, #compile only |
| 106 | visibility = visibility, |
| 107 | ) |
| 108 | |
| 109 | osgi_feature( |
| 110 | name = name, |
| 111 | feature_coords = name, |
| 112 | version = version, |
| 113 | title = description, |
| 114 | required_features = [], |
| 115 | included_bundles = exported_deps, |
| 116 | generate_file = False, |
| 117 | visibility = visibility, |
Ray Milkey | 033b9f9 | 2016-12-09 16:21:55 -0800 | [diff] [blame] | 118 | maven_coords = maven_coords, |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 119 | ) |
| 120 | |
| 121 | |
| 122 | |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 123 | def onos_app( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 124 | app_name = None, |
| 125 | name = None, |
| 126 | title = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 127 | version = ONOS_VERSION, |
| 128 | origin = ONOS_ORIGIN, |
| 129 | category = DEFAULT_APP_CATEGORY, |
| 130 | url = None, |
| 131 | description = None, #TODO make this a file |
| 132 | #TODO icon, |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 133 | feature_coords = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 134 | required_features = [ 'onos-api' ], |
| 135 | required_apps = [], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 136 | included_bundles = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 137 | excluded_bundles = [], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 138 | visibility = [ 'PUBLIC' ], |
Heedo Kang | 3cda3f3 | 2017-09-07 22:27:38 +0900 | [diff] [blame] | 139 | security = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 140 | **kwargs): |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 141 | if name is None: |
| 142 | name = _get_name() |
| 143 | |
| 144 | if app_name is None: |
| 145 | app_name = _get_app_name() |
| 146 | |
Brian O'Connor | 8cc10ec | 2016-09-13 16:29:36 -0700 | [diff] [blame] | 147 | maven_coords = '%s:%s:oar:%s' % ( ONOS_GROUP_ID, name, ONOS_VERSION ) |
Ray Milkey | 033b9f9 | 2016-12-09 16:21:55 -0800 | [diff] [blame] | 148 | feature_xml_coords = '%s:%s:xml:features:%s' % ( ONOS_GROUP_ID, name, ONOS_VERSION ) |
Brian O'Connor | 8cc10ec | 2016-09-13 16:29:36 -0700 | [diff] [blame] | 149 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 150 | if title is None: |
| 151 | print "Missing title for %s" % _get_name() |
| 152 | title = _get_app_name() |
| 153 | |
| 154 | if included_bundles is None: |
Yuta HIGUCHI | 7083150 | 2018-05-14 13:04:21 -0700 | [diff] [blame^] | 155 | target = ':' + name |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 156 | included_bundles = [ target ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 157 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 158 | if not feature_coords and len(included_bundles) == 1: |
| 159 | feature_coords = '$(maven_coords %s)' % included_bundles[0] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 160 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 161 | if not feature_coords: |
Yuta HIGUCHI | 7083150 | 2018-05-14 13:04:21 -0700 | [diff] [blame^] | 162 | feature_coords = '%s:%s:%s' % ( ONOS_GROUP_ID, name, ONOS_VERSION ) |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 163 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 164 | args = [ '-n %s' % feature_coords, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 165 | '-v %s' % version, |
| 166 | '-t "%s"' % title, |
| 167 | '-o "%s"' % origin, |
| 168 | '-c "%s"' % category, |
| 169 | '-a "%s"' % app_name, |
| 170 | '-u %s' % url, |
| 171 | ] |
| 172 | args += [ '-f %s' % f for f in required_features ] |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 173 | args += [ '-b $(maven_coords %s)' % b for b in included_bundles ] |
| 174 | args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 175 | args += [ '-d %s' % a for a in required_apps ] |
Thomas Vachuska | b002968 | 2017-08-23 17:55:53 -0700 | [diff] [blame] | 176 | if description is not None: |
| 177 | args += [ '-D "%s"' % description ] |
Heedo Kang | 3cda3f3 | 2017-09-07 22:27:38 +0900 | [diff] [blame] | 178 | if security is not None: |
| 179 | args += [ '-s "%s"' % security ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 180 | |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 181 | # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT' |
| 182 | # genrule( |
| 183 | # name = name + '-feature', |
| 184 | # bash = cmd, |
| 185 | # out = 'features.xml', |
| 186 | # visibility = [], |
| 187 | # ) |
| 188 | osgi_feature( |
| 189 | name = name, |
| 190 | feature_coords = feature_coords, |
| 191 | version = version, |
| 192 | title = title, |
| 193 | required_features = required_features, |
| 194 | included_bundles = included_bundles, |
| 195 | excluded_bundles = excluded_bundles, |
| 196 | generate_file = True, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 197 | visibility = [], |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 198 | stage_repo = False, |
Ray Milkey | 033b9f9 | 2016-12-09 16:21:55 -0800 | [diff] [blame] | 199 | maven_coords = feature_xml_coords, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 200 | ) |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 201 | |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 202 | cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT' |
| 203 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 204 | name = name + '-app-xml', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 205 | bash = cmd, |
| 206 | out = 'app.xml', |
| 207 | visibility = [], |
| 208 | ) |
| 209 | |
| 210 | sources = [ |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 211 | '$(location :%s-feature) %s' % (name, feature_coords), |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 212 | '$(location :%s-app-xml) NONE' % name, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 213 | ] |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 214 | sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 215 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 216 | name = name + '-oar', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 217 | out = 'app.oar', |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 218 | bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources), |
Brian O'Connor | 8cc10ec | 2016-09-13 16:29:36 -0700 | [diff] [blame] | 219 | maven_coords = maven_coords, |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 220 | visibility = visibility, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 221 | ) |