blob: 91e31b17e4639bbda5a958d8cad9d8381a3ca435 [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,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070027 **kwargs
28 ):
29
30 if name is None:
31 name = _get_name()
32
Thomas Vachuska89534452017-07-28 10:20:12 -070033 if model_id is None:
34 model_id = app_name
35
Thomas Vachuska22f731c2017-03-23 15:00:08 -070036 yang = name + '-yang'
37 yangSrcs = yang + '#srcs'
38 schema = name + '-schema'
39 registrator = name + '-registrator'
40
41 yang_library(
Gaurav Agrawal28920d82017-10-06 17:39:42 +053042 deps = deps,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070043 name = yang,
Yuta HIGUCHIa1c1bbc2017-07-07 16:55:47 -070044 srcs = glob(['src/main/yang/**/*.yang'], excludes=['**/target/**']),
Thomas Vachuska89534452017-07-28 10:20:12 -070045 model_id = model_id
Thomas Vachuska22f731c2017-03-23 15:00:08 -070046 )
47
48 genrule(
49 name = schema,
50 srcs = [ ':' + yangSrcs ],
51 cmd = '$(location //buck-tools:yang-schema) $OUT $SRCS',
52 out = 'yang'
53 )
54
Thomas Vachuska803278e2017-10-06 11:11:58 -070055 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 Vachuska22f731c2017-03-23 15:00:08 -070081
82 onos_app (
83 app_name = app_name,
84 title = title,
Thomas Vachuskac98aa2a2017-08-28 10:47:48 -070085 category = 'Models',
Thomas Vachuska22f731c2017-03-23 15:00:08 -070086 url = url,
87 description = description,
Gaurav Agrawalf2a8c2b2017-10-06 20:45:11 +053088 required_apps = required_apps + [ 'org.onosproject.yang' ],
Thomas Vachuska22f731c2017-03-23 15:00:08 -070089 )
90
Ray Milkeye88d69b2016-12-16 17:09:13 -080091def yang_osgi_jar(
92 name = None,
93 srcs = None,
Thomas Vachuska89534452017-07-28 10:20:12 -070094 model_id = None,
Ray Milkeye88d69b2016-12-16 17:09:13 -080095 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 Vachuska89534452017-07-28 10:20:12 -0700106 if model_id is None:
107 model_id = name
Ray Milkeye88d69b2016-12-16 17:09:13 -0800108 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 Vachuska89534452017-07-28 10:20:12 -0700117 model_id = model_id,
Ray Milkeye88d69b2016-12-16 17:09:13 -0800118 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 )