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