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