Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 1 | ONOS_ORIGIN = 'ON.Lab' |
| 2 | ONOS_VERSION = '1.6.0-SNAPSHOT' |
| 3 | DEFAULT_APP_CATEGORY = 'Utility' |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame^] | 4 | ONOS_ARTIFACT_BASE = 'onos-' |
| 5 | APP_PREFIX = 'org.onosproject.' |
| 6 | |
| 7 | import os.path |
| 8 | |
| 9 | # FIXME Factor this into common place |
| 10 | def _get_name(): |
| 11 | base_path = get_base_path() |
| 12 | return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator |
| 13 | |
| 14 | def _get_app_name(): |
| 15 | base_path = get_base_path() |
| 16 | return APP_PREFIX + os.path.basename(base_path) |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 17 | |
| 18 | def onos_app( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame^] | 19 | app_name = None, |
| 20 | name = None, |
| 21 | title = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 22 | version = ONOS_VERSION, |
| 23 | origin = ONOS_ORIGIN, |
| 24 | category = DEFAULT_APP_CATEGORY, |
| 25 | url = None, |
| 26 | description = None, #TODO make this a file |
| 27 | #TODO icon, |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 28 | feature_coords = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 29 | required_features = [ 'onos-api' ], |
| 30 | required_apps = [], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame^] | 31 | included_bundles = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 32 | excluded_bundles = [], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame^] | 33 | visibility = [ 'PUBLIC' ], |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 34 | **kwargs): |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame^] | 35 | if name is None: |
| 36 | name = _get_name() |
| 37 | |
| 38 | if app_name is None: |
| 39 | app_name = _get_app_name() |
| 40 | |
| 41 | if title is None: |
| 42 | print "Missing title for %s" % _get_name() |
| 43 | title = _get_app_name() |
| 44 | |
| 45 | if included_bundles is None: |
| 46 | target = ':' + _get_name() |
| 47 | included_bundles = [ target ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 48 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 49 | if not feature_coords and len(included_bundles) == 1: |
| 50 | feature_coords = '$(maven_coords %s)' % included_bundles[0] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 51 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame^] | 52 | if not feature_coords: |
| 53 | print 'Missing maven coordinates for %s app feature.' % name |
| 54 | return |
| 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 | ) |