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 | cab7dc5 | 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 | cab7dc5 | 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"> |
| 67 | <repository>mvn:org.apache.karaf.features/standard/3.0.5/xml/features</repository> |
| 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 | cab7dc5 | 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 | cab7dc5 | 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' ], |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 139 | **kwargs): |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 140 | if name is None: |
| 141 | name = _get_name() |
| 142 | |
| 143 | if app_name is None: |
| 144 | app_name = _get_app_name() |
| 145 | |
Brian O'Connor | 8cc10ec | 2016-09-13 16:29:36 -0700 | [diff] [blame] | 146 | maven_coords = '%s:%s:oar:%s' % ( ONOS_GROUP_ID, name, ONOS_VERSION ) |
Ray Milkey | cab7dc5 | 2016-12-09 16:21:55 -0800 | [diff] [blame] | 147 | 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] | 148 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 149 | if title is None: |
| 150 | print "Missing title for %s" % _get_name() |
| 151 | title = _get_app_name() |
| 152 | |
| 153 | if included_bundles is None: |
| 154 | target = ':' + _get_name() |
| 155 | included_bundles = [ target ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 156 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 157 | if not feature_coords and len(included_bundles) == 1: |
| 158 | feature_coords = '$(maven_coords %s)' % included_bundles[0] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 159 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 160 | if not feature_coords: |
Ray Milkey | 24439fe | 2016-04-08 21:50:55 -0700 | [diff] [blame] | 161 | feature_coords = '%s:%s:%s' % ( ONOS_GROUP_ID, _get_name(), ONOS_VERSION ) |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 162 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 163 | args = [ '-n %s' % feature_coords, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 164 | '-v %s' % version, |
| 165 | '-t "%s"' % title, |
| 166 | '-o "%s"' % origin, |
| 167 | '-c "%s"' % category, |
| 168 | '-a "%s"' % app_name, |
| 169 | '-u %s' % url, |
| 170 | ] |
| 171 | args += [ '-f %s' % f for f in required_features ] |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 172 | args += [ '-b $(maven_coords %s)' % b for b in included_bundles ] |
| 173 | args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 174 | args += [ '-d %s' % a for a in required_apps ] |
| 175 | |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 176 | # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT' |
| 177 | # genrule( |
| 178 | # name = name + '-feature', |
| 179 | # bash = cmd, |
| 180 | # out = 'features.xml', |
| 181 | # visibility = [], |
| 182 | # ) |
| 183 | osgi_feature( |
| 184 | name = name, |
| 185 | feature_coords = feature_coords, |
| 186 | version = version, |
| 187 | title = title, |
| 188 | required_features = required_features, |
| 189 | included_bundles = included_bundles, |
| 190 | excluded_bundles = excluded_bundles, |
| 191 | generate_file = True, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 192 | visibility = [], |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 193 | stage_repo = False, |
Ray Milkey | cab7dc5 | 2016-12-09 16:21:55 -0800 | [diff] [blame] | 194 | maven_coords = feature_xml_coords, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 195 | ) |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 196 | |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 197 | cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT' |
| 198 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 199 | name = name + '-app-xml', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 200 | bash = cmd, |
| 201 | out = 'app.xml', |
| 202 | visibility = [], |
| 203 | ) |
| 204 | |
| 205 | sources = [ |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 206 | '$(location :%s-feature) %s' % (name, feature_coords), |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 207 | '$(location :%s-app-xml) NONE' % name, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 208 | ] |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 209 | 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] | 210 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 211 | name = name + '-oar', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 212 | out = 'app.oar', |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 213 | bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources), |
Brian O'Connor | 8cc10ec | 2016-09-13 16:29:36 -0700 | [diff] [blame] | 214 | maven_coords = maven_coords, |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 215 | visibility = visibility, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 216 | ) |