Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 1 | COMPILE_DEPS = [ |
| 2 | '//lib:CORE_DEPS', |
| 3 | ] |
| 4 | |
| 5 | |
| 6 | PI_BASEURL = 'https://github.com/p4lang/PI.git' |
| 7 | PROTOBUF_BASEURL = 'https://github.com/google/protobuf.git' |
| 8 | |
| 9 | PROTOC_VER = '3.3.0' |
| 10 | GRPC_VER = '1.3.0' |
| 11 | |
| 12 | PROTOC_EXE_BASEURL = 'http://central.maven.org/maven2/com/google/protobuf/protoc/' |
| 13 | GRPC_JAVA_BASEURL = 'http://central.maven.org/maven2/io/grpc/protoc-gen-grpc-java/' |
| 14 | |
| 15 | |
| 16 | PROTOC_SHA1S = { |
| 17 | 'protoc-3.3.0-linux-x86_64.exe':'e6a95fc7477c602cc402ed976d3edbd82c841879', |
| 18 | 'protoc-3.3.0-osx-x86_64.exe':'3070e439f9557bb72fb04df631f29d7556c9029c' |
| 19 | } |
| 20 | |
| 21 | GRPC_JAVA_SHA1S = { |
| 22 | 'protoc-gen-grpc-java-1.3.0-linux-x86_64.exe':'44a0fa3e6074852ea84f93d258233b3f4f6d9e53', |
| 23 | 'protoc-gen-grpc-java-1.3.0-osx-x86_64.exe':'61a1b81b9f0af7d0900c314a4201972b52fb5f12' |
| 24 | } |
| 25 | |
| 26 | |
| 27 | GRPC_DEPS = [ |
| 28 | '//lib:grpc-core-' + GRPC_VER, |
| 29 | '//lib:grpc-protobuf-' + GRPC_VER, |
| 30 | '//lib:grpc-stub-' + GRPC_VER, |
| 31 | '//lib:grpc-netty-' + GRPC_VER, |
| 32 | '//lib:grpc-auth-' + GRPC_VER, |
| 33 | '//lib:protobuf-java-' + PROTOC_VER, |
| 34 | ] |
| 35 | |
| 36 | |
| 37 | def get_arch(): |
| 38 | import platform |
| 39 | os_name = platform.system().lower() |
| 40 | if os_name == 'darwin': |
| 41 | os_name = 'osx' |
| 42 | arch = '%s-%s' % (os_name, platform.machine()) |
| 43 | return arch |
| 44 | |
| 45 | # TODO: defs to download prebuilt protoc and grpc java plugin should visible by other BUCK files. |
| 46 | |
| 47 | def prebuilt_protoc(): |
| 48 | fname = 'protoc-%s-%s.exe' % (PROTOC_VER, get_arch()) |
| 49 | if fname not in PROTOC_SHA1S: |
| 50 | raise Exception('Cannot download %s, architecture not supported' % fname) |
| 51 | remote_file( |
| 52 | name = 'protoc-binary', |
| 53 | out = 'protoc.binary', |
| 54 | url = PROTOC_EXE_BASEURL + PROTOC_VER + '/' + fname, |
| 55 | sha1 = PROTOC_SHA1S[fname], |
| 56 | ) |
| 57 | genrule ( |
| 58 | name = 'protoc-exe', |
| 59 | srcs = [ ':protoc-binary' ], |
| 60 | bash = 'cp $(location :protoc-binary) $OUT && chmod +x $OUT', |
| 61 | executable = True, |
| 62 | out = 'protoc.exe' |
| 63 | ) |
| 64 | |
| 65 | |
| 66 | def prebuilt_protoc_java_plugin(): |
| 67 | arch = get_arch() |
| 68 | fname = 'protoc-gen-grpc-java-%s-%s.exe' % (GRPC_VER, get_arch()) |
| 69 | if fname not in GRPC_JAVA_SHA1S: |
| 70 | raise Exception('Cannot download %s, architecture not supported' % fname) |
| 71 | remote_file( |
| 72 | name = 'grpc-java-binary', |
| 73 | out = 'grpc-java.binary', |
| 74 | url = GRPC_JAVA_BASEURL + GRPC_VER + '/' + fname, |
| 75 | sha1 = GRPC_JAVA_SHA1S[fname], |
| 76 | ) |
| 77 | genrule ( |
| 78 | name = 'grpc-java-exe', |
| 79 | srcs = [ ':grpc-java-binary' ], |
| 80 | bash = 'cp $(location :grpc-java-binary) $OUT && chmod +x $OUT', |
| 81 | executable = True, |
| 82 | out = 'grpc-java.exe' |
| 83 | ) |
| 84 | |
| 85 | prebuilt_protoc() |
| 86 | prebuilt_protoc_java_plugin() |
| 87 | |
| 88 | genrule ( |
| 89 | name = 'p4lang-pi-repo', |
| 90 | # FIXME: should download a specific commit id/tag of p4runtime, right now we get the master. |
| 91 | bash = 'git clone --quiet ' + PI_BASEURL + ' $OUT > /dev/null && cd $OUT && ' |
| 92 | + 'git submodule update --quiet --init --recursive > /dev/null', |
| 93 | out = 'repo', |
| 94 | ) |
| 95 | |
| 96 | genrule ( |
| 97 | name = 'protoc-repo', |
| 98 | bash = 'git clone --quiet ' + PROTOBUF_BASEURL + ' $OUT > /dev/null && cd $OUT && ' |
| 99 | + 'git checkout --quiet -b x tags/v' + PROTOC_VER + ' > /dev/null', |
| 100 | out = 'repo', |
| 101 | ) |
| 102 | |
| 103 | def protoc_gen( |
| 104 | name, |
| 105 | proto_file, |
| 106 | out_pkg, |
| 107 | ): |
| 108 | genrule( |
| 109 | name = name + '-gen', |
| 110 | cmd = '$(exe :protoc-exe) --plugin=protoc-gen-grpc-java=$(location :grpc-java-exe) ' |
| 111 | + '--grpc-java_out=$SRCDIR/../' + name + '-gen ' |
| 112 | + '--java_out=$SRCDIR/../' + name + '-gen ' |
| 113 | + '-I$(location :p4lang-pi-repo)/proto ' |
| 114 | + '-I$(location :protoc-repo)/src ' |
| 115 | + proto_file, |
| 116 | out = out_pkg, |
| 117 | ) |
| 118 | zip_file( |
| 119 | name = name, |
| 120 | out = name + '.src.zip', |
| 121 | srcs = [':'+name+'-gen'] |
| 122 | ) |
| 123 | |
| 124 | # Wondering which .proto files to build? Check p4runtime's Makefile: |
| 125 | # https://github.com/p4lang/PI/blob/master/proto/Makefile.am |
| 126 | protoc_gen( |
| 127 | name = 'p4runtime', |
| 128 | proto_file = '$(location :p4lang-pi-repo)/proto/p4/p4runtime.proto', |
| 129 | out_pkg = 'p4', |
| 130 | ) |
| 131 | protoc_gen( |
| 132 | name = 'p4info', |
| 133 | proto_file = '$(location :p4lang-pi-repo)/proto/p4/config/p4info.proto', |
| 134 | out_pkg = 'p4', |
| 135 | ) |
| 136 | protoc_gen( |
| 137 | name = 'google-rpc-status', |
| 138 | proto_file = '$(location :p4lang-pi-repo)/proto/google/rpc/status.proto', |
| 139 | out_pkg = 'com', |
| 140 | ) |
| 141 | protoc_gen( |
| 142 | name = 'google-rpc-code', |
| 143 | proto_file = '$(location :p4lang-pi-repo)/proto/google/rpc/code.proto', |
| 144 | out_pkg = 'com', |
| 145 | ) |
| 146 | protoc_gen( |
| 147 | name = 'p4config', |
| 148 | proto_file = '$(location :p4lang-pi-repo)/proto/p4/tmp/p4config.proto', |
| 149 | out_pkg = 'p4', |
| 150 | ) |
| 151 | |
| 152 | |
| 153 | osgi_jar( |
| 154 | srcs = [':p4runtime', ':p4info', ':google-rpc-status', ':google-rpc-code', ':p4config'], |
| 155 | deps = COMPILE_DEPS + GRPC_DEPS, |
| 156 | do_javadocs = False, |
| 157 | do_checkstyle = False |
| 158 | ) |
| 159 | |
| 160 | |
| 161 | project_config( |
| 162 | src_target = ':onos-drivers-p4runtime-proto' |
| 163 | ) |