blob: d9a2df0e97201a1ebc8e2232712e158cd74683a9 [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 = [],
25 **kwargs
26 ):
27
28 if name is None:
29 name = _get_name()
30
Thomas Vachuska89534452017-07-28 10:20:12 -070031 if model_id is None:
32 model_id = app_name
33
Thomas Vachuska22f731c2017-03-23 15:00:08 -070034 yang = name + '-yang'
35 yangSrcs = yang + '#srcs'
36 schema = name + '-schema'
37 registrator = name + '-registrator'
38
39 yang_library(
Gaurav Agrawal28920d82017-10-06 17:39:42 +053040 deps = deps,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070041 name = yang,
Yuta HIGUCHIa1c1bbc2017-07-07 16:55:47 -070042 srcs = glob(['src/main/yang/**/*.yang'], excludes=['**/target/**']),
Thomas Vachuska89534452017-07-28 10:20:12 -070043 model_id = model_id
Thomas Vachuska22f731c2017-03-23 15:00:08 -070044 )
45
46 genrule(
47 name = schema,
48 srcs = [ ':' + yangSrcs ],
49 cmd = '$(location //buck-tools:yang-schema) $OUT $SRCS',
50 out = 'yang'
51 )
52
53 genrule(
54 name = registrator,
55 srcs = [ ':' + yangSrcs ],
Thomas Vachuska4d9051e2017-09-06 13:34:05 -070056 cmd = '$(location //buck-tools:yang-registrator) $OUT ' + app_name + ' $SRCS',
Thomas Vachuska22f731c2017-03-23 15:00:08 -070057 out = 'YangModelRegistrator.java'
58 )
59
60 osgi_jar(
Thomas Vachuskad92f6eb2017-03-27 13:48:18 -070061 name = name,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070062 srcs = [ ':' + yangSrcs, ':' + registrator ],
63 deps = deps + YANG_TOOLS,
64 resources = [ ':' + schema ],
65 resources_root = ".",
66 do_checkstyle = False,
67 do_javadocs = False,
68 )
69
70 onos_app (
71 app_name = app_name,
72 title = title,
Thomas Vachuskac98aa2a2017-08-28 10:47:48 -070073 category = 'Models',
Thomas Vachuska22f731c2017-03-23 15:00:08 -070074 url = url,
75 description = description,
76 required_apps = [ 'org.onosproject.yang' ],
77 )
78
Ray Milkeye88d69b2016-12-16 17:09:13 -080079def yang_osgi_jar(
80 name = None,
81 srcs = None,
Thomas Vachuska89534452017-07-28 10:20:12 -070082 model_id = None,
Ray Milkeye88d69b2016-12-16 17:09:13 -080083 group_id = ONOS_GROUP_ID,
84 version = ONOS_VERSION,
85 deps = [],
86 visibility = ['PUBLIC'],
87 license = 'NONE',
88 **kwargs
89 ):
90
91 if name is None:
92 name = _get_name()
93
Thomas Vachuska89534452017-07-28 10:20:12 -070094 if model_id is None:
95 model_id = name
Ray Milkeye88d69b2016-12-16 17:09:13 -080096 yang_jar = name + '-yang'
97 bnd_jar = name + '-bnd'
98
99 args = { 'group':group_id, 'artifact':name, 'version':version }
100
101 yang_library(
102 deps = deps,
103 name = yang_jar,
104 srcs = srcs,
Thomas Vachuska89534452017-07-28 10:20:12 -0700105 model_id = model_id,
Ray Milkeye88d69b2016-12-16 17:09:13 -0800106 visibility = [ ],
107 )
108
109 cmd = 'java -jar $(location //lib:bndexe) wrap -o $OUT '
110 cmd += '-b %(group)s.%(artifact)s ' % args
111 cmd += '-v ' + version.replace('-', '.') + ' '
112 cmd += '$(location :%s) ' % yang_jar
113 cmd += ' >/dev/null 2>&1'
114
115 genrule(
116 name = bnd_jar,
117 bash = cmd,
118 out = name + '.jar',
119 visibility = [],
120 )
121
122 prebuilt_jar(
123 name = name,
124 binary_jar = ':' + bnd_jar,
125 maven_coords = '%(group)s:%(artifact)s:%(version)s'%args,
126 visibility = visibility,
127 )