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