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 = [], |
Thomas Vachuska | 82c79d9 | 2017-10-06 11:11:58 -0700 | [diff] [blame^] | 25 | required_apps = [], |
| 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( |
| 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 | |
Thomas Vachuska | 82c79d9 | 2017-10-06 11:11:58 -0700 | [diff] [blame^] | 54 | if custom_registrator: |
| 55 | osgi_jar( |
| 56 | name = name, |
| 57 | srcs = [ ':' + yangSrcs ] + glob(['src/main/java/**/*.java']), |
| 58 | deps = deps + YANG_TOOLS, |
| 59 | resources = [ ':' + schema ], |
| 60 | resources_root = ".", |
| 61 | do_checkstyle = False, |
| 62 | do_javadocs = False, |
| 63 | ) |
| 64 | else: |
| 65 | genrule( |
| 66 | name = registrator, |
| 67 | srcs = [ ':' + yangSrcs ], |
| 68 | cmd = '$(location //buck-tools:yang-registrator) $OUT ' + app_name + ' $SRCS', |
| 69 | out = 'YangModelRegistrator.java' |
| 70 | ) |
| 71 | osgi_jar( |
| 72 | name = name, |
| 73 | srcs = [ ':' + yangSrcs, ':' + registrator ], |
| 74 | deps = deps + YANG_TOOLS, |
| 75 | resources = [ ':' + schema ], |
| 76 | resources_root = ".", |
| 77 | do_checkstyle = False, |
| 78 | do_javadocs = False, |
| 79 | ) |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 80 | |
| 81 | onos_app ( |
| 82 | app_name = app_name, |
| 83 | title = title, |
Thomas Vachuska | cc7d2a3 | 2017-08-28 10:47:48 -0700 | [diff] [blame] | 84 | category = 'Models', |
Thomas Vachuska | 22f731c | 2017-03-23 15:00:08 -0700 | [diff] [blame] | 85 | url = url, |
| 86 | description = description, |
| 87 | required_apps = [ 'org.onosproject.yang' ], |
| 88 | ) |
| 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 | ) |