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 = [], |
| 74 | visibility = [ 'PUBLIC' ], |
| 75 | ): |
| 76 | |
| 77 | cmd = "(echo '%s'; " % FEATURES_HEADER |
| 78 | cmd += ''.join(['cat $(location %s-feature); ' % s for s in features]) |
| 79 | cmd += "echo '%s') > $OUT" % FEATURES_FOOTER |
| 80 | |
| 81 | genrule( |
| 82 | name = name, |
| 83 | bash = cmd, |
| 84 | visibility = visibility, |
| 85 | out = 'features.xml', |
| 86 | ) |
| 87 | |
| 88 | |
| 89 | #TODO rename this |
| 90 | def osgi_feature_group( |
| 91 | name, |
| 92 | description = 'TEST', |
| 93 | version = ONOS_VERSION, |
| 94 | exported_deps = [], |
| 95 | visibility = ['PUBLIC'], |
| 96 | **kwargs |
| 97 | ): |
| 98 | java_library( |
| 99 | name = name, |
| 100 | exported_deps = exported_deps, #compile only |
| 101 | visibility = visibility, |
| 102 | ) |
| 103 | |
| 104 | osgi_feature( |
| 105 | name = name, |
| 106 | feature_coords = name, |
| 107 | version = version, |
| 108 | title = description, |
| 109 | required_features = [], |
| 110 | included_bundles = exported_deps, |
| 111 | generate_file = False, |
| 112 | visibility = visibility, |
| 113 | ) |
| 114 | |
| 115 | |
| 116 | |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 117 | def onos_app( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 118 | app_name = None, |
| 119 | name = None, |
| 120 | title = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 121 | version = ONOS_VERSION, |
| 122 | origin = ONOS_ORIGIN, |
| 123 | category = DEFAULT_APP_CATEGORY, |
| 124 | url = None, |
| 125 | description = None, #TODO make this a file |
| 126 | #TODO icon, |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 127 | feature_coords = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 128 | required_features = [ 'onos-api' ], |
| 129 | required_apps = [], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 130 | included_bundles = None, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 131 | excluded_bundles = [], |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 132 | visibility = [ 'PUBLIC' ], |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 133 | **kwargs): |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 134 | if name is None: |
| 135 | name = _get_name() |
| 136 | |
| 137 | if app_name is None: |
| 138 | app_name = _get_app_name() |
| 139 | |
| 140 | if title is None: |
| 141 | print "Missing title for %s" % _get_name() |
| 142 | title = _get_app_name() |
| 143 | |
| 144 | if included_bundles is None: |
| 145 | target = ':' + _get_name() |
| 146 | included_bundles = [ target ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 147 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 148 | if not feature_coords and len(included_bundles) == 1: |
| 149 | feature_coords = '$(maven_coords %s)' % included_bundles[0] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 150 | |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 151 | if not feature_coords: |
Ray Milkey | 24439fe | 2016-04-08 21:50:55 -0700 | [diff] [blame] | 152 | 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] | 153 | |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 154 | args = [ '-n %s' % feature_coords, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 155 | '-v %s' % version, |
| 156 | '-t "%s"' % title, |
| 157 | '-o "%s"' % origin, |
| 158 | '-c "%s"' % category, |
| 159 | '-a "%s"' % app_name, |
| 160 | '-u %s' % url, |
| 161 | ] |
| 162 | args += [ '-f %s' % f for f in required_features ] |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 163 | args += [ '-b $(maven_coords %s)' % b for b in included_bundles ] |
| 164 | args += [ '-e $(maven_coords %s)' % b for b in excluded_bundles ] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 165 | args += [ '-d %s' % a for a in required_apps ] |
| 166 | |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 167 | # cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT' |
| 168 | # genrule( |
| 169 | # name = name + '-feature', |
| 170 | # bash = cmd, |
| 171 | # out = 'features.xml', |
| 172 | # visibility = [], |
| 173 | # ) |
| 174 | osgi_feature( |
| 175 | name = name, |
| 176 | feature_coords = feature_coords, |
| 177 | version = version, |
| 178 | title = title, |
| 179 | required_features = required_features, |
| 180 | included_bundles = included_bundles, |
| 181 | excluded_bundles = excluded_bundles, |
| 182 | generate_file = True, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 183 | visibility = [], |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 184 | stage_repo = False, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 185 | ) |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 186 | |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 187 | cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT' |
| 188 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 189 | name = name + '-app-xml', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 190 | bash = cmd, |
| 191 | out = 'app.xml', |
| 192 | visibility = [], |
| 193 | ) |
| 194 | |
| 195 | sources = [ |
Brian O'Connor | fc7f5fc | 2016-04-29 17:04:06 -0700 | [diff] [blame] | 196 | '$(location :%s-feature) %s' % (name, feature_coords), |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 197 | '$(location :%s-app-xml) NONE' % name, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 198 | ] |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 199 | 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] | 200 | genrule( |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 201 | name = name + '-oar', |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 202 | out = 'app.oar', |
Brian O'Connor | e4da59d | 2016-04-08 00:32:18 -0700 | [diff] [blame] | 203 | bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources), |
| 204 | visibility = visibility, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 205 | ) |