Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 1 | ONOS_ORIGIN = 'ON.Lab' |
Ray Milkey | 24439fe | 2016-04-08 21:50:55 -0700 | [diff] [blame] | 2 | ONOS_GROUP_ID = 'org.onosproject' |
Thomas Vachuska | 389f108 | 2016-06-08 17:57:28 -0700 | [diff] [blame] | 3 | ONOS_VERSION = '1.6.0-SNAPSHOT' |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 4 | DEFAULT_APP_CATEGORY = 'Utility' |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 5 | ONOS_ARTIFACT_BASE = 'onos-' |
Ray Milkey | 24439fe | 2016-04-08 21:50:55 -0700 | [diff] [blame] | 6 | APP_PREFIX = ONOS_GROUP_ID + '.' |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 7 | |
| 8 | import os.path |
| 9 | |
| 10 | # FIXME Factor this into common place |
| 11 | def _get_name(): |
| 12 | base_path = get_base_path() |
| 13 | return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator |
| 14 | |
| 15 | def _get_app_name(): |
| 16 | base_path = get_base_path() |
| 17 | return APP_PREFIX + os.path.basename(base_path) |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 18 | |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 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 | |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 120 | def onos_app( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 121 | app_name = None, |
| 122 | name = None, |
| 123 | title = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 124 | version = ONOS_VERSION, |
| 125 | origin = ONOS_ORIGIN, |
| 126 | category = DEFAULT_APP_CATEGORY, |
| 127 | url = None, |
| 128 | description = None, #TODO make this a file |
| 129 | #TODO icon, |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 130 | feature_coords = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 131 | required_features = [ 'onos-api' ], |
| 132 | required_apps = [], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 133 | included_bundles = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 134 | excluded_bundles = [], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 135 | visibility = [ 'PUBLIC' ], |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 136 | **kwargs): |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 137 | if name is None: |
| 138 | name = _get_name() |
| 139 | |
| 140 | if app_name is None: |
| 141 | app_name = _get_app_name() |
| 142 | |
| 143 | if title is None: |
| 144 | print "Missing title for %s" % _get_name() |
| 145 | title = _get_app_name() |
| 146 | |
| 147 | if included_bundles is None: |
| 148 | target = ':' + _get_name() |
| 149 | included_bundles = [ target ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 150 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 151 | if not feature_coords and len(included_bundles) == 1: |
| 152 | feature_coords = '$(maven_coords %s)' % included_bundles[0] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 153 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 154 | if not feature_coords: |
Ray Milkey | 24439fe | 2016-04-08 21:50:55 -0700 | [diff] [blame] | 155 | 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] | 156 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 157 | args = [ '-n %s' % feature_coords, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 158 | '-v %s' % version, |
| 159 | '-t "%s"' % title, |
| 160 | '-o "%s"' % origin, |
| 161 | '-c "%s"' % category, |
| 162 | '-a "%s"' % app_name, |
| 163 | '-u %s' % url, |
| 164 | ] |
| 165 | args += [ '-f %s' % f for f in required_features ] |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 166 | args += [ '-b $(maven_coords %s)' % b for b in included_bundles ] |
| 167 | args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 168 | args += [ '-d %s' % a for a in required_apps ] |
| 169 | |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 170 | # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT' |
| 171 | # genrule( |
| 172 | # name = name + '-feature', |
| 173 | # bash = cmd, |
| 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, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 186 | visibility = [], |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 187 | stage_repo = False, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 188 | ) |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 189 | |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 190 | cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT' |
| 191 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 192 | name = name + '-app-xml', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 193 | bash = cmd, |
| 194 | out = 'app.xml', |
| 195 | visibility = [], |
| 196 | ) |
| 197 | |
| 198 | sources = [ |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 199 | '$(location :%s-feature) %s' % (name, feature_coords), |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 200 | '$(location :%s-app-xml) NONE' % name, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 201 | ] |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 202 | 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] | 203 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 204 | name = name + '-oar', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 205 | out = 'app.oar', |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 206 | bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources), |
| 207 | visibility = visibility, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 208 | ) |