blob: f8fe5798e68107e450c968a2eb3bdd3ea1413b21 [file] [log] [blame]
Aaron Kruglikove630fb12017-04-24 13:05:26 -07001include_defs('//onos.defs')
2include_defs('//bucklets/onos.bucklet')
3
4
Carmelo Cascone65f98ff2017-06-21 02:04:55 -04005DEFAULT_PROTOC_VERSION = '3.2.0'
6DEFAULT_GRPC_PLUGIN_VERSION = '1.3.0'
Aaron Kruglikove630fb12017-04-24 13:05:26 -07007
Carmelo Cascone65f98ff2017-06-21 02:04:55 -04008PROTOC_RELEASE_BASE_URL = "https://github.com/google/protobuf/releases/download"
Aaron Kruglikove630fb12017-04-24 13:05:26 -07009GRPC_PLUGIN_BASE_URL = "https://repo1.maven.org/maven2/io/grpc/protoc-gen-grpc-java"
10
11PROTOC_SHA1S = {
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040012 "protoc-3.2.0-linux-x86_64.zip":"f418d246d183a534d9bd749e614f639a55f6829b",
13 "protoc-3.2.0-osx-x86_64.zip":"81f4fac3200ba2cb12a98df0a9ee4d1c584e9210"
Aaron Kruglikove630fb12017-04-24 13:05:26 -070014}
15
16GRPC_JAVA_SHA1S = {
17 "protoc-gen-grpc-java-1.3.0-linux-x86_64.exe":"44a0fa3e6074852ea84f93d258233b3f4f6d9e53",
18 "protoc-gen-grpc-java-1.3.0-osx-x86_64.exe":"61a1b81b9f0af7d0900c314a4201972b52fb5f12"
19}
20
21#Returns the string for the OS and architecture of the system of the form 'OS-ARCH'
22def get_system_arch():
23 import platform
24 os = platform.system().lower()
25 arch = platform.machine()
26 if os == "darwin":
27 os = "osx"
28 return "%s-%s" % ( os, arch)
29
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040030def fetch_protoc(
31 version
Aaron Kruglikove630fb12017-04-24 13:05:26 -070032 ):
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040033 file_name = "protoc-%s-%s.zip" % (version, get_system_arch())
Aaron Kruglikove630fb12017-04-24 13:05:26 -070034 if file_name not in PROTOC_SHA1S:
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040035 raise Exception('Cannot download %s, architecture or version not supported' % file_name)
Aaron Kruglikove630fb12017-04-24 13:05:26 -070036 remote_file(
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040037 name = 'protoc-release-' + version,
38 url = PROTOC_RELEASE_BASE_URL + '/v' + version + '/' + file_name,
Aaron Kruglikove630fb12017-04-24 13:05:26 -070039 sha1 = PROTOC_SHA1S[file_name],
40 )
41 genrule(
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040042 name = 'protoc-exe-' + version,
43 bash = 'jar xf $(location :protoc-release-' + version + ') bin/protoc && ' +
44 'mv bin/protoc $OUT && ' +
45 'chmod +x $OUT',
46 out = 'protoc.exe',
Aaron Kruglikove630fb12017-04-24 13:05:26 -070047 executable = True,
48 visibility = [ "PUBLIC" ],
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040049 )
50 genrule(
51 name = 'protoc-lib-' + version,
52 bash = 'jar xf $(location :protoc-release-' + version + ') include && mv include $OUT',
53 out = 'include',
54 visibility = [ "PUBLIC" ],
Aaron Kruglikove630fb12017-04-24 13:05:26 -070055 )
56
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040057def fetch_grpc_plugin(
58 version
59):
60 file_name = "protoc-gen-grpc-java-%s-%s.exe" % (version, get_system_arch())
Aaron Kruglikove630fb12017-04-24 13:05:26 -070061 if file_name not in GRPC_JAVA_SHA1S:
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040062 raise Exception('Cannot download %s, architecture or version not supported' % file_name)
Aaron Kruglikove630fb12017-04-24 13:05:26 -070063 remote_file(
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040064 name = 'grpc-plugin-binary-' + version,
65 url = GRPC_PLUGIN_BASE_URL + '/' + version + '/' + file_name,
Aaron Kruglikove630fb12017-04-24 13:05:26 -070066 sha1 = GRPC_JAVA_SHA1S[file_name],
67 )
68 genrule(
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040069 name = 'grpc-plugin-exe-' + version,
70 bash = 'cp $(location :grpc-plugin-binary-' + version + ') $OUT && chmod +x $OUT',
Aaron Kruglikove630fb12017-04-24 13:05:26 -070071 executable = True,
72 visibility = [ "PUBLIC" ],
73 out = 'grpc-plugin.exe',
74 )
75
76def _get_name():
77 base_path = get_base_path()
78 return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
79
80def grpc_jar(
81 name = None,
82 deps = [],
83 #NOTE: if targeting a directory also built with maven this path MUST end in
Aaron Kruglikov9f95f992017-06-23 14:15:25 +090084 # /proto because maven plugin interprets imports relative to the proto
85 # directory and BUCK interprets imports relative to the last directory
86 # listed in the first listed proto_path which contains the specified
87 # file
Aaron Kruglikove630fb12017-04-24 13:05:26 -070088 proto_paths = [],
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040089 srcs = [],
90 src_string = '', # Useful to build proto files external to the ONOS sources, using BUCK's environment variables.
Aaron Kruglikove630fb12017-04-24 13:05:26 -070091 proto_match_patterns = [ "**/proto/**/*.proto" ],
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040092 protoc_version = DEFAULT_PROTOC_VERSION,
93 plugin_version = DEFAULT_GRPC_PLUGIN_VERSION,
94 include_std_lib = False,
Aaron Kruglikove630fb12017-04-24 13:05:26 -070095 **kwargs
96 ):
97
98 #Get the correct name for the protoc compilation call
99 if name is None:
100 name = _get_name()
101
Carmelo Cascone65f98ff2017-06-21 02:04:55 -0400102 # Create the string for the proto_path arguments (order matters, similar to classpath)
103
104 if include_std_lib:
105 # Add protoc standard lib to the includes
106 proto_paths = ['$(location //incubator/protobuf-dependencies:protoc-lib-' + protoc_version + ')'] + proto_paths
107
Aaron Kruglikove630fb12017-04-24 13:05:26 -0700108 if len(proto_paths) != 0:
109 proto_paths_string = "-I=" + reduce(lambda a,b: a +" -I=" + b, proto_paths)
110 else:
111 proto_paths_string = ""
112 protoc = name + '-protoc'
113
114 genrule(
115 name = protoc,
116 srcs = glob(proto_match_patterns),
117 out = 'grpc.src.zip',
118 cmd = '$(location //buck-tools:grpc) $OUT '
119 + '\"' + proto_paths_string + '\" '
Carmelo Cascone65f98ff2017-06-21 02:04:55 -0400120 + '$(location //incubator/protobuf-dependencies:protoc-exe-'+ protoc_version + ') '
121 + '$(location //incubator/grpc-dependencies:grpc-plugin-exe-' + plugin_version + ') '
122 + '$SRCS' + src_string,
Aaron Kruglikove630fb12017-04-24 13:05:26 -0700123 )
124
Aaron Kruglikov9f95f992017-06-23 14:15:25 +0900125 osgi_jar(
Aaron Kruglikove630fb12017-04-24 13:05:26 -0700126 name = name,
127 srcs = [ ':' + protoc ],
128 deps = deps + [ ':' + protoc ],
129 do_javadocs = False,
130 do_checkstyle = False,
131 **kwargs
132 )