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