blob: 8d5d83fabef190606ff6725ae0cce7cddbc14d63 [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 Vachuska803278e2017-10-06 11:11:58 -070026 custom_registrator = False,
Yuta HIGUCHIf9361912018-05-09 10:51:46 -070027 yang_src = None,
28 custom_src = None,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070029 **kwargs
30 ):
31
32 if name is None:
33 name = _get_name()
34
Thomas Vachuska89534452017-07-28 10:20:12 -070035 if model_id is None:
36 model_id = app_name
37
Yuta HIGUCHIf9361912018-05-09 10:51:46 -070038 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 Vachuska22f731c2017-03-23 15:00:08 -070044 yang = name + '-yang'
45 yangSrcs = yang + '#srcs'
46 schema = name + '-schema'
47 registrator = name + '-registrator'
48
49 yang_library(
Gaurav Agrawal28920d82017-10-06 17:39:42 +053050 deps = deps,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070051 name = yang,
Yuta HIGUCHIf9361912018-05-09 10:51:46 -070052 srcs = yang_src,
Thomas Vachuska89534452017-07-28 10:20:12 -070053 model_id = model_id
Thomas Vachuska22f731c2017-03-23 15:00:08 -070054 )
55
56 genrule(
57 name = schema,
58 srcs = [ ':' + yangSrcs ],
59 cmd = '$(location //buck-tools:yang-schema) $OUT $SRCS',
60 out = 'yang'
61 )
62
Thomas Vachuska803278e2017-10-06 11:11:58 -070063 if custom_registrator:
64 osgi_jar(
65 name = name,
Yuta HIGUCHIf9361912018-05-09 10:51:46 -070066 srcs = [ ':' + yangSrcs ] + custom_src,
Thomas Vachuska803278e2017-10-06 11:11:58 -070067 deps = deps + YANG_TOOLS,
68 resources = [ ':' + schema ],
69 resources_root = ".",
Yuta HIGUCHIe7e71a82018-05-18 16:36:43 -070070 do_checkstyle = True,
Thomas Vachuska803278e2017-10-06 11:11:58 -070071 do_javadocs = False,
72 )
73 else:
74 genrule(
75 name = registrator,
76 srcs = [ ':' + yangSrcs ],
Yuta HIGUCHIf9361912018-05-09 10:51:46 -070077 cmd = '$(location //buck-tools:yang-registrator) $OUT ' + app_name.replace('-', '_') + ' $SRCS',
Thomas Vachuska803278e2017-10-06 11:11:58 -070078 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 Vachuska22f731c2017-03-23 15:00:08 -070089
90 onos_app (
Yuta HIGUCHIf9361912018-05-09 10:51:46 -070091 name = name,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070092 app_name = app_name,
93 title = title,
Thomas Vachuskac98aa2a2017-08-28 10:47:48 -070094 category = 'Models',
Thomas Vachuska22f731c2017-03-23 15:00:08 -070095 url = url,
96 description = description,
Gaurav Agrawalf2a8c2b2017-10-06 20:45:11 +053097 required_apps = required_apps + [ 'org.onosproject.yang' ],
Thomas Vachuska22f731c2017-03-23 15:00:08 -070098 )
99
Ray Milkeye88d69b2016-12-16 17:09:13 -0800100def yang_osgi_jar(
101 name = None,
102 srcs = None,
Thomas Vachuska89534452017-07-28 10:20:12 -0700103 model_id = None,
Ray Milkeye88d69b2016-12-16 17:09:13 -0800104 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 Vachuska89534452017-07-28 10:20:12 -0700115 if model_id is None:
116 model_id = name
Ray Milkeye88d69b2016-12-16 17:09:13 -0800117 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 Vachuska89534452017-07-28 10:20:12 -0700126 model_id = model_id,
Ray Milkeye88d69b2016-12-16 17:09:13 -0800127 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 )