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( |
Gaurav Agrawal | 28920d8 | 2017-10-06 17:39:42 +0530 | [diff] [blame^] | 40 | deps = deps, |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 41 | name = yang, |
Yuta HIGUCHI | a1c1bbc | 2017-07-07 16:55:47 -0700 | [diff] [blame] | 42 | srcs = glob(['src/main/yang/**/*.yang'], excludes=['**/target/**']), |
Thomas Vachuska | 8953445 | 2017-07-28 10:20:12 -0700 | [diff] [blame] | 43 | model_id = model_id |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 44 | ) |
| 45 | |
| 46 | genrule( |
| 47 | name = schema, |
| 48 | srcs = [ ':' + yangSrcs ], |
| 49 | cmd = '$(location //buck-tools:yang-schema) $OUT $SRCS', |
| 50 | out = 'yang' |
| 51 | ) |
| 52 | |
| 53 | genrule( |
| 54 | name = registrator, |
| 55 | srcs = [ ':' + yangSrcs ], |
Thomas Vachuska | 4d9051e | 2017-09-06 13:34:05 -0700 | [diff] [blame] | 56 | cmd = '$(location //buck-tools:yang-registrator) $OUT ' + app_name + ' $SRCS', |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 57 | out = 'YangModelRegistrator.java' |
| 58 | ) |
| 59 | |
| 60 | osgi_jar( |
Thomas Vachuska | d92f6eb | 2017-03-27 13:48:18 -0700 | [diff] [blame] | 61 | name = name, |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 62 | srcs = [ ':' + yangSrcs, ':' + registrator ], |
| 63 | deps = deps + YANG_TOOLS, |
| 64 | resources = [ ':' + schema ], |
| 65 | resources_root = ".", |
| 66 | do_checkstyle = False, |
| 67 | do_javadocs = False, |
| 68 | ) |
| 69 | |
| 70 | onos_app ( |
| 71 | app_name = app_name, |
| 72 | title = title, |
Thomas Vachuska | c98aa2a | 2017-08-28 10:47:48 -0700 | [diff] [blame] | 73 | category = 'Models', |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 74 | url = url, |
| 75 | description = description, |
| 76 | required_apps = [ 'org.onosproject.yang' ], |
| 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 | ) |