blob: 53ab5efd3d4d56d60a98adb57bda313490b518a9 [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'
Carmelo Casconeb1936bd2017-12-12 14:42:27 -08006DEFAULT_GRPC_PLUGIN_VERSION = '1.3.1'
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 Cascone569d4ad2017-07-10 16:09:00 -040012 "protoc-3.0.2-linux-x86_64.zip":"779ed606f524eb2c8c116b0fce7a3bc6507769e7",
13 "protoc-3.0.2-osx-x86_64.zip":"f71d97affca4ffe32747772539c0bcbf76c9dc9b",
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040014 "protoc-3.2.0-linux-x86_64.zip":"f418d246d183a534d9bd749e614f639a55f6829b",
Carmelo Cascone569d4ad2017-07-10 16:09:00 -040015 "protoc-3.2.0-osx-x86_64.zip":"81f4fac3200ba2cb12a98df0a9ee4d1c584e9210",
Aaron Kruglikove630fb12017-04-24 13:05:26 -070016}
17
18GRPC_JAVA_SHA1S = {
Carmelo Casconeb1936bd2017-12-12 14:42:27 -080019 "protoc-gen-grpc-java-1.3.1-linux-x86_64.exe":"9598b00ad0f41a6bd6aeb01f647903dbc62792cc",
20 "protoc-gen-grpc-java-1.3.1-osx-x86_64.exe":"f4eccb96524b8b9f152024890550d9b88398b8cd"
Aaron Kruglikove630fb12017-04-24 13:05:26 -070021}
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
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040032def fetch_protoc(
33 version
Aaron Kruglikove630fb12017-04-24 13:05:26 -070034 ):
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040035 file_name = "protoc-%s-%s.zip" % (version, get_system_arch())
Aaron Kruglikove630fb12017-04-24 13:05:26 -070036 if file_name not in PROTOC_SHA1S:
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040037 raise Exception('Cannot download %s, architecture or version not supported' % file_name)
Aaron Kruglikove630fb12017-04-24 13:05:26 -070038 remote_file(
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040039 name = 'protoc-release-' + version,
40 url = PROTOC_RELEASE_BASE_URL + '/v' + version + '/' + file_name,
Aaron Kruglikove630fb12017-04-24 13:05:26 -070041 sha1 = PROTOC_SHA1S[file_name],
42 )
43 genrule(
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040044 name = 'protoc-exe-' + version,
45 bash = 'jar xf $(location :protoc-release-' + version + ') bin/protoc && ' +
46 'mv bin/protoc $OUT && ' +
47 'chmod +x $OUT',
48 out = 'protoc.exe',
Aaron Kruglikove630fb12017-04-24 13:05:26 -070049 executable = True,
50 visibility = [ "PUBLIC" ],
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040051 )
52 genrule(
53 name = 'protoc-lib-' + version,
54 bash = 'jar xf $(location :protoc-release-' + version + ') include && mv include $OUT',
55 out = 'include',
56 visibility = [ "PUBLIC" ],
Aaron Kruglikove630fb12017-04-24 13:05:26 -070057 )
58
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040059def fetch_grpc_plugin(
60 version
61):
62 file_name = "protoc-gen-grpc-java-%s-%s.exe" % (version, get_system_arch())
Aaron Kruglikove630fb12017-04-24 13:05:26 -070063 if file_name not in GRPC_JAVA_SHA1S:
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040064 raise Exception('Cannot download %s, architecture or version not supported' % file_name)
Aaron Kruglikove630fb12017-04-24 13:05:26 -070065 remote_file(
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040066 name = 'grpc-plugin-binary-' + version,
67 url = GRPC_PLUGIN_BASE_URL + '/' + version + '/' + file_name,
Aaron Kruglikove630fb12017-04-24 13:05:26 -070068 sha1 = GRPC_JAVA_SHA1S[file_name],
69 )
70 genrule(
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040071 name = 'grpc-plugin-exe-' + version,
72 bash = 'cp $(location :grpc-plugin-binary-' + version + ') $OUT && chmod +x $OUT',
Aaron Kruglikove630fb12017-04-24 13:05:26 -070073 executable = True,
74 visibility = [ "PUBLIC" ],
75 out = 'grpc-plugin.exe',
76 )
77
78def _get_name():
79 base_path = get_base_path()
80 return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
81
82def grpc_jar(
83 name = None,
84 deps = [],
85 #NOTE: if targeting a directory also built with maven this path MUST end in
Aaron Kruglikov9f95f992017-06-23 14:15:25 +090086 # /proto because maven plugin interprets imports relative to the proto
87 # directory and BUCK interprets imports relative to the last directory
88 # listed in the first listed proto_path which contains the specified
89 # file
Aaron Kruglikove630fb12017-04-24 13:05:26 -070090 proto_paths = [],
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040091 srcs = [],
92 src_string = '', # Useful to build proto files external to the ONOS sources, using BUCK's environment variables.
Yuta HIGUCHIb1aec662017-11-15 14:20:13 -080093 proto_match_patterns = [ "src/main/proto/**/*.proto" ],
Carmelo Cascone65f98ff2017-06-21 02:04:55 -040094 protoc_version = DEFAULT_PROTOC_VERSION,
95 plugin_version = DEFAULT_GRPC_PLUGIN_VERSION,
96 include_std_lib = False,
Aaron Kruglikove630fb12017-04-24 13:05:26 -070097 **kwargs
98 ):
99
100 #Get the correct name for the protoc compilation call
101 if name is None:
102 name = _get_name()
103
Carmelo Cascone65f98ff2017-06-21 02:04:55 -0400104 # Create the string for the proto_path arguments (order matters, similar to classpath)
105
106 if include_std_lib:
107 # Add protoc standard lib to the includes
108 proto_paths = ['$(location //incubator/protobuf-dependencies:protoc-lib-' + protoc_version + ')'] + proto_paths
109
Aaron Kruglikove630fb12017-04-24 13:05:26 -0700110 if len(proto_paths) != 0:
111 proto_paths_string = "-I=" + reduce(lambda a,b: a +" -I=" + b, proto_paths)
112 else:
113 proto_paths_string = ""
114 protoc = name + '-protoc'
115
116 genrule(
117 name = protoc,
118 srcs = glob(proto_match_patterns),
119 out = 'grpc.src.zip',
120 cmd = '$(location //buck-tools:grpc) $OUT '
121 + '\"' + proto_paths_string + '\" '
Carmelo Cascone65f98ff2017-06-21 02:04:55 -0400122 + '$(location //incubator/protobuf-dependencies:protoc-exe-'+ protoc_version + ') '
123 + '$(location //incubator/grpc-dependencies:grpc-plugin-exe-' + plugin_version + ') '
124 + '$SRCS' + src_string,
Aaron Kruglikove630fb12017-04-24 13:05:26 -0700125 )
126
Aaron Kruglikov9f95f992017-06-23 14:15:25 +0900127 osgi_jar(
Aaron Kruglikove630fb12017-04-24 13:05:26 -0700128 name = name,
129 srcs = [ ':' + protoc ],
130 deps = deps + [ ':' + protoc ],
131 do_javadocs = False,
132 do_checkstyle = False,
133 **kwargs
134 )