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