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' |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 3 | ONOS_VERSION = '1.6.0-SNAPSHOT' |
| 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 | |
| 19 | def onos_app( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 20 | app_name = None, |
| 21 | name = None, |
| 22 | title = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 23 | version = ONOS_VERSION, |
| 24 | origin = ONOS_ORIGIN, |
| 25 | category = DEFAULT_APP_CATEGORY, |
| 26 | url = None, |
| 27 | description = None, #TODO make this a file |
| 28 | #TODO icon, |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 29 | feature_coords = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 30 | required_features = [ 'onos-api' ], |
| 31 | required_apps = [], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 32 | included_bundles = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 33 | excluded_bundles = [], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 34 | visibility = [ 'PUBLIC' ], |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 35 | **kwargs): |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 36 | if name is None: |
| 37 | name = _get_name() |
| 38 | |
| 39 | if app_name is None: |
| 40 | app_name = _get_app_name() |
| 41 | |
| 42 | if title is None: |
| 43 | print "Missing title for %s" % _get_name() |
| 44 | title = _get_app_name() |
| 45 | |
| 46 | if included_bundles is None: |
| 47 | target = ':' + _get_name() |
| 48 | included_bundles = [ target ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 49 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 50 | if not feature_coords and len(included_bundles) == 1: |
| 51 | feature_coords = '$(maven_coords %s)' % included_bundles[0] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 52 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 53 | if not feature_coords: |
Ray Milkey | 24439fe | 2016-04-08 21:50:55 -0700 | [diff] [blame] | 54 | 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] | 55 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 56 | args = [ '-n %s' % feature_coords, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 57 | '-v %s' % version, |
| 58 | '-t "%s"' % title, |
| 59 | '-o "%s"' % origin, |
| 60 | '-c "%s"' % category, |
| 61 | '-a "%s"' % app_name, |
| 62 | '-u %s' % url, |
| 63 | ] |
| 64 | args += [ '-f %s' % f for f in required_features ] |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 65 | args += [ '-b $(maven_coords %s)' % b for b in included_bundles ] |
| 66 | args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 67 | args += [ '-d %s' % a for a in required_apps ] |
| 68 | |
| 69 | cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT' |
| 70 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 71 | name = name + '-features', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 72 | bash = cmd, |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 73 | out = 'features.xml', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 74 | visibility = [], |
| 75 | ) |
| 76 | cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT' |
| 77 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 78 | name = name + '-app-xml', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 79 | bash = cmd, |
| 80 | out = 'app.xml', |
| 81 | visibility = [], |
| 82 | ) |
| 83 | |
| 84 | sources = [ |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 85 | '$(location :%s-features) %s' % (name, feature_coords), |
| 86 | '$(location :%s-app-xml) NONE' % name, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 87 | ] |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 88 | 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] | 89 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 90 | name = name + '-oar', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 91 | out = 'app.oar', |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 92 | bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources), |
| 93 | visibility = visibility, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 94 | ) |