Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 1 | include_defs('//onos.defs') |
| 2 | include_defs('//bucklets/onos.bucklet') |
| 3 | |
| 4 | |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 5 | DEFAULT_PROTOC_VERSION = '3.2.0' |
| 6 | DEFAULT_GRPC_PLUGIN_VERSION = '1.3.0' |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 7 | |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 8 | PROTOC_RELEASE_BASE_URL = "https://github.com/google/protobuf/releases/download" |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 9 | GRPC_PLUGIN_BASE_URL = "https://repo1.maven.org/maven2/io/grpc/protoc-gen-grpc-java" |
| 10 | |
| 11 | PROTOC_SHA1S = { |
Carmelo Cascone | 569d4ad | 2017-07-10 16:09:00 -0400 | [diff] [blame] | 12 | "protoc-3.0.2-linux-x86_64.zip":"779ed606f524eb2c8c116b0fce7a3bc6507769e7", |
| 13 | "protoc-3.0.2-osx-x86_64.zip":"f71d97affca4ffe32747772539c0bcbf76c9dc9b", |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 14 | "protoc-3.2.0-linux-x86_64.zip":"f418d246d183a534d9bd749e614f639a55f6829b", |
Carmelo Cascone | 569d4ad | 2017-07-10 16:09:00 -0400 | [diff] [blame] | 15 | "protoc-3.2.0-osx-x86_64.zip":"81f4fac3200ba2cb12a98df0a9ee4d1c584e9210", |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | GRPC_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' |
| 24 | def 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 Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 32 | def fetch_protoc( |
| 33 | version |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 34 | ): |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 35 | file_name = "protoc-%s-%s.zip" % (version, get_system_arch()) |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 36 | if file_name not in PROTOC_SHA1S: |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 37 | raise Exception('Cannot download %s, architecture or version not supported' % file_name) |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 38 | remote_file( |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 39 | name = 'protoc-release-' + version, |
| 40 | url = PROTOC_RELEASE_BASE_URL + '/v' + version + '/' + file_name, |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 41 | sha1 = PROTOC_SHA1S[file_name], |
| 42 | ) |
| 43 | genrule( |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 44 | 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 Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 49 | executable = True, |
| 50 | visibility = [ "PUBLIC" ], |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 51 | ) |
| 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 Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 57 | ) |
| 58 | |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 59 | def fetch_grpc_plugin( |
| 60 | version |
| 61 | ): |
| 62 | file_name = "protoc-gen-grpc-java-%s-%s.exe" % (version, get_system_arch()) |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 63 | if file_name not in GRPC_JAVA_SHA1S: |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 64 | raise Exception('Cannot download %s, architecture or version not supported' % file_name) |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 65 | remote_file( |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 66 | name = 'grpc-plugin-binary-' + version, |
| 67 | url = GRPC_PLUGIN_BASE_URL + '/' + version + '/' + file_name, |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 68 | sha1 = GRPC_JAVA_SHA1S[file_name], |
| 69 | ) |
| 70 | genrule( |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 71 | name = 'grpc-plugin-exe-' + version, |
| 72 | bash = 'cp $(location :grpc-plugin-binary-' + version + ') $OUT && chmod +x $OUT', |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 73 | executable = True, |
| 74 | visibility = [ "PUBLIC" ], |
| 75 | out = 'grpc-plugin.exe', |
| 76 | ) |
| 77 | |
| 78 | def _get_name(): |
| 79 | base_path = get_base_path() |
| 80 | return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator |
| 81 | |
| 82 | def grpc_jar( |
| 83 | name = None, |
| 84 | deps = [], |
| 85 | #NOTE: if targeting a directory also built with maven this path MUST end in |
Aaron Kruglikov | 9f95f99 | 2017-06-23 14:15:25 +0900 | [diff] [blame] | 86 | # /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 Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 90 | proto_paths = [], |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 91 | srcs = [], |
| 92 | src_string = '', # Useful to build proto files external to the ONOS sources, using BUCK's environment variables. |
Yuta HIGUCHI | b1aec66 | 2017-11-15 14:20:13 -0800 | [diff] [blame^] | 93 | proto_match_patterns = [ "src/main/proto/**/*.proto" ], |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 94 | protoc_version = DEFAULT_PROTOC_VERSION, |
| 95 | plugin_version = DEFAULT_GRPC_PLUGIN_VERSION, |
| 96 | include_std_lib = False, |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 97 | **kwargs |
| 98 | ): |
| 99 | |
| 100 | #Get the correct name for the protoc compilation call |
| 101 | if name is None: |
| 102 | name = _get_name() |
| 103 | |
Carmelo Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 104 | # 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 Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 110 | 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 Cascone | 65f98ff | 2017-06-21 02:04:55 -0400 | [diff] [blame] | 122 | + '$(location //incubator/protobuf-dependencies:protoc-exe-'+ protoc_version + ') ' |
| 123 | + '$(location //incubator/grpc-dependencies:grpc-plugin-exe-' + plugin_version + ') ' |
| 124 | + '$SRCS' + src_string, |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 125 | ) |
| 126 | |
Aaron Kruglikov | 9f95f99 | 2017-06-23 14:15:25 +0900 | [diff] [blame] | 127 | osgi_jar( |
Aaron Kruglikov | e630fb1 | 2017-04-24 13:05:26 -0700 | [diff] [blame] | 128 | name = name, |
| 129 | srcs = [ ':' + protoc ], |
| 130 | deps = deps + [ ':' + protoc ], |
| 131 | do_javadocs = False, |
| 132 | do_checkstyle = False, |
| 133 | **kwargs |
| 134 | ) |