blob: 276586e13eb30b3a39c3b9ac87df3d2c97b16cd6 [file] [log] [blame]
Aaron Kruglikove630fb12017-04-24 13:05:26 -07001include_defs('//onos.defs')
2include_defs('//bucklets/onos.bucklet')
3
4
5PROTOC_VERSION = '3.2.0'
6GRPC_PLUGIN_VERSION = '1.3.0'
7
8PROTOC_EXECUTABLE_BASE_URL = "https://repo1.maven.org/maven2/com/google/protobuf/protoc"
9GRPC_PLUGIN_BASE_URL = "https://repo1.maven.org/maven2/io/grpc/protoc-gen-grpc-java"
10
11PROTOC_SHA1S = {
12 "protoc-3.3.0-osx-x86_64.exe":"3070e439f9557bb72fb04df631f29d7556c9029c",
13 "protoc-3.3.0-linux-x86_64.exe":"e6a95fc7477c602cc402ed976d3edbd82c841879",
14 "protoc-3.2.0-linux-x86_64.exe":"086893ffdc1023e503ccd0ee522ca1e6046b12a7",
15 "protoc-3.2.0-osx-x86_64.exe":"87f532ef51bb314d2c5d2ba7842b39cbbdb60323"
16}
17
18GRPC_JAVA_SHA1S = {
19 "protoc-gen-grpc-java-1.3.0-linux-x86_64.exe":"44a0fa3e6074852ea84f93d258233b3f4f6d9e53",
20 "protoc-gen-grpc-java-1.3.0-osx-x86_64.exe":"61a1b81b9f0af7d0900c314a4201972b52fb5f12"
21}
22
23#Returns the string for the OS and architecture of the system of the form 'OS-ARCH'
24def get_system_arch():
25 import platform
26 os = platform.system().lower()
27 arch = platform.machine()
28 if os == "darwin":
29 os = "osx"
30 return "%s-%s" % ( os, arch)
31
32def fetch_protoc_binary(
33 protoc_version = PROTOC_VERSION
34 ):
35 file_name = "protoc-%s-%s.exe" % (protoc_version, get_system_arch())
36 if file_name not in PROTOC_SHA1S:
37 raise Exception('Cannot download %s, architecture not supported' % file_name)
38 remote_file(
39 name = 'fetch-protoc-binary-' + protoc_version,
40 out = 'protoc-binary',
41 url = PROTOC_EXECUTABLE_BASE_URL + '/' + protoc_version + '/' + file_name,
42 sha1 = PROTOC_SHA1S[file_name],
43 )
44 genrule(
45 name = 'prepare-protoc-executable-' + protoc_version,
46 srcs = [ ':fetch-protoc-binary-' + protoc_version ],
47 bash = 'cp $(location :fetch-protoc-binary-' + protoc_version +') $OUT && chmod +x $OUT',
48 executable = True,
49 visibility = [ "PUBLIC" ],
50 out = 'protoc.exe',
51 )
52
53def fetch_grpc_plugin_binary(
54 grpc_plugin_version = GRPC_PLUGIN_VERSION
55):
56 file_name = "protoc-gen-grpc-java-%s-%s.exe" % (grpc_plugin_version, get_system_arch())
57 if file_name not in GRPC_JAVA_SHA1S:
58 raise Exception('Cannot download %s, architecture not supported' % file_name)
59 remote_file(
60 name = 'fetch-grpc-plugin-binary-' + grpc_plugin_version,
61 out = 'grpc-plugin-binary',
62 url = GRPC_PLUGIN_BASE_URL + '/' + grpc_plugin_version + '/' + file_name,
63 sha1 = GRPC_JAVA_SHA1S[file_name],
64 )
65 genrule(
66 name = 'prepare-grpc-plugin-executable-' + grpc_plugin_version,
67 srcs = [ ':fetch-grpc-plugin-binary-' + grpc_plugin_version ],
68 bash = 'cp $(location :fetch-grpc-plugin-binary-' + grpc_plugin_version + ') $OUT && chmod +x $OUT',
69 executable = True,
70 visibility = [ "PUBLIC" ],
71 out = 'grpc-plugin.exe',
72 )
73
74def _get_name():
75 base_path = get_base_path()
76 return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
77
78def grpc_jar(
79 name = None,
80 deps = [],
81 #NOTE: if targeting a directory also built with maven this path MUST end in
82 # /proto because maven plugin interprets imports relative to the proto
83 # directory and BUCK interprets imports relative to the last directory
84 # listed in the first listed proto_path which contains the specified
85 # file
86 proto_paths = [],
87 proto_match_patterns = [ "**/proto/**/*.proto" ],
88 protoc_version = PROTOC_VERSION,
89 plugin_version = GRPC_PLUGIN_VERSION,
90 **kwargs
91 ):
92
93 #Get the correct name for the protoc compilation call
94 if name is None:
95 name = _get_name()
96
97 #Create the string for the proto_path arguments (order matters, similar to classpath)
98 if len(proto_paths) != 0:
99 proto_paths_string = "-I=" + reduce(lambda a,b: a +" -I=" + b, proto_paths)
100 else:
101 proto_paths_string = ""
102 protoc = name + '-protoc'
103
104 genrule(
105 name = protoc,
106 srcs = glob(proto_match_patterns),
107 out = 'grpc.src.zip',
108 cmd = '$(location //buck-tools:grpc) $OUT '
109 + '\"' + proto_paths_string + '\" '
110 + '$(location //incubator/protobuf-dependencies:prepare-protoc-executable-'+ protoc_version + ') '
111 + '$(location //incubator/grpc-dependencies:prepare-grpc-plugin-executable-' + plugin_version + ') '
112 + '$SRCS',
113 )
114
115 osgi_jar_with_tests(
116 name = name,
117 srcs = [ ':' + protoc ],
118 deps = deps + [ ':' + protoc ],
119 do_javadocs = False,
120 do_checkstyle = False,
121 **kwargs
122 )