| include_defs('//onos.defs') |
| include_defs('//bucklets/onos.bucklet') |
| |
| |
| DEFAULT_PROTOC_VERSION = '3.2.0' |
| DEFAULT_GRPC_PLUGIN_VERSION = '1.3.0' |
| |
| PROTOC_RELEASE_BASE_URL = "https://github.com/google/protobuf/releases/download" |
| GRPC_PLUGIN_BASE_URL = "https://repo1.maven.org/maven2/io/grpc/protoc-gen-grpc-java" |
| |
| PROTOC_SHA1S = { |
| "protoc-3.2.0-linux-x86_64.zip":"f418d246d183a534d9bd749e614f639a55f6829b", |
| "protoc-3.2.0-osx-x86_64.zip":"81f4fac3200ba2cb12a98df0a9ee4d1c584e9210" |
| } |
| |
| GRPC_JAVA_SHA1S = { |
| "protoc-gen-grpc-java-1.3.0-linux-x86_64.exe":"44a0fa3e6074852ea84f93d258233b3f4f6d9e53", |
| "protoc-gen-grpc-java-1.3.0-osx-x86_64.exe":"61a1b81b9f0af7d0900c314a4201972b52fb5f12" |
| } |
| |
| #Returns the string for the OS and architecture of the system of the form 'OS-ARCH' |
| def get_system_arch(): |
| import platform |
| os = platform.system().lower() |
| arch = platform.machine() |
| if os == "darwin": |
| os = "osx" |
| return "%s-%s" % ( os, arch) |
| |
| def fetch_protoc( |
| version |
| ): |
| file_name = "protoc-%s-%s.zip" % (version, get_system_arch()) |
| if file_name not in PROTOC_SHA1S: |
| raise Exception('Cannot download %s, architecture or version not supported' % file_name) |
| remote_file( |
| name = 'protoc-release-' + version, |
| url = PROTOC_RELEASE_BASE_URL + '/v' + version + '/' + file_name, |
| sha1 = PROTOC_SHA1S[file_name], |
| ) |
| genrule( |
| name = 'protoc-exe-' + version, |
| bash = 'jar xf $(location :protoc-release-' + version + ') bin/protoc && ' + |
| 'mv bin/protoc $OUT && ' + |
| 'chmod +x $OUT', |
| out = 'protoc.exe', |
| executable = True, |
| visibility = [ "PUBLIC" ], |
| ) |
| genrule( |
| name = 'protoc-lib-' + version, |
| bash = 'jar xf $(location :protoc-release-' + version + ') include && mv include $OUT', |
| out = 'include', |
| visibility = [ "PUBLIC" ], |
| ) |
| |
| def fetch_grpc_plugin( |
| version |
| ): |
| file_name = "protoc-gen-grpc-java-%s-%s.exe" % (version, get_system_arch()) |
| if file_name not in GRPC_JAVA_SHA1S: |
| raise Exception('Cannot download %s, architecture or version not supported' % file_name) |
| remote_file( |
| name = 'grpc-plugin-binary-' + version, |
| url = GRPC_PLUGIN_BASE_URL + '/' + version + '/' + file_name, |
| sha1 = GRPC_JAVA_SHA1S[file_name], |
| ) |
| genrule( |
| name = 'grpc-plugin-exe-' + version, |
| bash = 'cp $(location :grpc-plugin-binary-' + version + ') $OUT && chmod +x $OUT', |
| executable = True, |
| visibility = [ "PUBLIC" ], |
| out = 'grpc-plugin.exe', |
| ) |
| |
| def _get_name(): |
| base_path = get_base_path() |
| return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator |
| |
| def grpc_jar( |
| name = None, |
| deps = [], |
| #NOTE: if targeting a directory also built with maven this path MUST end in |
| # /proto because maven plugin interprets imports relative to the proto |
| # directory and BUCK interprets imports relative to the last directory |
| # listed in the first listed proto_path which contains the specified |
| # file |
| proto_paths = [], |
| srcs = [], |
| src_string = '', # Useful to build proto files external to the ONOS sources, using BUCK's environment variables. |
| proto_match_patterns = [ "**/proto/**/*.proto" ], |
| protoc_version = DEFAULT_PROTOC_VERSION, |
| plugin_version = DEFAULT_GRPC_PLUGIN_VERSION, |
| include_std_lib = False, |
| **kwargs |
| ): |
| |
| #Get the correct name for the protoc compilation call |
| if name is None: |
| name = _get_name() |
| |
| # Create the string for the proto_path arguments (order matters, similar to classpath) |
| |
| if include_std_lib: |
| # Add protoc standard lib to the includes |
| proto_paths = ['$(location //incubator/protobuf-dependencies:protoc-lib-' + protoc_version + ')'] + proto_paths |
| |
| if len(proto_paths) != 0: |
| proto_paths_string = "-I=" + reduce(lambda a,b: a +" -I=" + b, proto_paths) |
| else: |
| proto_paths_string = "" |
| protoc = name + '-protoc' |
| |
| genrule( |
| name = protoc, |
| srcs = glob(proto_match_patterns), |
| out = 'grpc.src.zip', |
| cmd = '$(location //buck-tools:grpc) $OUT ' |
| + '\"' + proto_paths_string + '\" ' |
| + '$(location //incubator/protobuf-dependencies:protoc-exe-'+ protoc_version + ') ' |
| + '$(location //incubator/grpc-dependencies:grpc-plugin-exe-' + plugin_version + ') ' |
| + '$SRCS' + src_string, |
| ) |
| |
| osgi_jar( |
| name = name, |
| srcs = [ ':' + protoc ], |
| deps = deps + [ ':' + protoc ], |
| do_javadocs = False, |
| do_checkstyle = False, |
| **kwargs |
| ) |