blob: 7769fe4942040aeee1c8a0c23370afaa63f67807 [file] [log] [blame]
Ray Milkeye88d69b2016-12-16 17:09:13 -08001include_defs('//onos.defs')
Thomas Vachuska22f731c2017-03-23 15:00:08 -07002include_defs('//bucklets/onos.bucklet')
3include_defs('//bucklets/onos_app.bucklet')
Ray Milkeye88d69b2016-12-16 17:09:13 -08004
5def _get_name():
6 base_path = get_base_path()
7 return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
8
Thomas Vachuska22f731c2017-03-23 15:00:08 -07009YANG_TOOLS = [
Thomas Vachuska315ff1c2017-03-28 18:23:00 -070010 '//lib:onos-yang-model',
11 '//lib:onos-yang-compiler-api',
Thomas Vachuska22f731c2017-03-23 15:00:08 -070012 '//lib:onos-yang-runtime',
Thomas Vachuska315ff1c2017-03-28 18:23:00 -070013 '//lib:org.apache.felix.scr.annotations',
14 '//apps/yang:onos-apps-yang',
Thomas Vachuska22f731c2017-03-23 15:00:08 -070015]
16
17def yang_model(
18 name = None,
19 app_name = None,
Thomas Vachuska89534452017-07-28 10:20:12 -070020 model_id = None,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070021 title = 'YANG Model',
22 url = 'http://onosproject.org',
23 description = None,
24 deps = [],
Gaurav Agrawalf2a8c2b2017-10-06 20:45:11 +053025 required_apps = [],
Thomas Vachuska22f731c2017-03-23 15:00:08 -070026 **kwargs
27 ):
28
29 if name is None:
30 name = _get_name()
31
Thomas Vachuska89534452017-07-28 10:20:12 -070032 if model_id is None:
33 model_id = app_name
34
Thomas Vachuska22f731c2017-03-23 15:00:08 -070035 yang = name + '-yang'
36 yangSrcs = yang + '#srcs'
37 schema = name + '-schema'
38 registrator = name + '-registrator'
39
40 yang_library(
Gaurav Agrawal28920d82017-10-06 17:39:42 +053041 deps = deps,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070042 name = yang,
Yuta HIGUCHIa1c1bbc2017-07-07 16:55:47 -070043 srcs = glob(['src/main/yang/**/*.yang'], excludes=['**/target/**']),
Thomas Vachuska89534452017-07-28 10:20:12 -070044 model_id = model_id
Thomas Vachuska22f731c2017-03-23 15:00:08 -070045 )
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 Vachuska4d9051e2017-09-06 13:34:05 -070057 cmd = '$(location //buck-tools:yang-registrator) $OUT ' + app_name + ' $SRCS',
Thomas Vachuska22f731c2017-03-23 15:00:08 -070058 out = 'YangModelRegistrator.java'
59 )
60
61 osgi_jar(
Thomas Vachuskad92f6eb2017-03-27 13:48:18 -070062 name = name,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070063 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 Vachuskac98aa2a2017-08-28 10:47:48 -070074 category = 'Models',
Thomas Vachuska22f731c2017-03-23 15:00:08 -070075 url = url,
76 description = description,
Gaurav Agrawalf2a8c2b2017-10-06 20:45:11 +053077 required_apps = required_apps + [ 'org.onosproject.yang' ],
Thomas Vachuska22f731c2017-03-23 15:00:08 -070078 )
79
Ray Milkeye88d69b2016-12-16 17:09:13 -080080def yang_osgi_jar(
81 name = None,
82 srcs = None,
Thomas Vachuska89534452017-07-28 10:20:12 -070083 model_id = None,
Ray Milkeye88d69b2016-12-16 17:09:13 -080084 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 Vachuska89534452017-07-28 10:20:12 -070095 if model_id is None:
96 model_id = name
Ray Milkeye88d69b2016-12-16 17:09:13 -080097 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 Vachuska89534452017-07-28 10:20:12 -0700106 model_id = model_id,
Ray Milkeye88d69b2016-12-16 17:09:13 -0800107 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 )