blob: 86a613bb6afa0031544b2bed7c84408ec69b428d [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 = [],
Thomas Vachuska82c79d92017-10-06 11:11:58 -070025 required_apps = [],
26 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(
42 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
Thomas Vachuska82c79d92017-10-06 11:11:58 -070054 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 Vachuska22f731c2017-03-23 15:00:08 -070080
81 onos_app (
82 app_name = app_name,
83 title = title,
Thomas Vachuskacc7d2a32017-08-28 10:47:48 -070084 category = 'Models',
Thomas Vachuska22f731c2017-03-23 15:00:08 -070085 url = url,
86 description = description,
87 required_apps = [ 'org.onosproject.yang' ],
88 )
89
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 )