Ray Milkey | e88d69b | 2016-12-16 17:09:13 -0800 | [diff] [blame] | 1 | include_defs('//onos.defs') |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 2 | include_defs('//bucklets/onos.bucklet') |
| 3 | include_defs('//bucklets/onos_app.bucklet') |
Ray Milkey | e88d69b | 2016-12-16 17:09:13 -0800 | [diff] [blame] | 4 | |
| 5 | def _get_name(): |
| 6 | base_path = get_base_path() |
| 7 | return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator |
| 8 | |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 9 | YANG_TOOLS = [ |
Thomas Vachuska | 315ff1c | 2017-03-28 18:23:00 -0700 | [diff] [blame] | 10 | '//lib:onos-yang-model', |
| 11 | '//lib:onos-yang-compiler-api', |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 12 | '//lib:onos-yang-runtime', |
Thomas Vachuska | 315ff1c | 2017-03-28 18:23:00 -0700 | [diff] [blame] | 13 | '//lib:org.apache.felix.scr.annotations', |
| 14 | '//apps/yang:onos-apps-yang', |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 15 | ] |
| 16 | |
| 17 | def yang_model( |
| 18 | name = None, |
| 19 | app_name = None, |
| 20 | title = 'YANG Model', |
| 21 | url = 'http://onosproject.org', |
| 22 | description = None, |
| 23 | deps = [], |
| 24 | **kwargs |
| 25 | ): |
| 26 | |
| 27 | if name is None: |
| 28 | name = _get_name() |
| 29 | |
| 30 | yang = name + '-yang' |
| 31 | yangSrcs = yang + '#srcs' |
| 32 | schema = name + '-schema' |
| 33 | registrator = name + '-registrator' |
| 34 | |
| 35 | yang_library( |
| 36 | name = yang, |
Thomas Vachuska | d92f6eb | 2017-03-27 13:48:18 -0700 | [diff] [blame] | 37 | srcs = glob(['**/*.yang']), |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 38 | ) |
| 39 | |
| 40 | genrule( |
| 41 | name = schema, |
| 42 | srcs = [ ':' + yangSrcs ], |
| 43 | cmd = '$(location //buck-tools:yang-schema) $OUT $SRCS', |
| 44 | out = 'yang' |
| 45 | ) |
| 46 | |
| 47 | genrule( |
| 48 | name = registrator, |
| 49 | srcs = [ ':' + yangSrcs ], |
| 50 | cmd = '$(location //buck-tools:yang-registrator) $OUT app_name $SRCS', |
| 51 | out = 'YangModelRegistrator.java' |
| 52 | ) |
| 53 | |
| 54 | osgi_jar( |
Thomas Vachuska | d92f6eb | 2017-03-27 13:48:18 -0700 | [diff] [blame] | 55 | name = name, |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 56 | srcs = [ ':' + yangSrcs, ':' + registrator ], |
| 57 | deps = deps + YANG_TOOLS, |
| 58 | resources = [ ':' + schema ], |
| 59 | resources_root = ".", |
| 60 | do_checkstyle = False, |
| 61 | do_javadocs = False, |
| 62 | ) |
| 63 | |
| 64 | onos_app ( |
| 65 | app_name = app_name, |
| 66 | title = title, |
| 67 | category = 'Model', |
| 68 | url = url, |
| 69 | description = description, |
| 70 | required_apps = [ 'org.onosproject.yang' ], |
| 71 | ) |
| 72 | |
| 73 | |
Ray Milkey | e88d69b | 2016-12-16 17:09:13 -0800 | [diff] [blame] | 74 | def yang_osgi_jar( |
| 75 | name = None, |
| 76 | srcs = None, |
| 77 | group_id = ONOS_GROUP_ID, |
| 78 | version = ONOS_VERSION, |
| 79 | deps = [], |
| 80 | visibility = ['PUBLIC'], |
| 81 | license = 'NONE', |
| 82 | **kwargs |
| 83 | ): |
| 84 | |
| 85 | if name is None: |
| 86 | name = _get_name() |
| 87 | |
| 88 | yang_jar = name + '-yang' |
| 89 | bnd_jar = name + '-bnd' |
| 90 | |
| 91 | args = { 'group':group_id, 'artifact':name, 'version':version } |
| 92 | |
| 93 | yang_library( |
| 94 | deps = deps, |
| 95 | name = yang_jar, |
| 96 | srcs = srcs, |
| 97 | visibility = [ ], |
| 98 | ) |
| 99 | |
| 100 | cmd = 'java -jar $(location //lib:bndexe) wrap -o $OUT ' |
| 101 | cmd += '-b %(group)s.%(artifact)s ' % args |
| 102 | cmd += '-v ' + version.replace('-', '.') + ' ' |
| 103 | cmd += '$(location :%s) ' % yang_jar |
| 104 | cmd += ' >/dev/null 2>&1' |
| 105 | |
| 106 | genrule( |
| 107 | name = bnd_jar, |
| 108 | bash = cmd, |
| 109 | out = name + '.jar', |
| 110 | visibility = [], |
| 111 | ) |
| 112 | |
| 113 | prebuilt_jar( |
| 114 | name = name, |
| 115 | binary_jar = ':' + bnd_jar, |
| 116 | maven_coords = '%(group)s:%(artifact)s:%(version)s'%args, |
| 117 | visibility = visibility, |
| 118 | ) |