blob: 31ce16993574472294a8e2877c9b3297632c63f0 [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(
40 name = yang,
Yuta HIGUCHIa1c1bbc2017-07-07 16:55:47 -070041 srcs = glob(['src/main/yang/**/*.yang'], excludes=['**/target/**']),
Thomas Vachuska89534452017-07-28 10:20:12 -070042 model_id = model_id
Thomas Vachuska22f731c2017-03-23 15:00:08 -070043 )
44
45 genrule(
46 name = schema,
47 srcs = [ ':' + yangSrcs ],
48 cmd = '$(location //buck-tools:yang-schema) $OUT $SRCS',
49 out = 'yang'
50 )
51
52 genrule(
53 name = registrator,
54 srcs = [ ':' + yangSrcs ],
55 cmd = '$(location //buck-tools:yang-registrator) $OUT app_name $SRCS',
56 out = 'YangModelRegistrator.java'
57 )
58
59 osgi_jar(
Thomas Vachuskad92f6eb2017-03-27 13:48:18 -070060 name = name,
Thomas Vachuska22f731c2017-03-23 15:00:08 -070061 srcs = [ ':' + yangSrcs, ':' + registrator ],
62 deps = deps + YANG_TOOLS,
63 resources = [ ':' + schema ],
64 resources_root = ".",
65 do_checkstyle = False,
66 do_javadocs = False,
67 )
68
69 onos_app (
70 app_name = app_name,
71 title = title,
72 category = 'Model',
73 url = url,
74 description = description,
75 required_apps = [ 'org.onosproject.yang' ],
76 )
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 )