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