Esin Karaman | 971fb7f | 2017-12-28 13:44:52 +0000 | [diff] [blame] | 1 | COMPILE_DEPS = [ |
| 2 | '//lib:CORE_DEPS', |
| 3 | '//lib:libthrift', |
| 4 | ] |
| 5 | |
| 6 | # BMV2_COMMIT should be set to the same value as specified in install-p4-tools.sh |
Carmelo Cascone | f645e84 | 2018-07-16 18:31:52 +0200 | [diff] [blame] | 7 | BMV2_COMMIT = 'a3f0ebe4c0f10a656f8aa1ad68cb20402a62b0ee' |
Esin Karaman | 971fb7f | 2017-12-28 13:44:52 +0000 | [diff] [blame] | 8 | BMV2_BASEURL = 'https://cdn.rawgit.com/p4lang/behavioral-model/' + BMV2_COMMIT |
| 9 | BMV2_NAMESPACE = 'org.onosproject.bmv2.thriftapi' |
| 10 | |
| 11 | THRIFT_EXE_BASEURL = 'https://cdn.rawgit.com/ccascone/mvn-thrift-compiler/1.1_0.9.3/exe/' |
| 12 | THRIFT_EXE_SHA1S = { |
| 13 | 'thrift-linux-x86_64.exe':'9b7b5d6eabc9552b8227e8f63981bc15c0985dd5', |
| 14 | 'thrift-osx-x86_64.exe':'b9215c5141f56fd277b7cf41d9745af847afe498' |
| 15 | } |
| 16 | |
| 17 | def prebuilt_thrift_compiler(): |
| 18 | import platform |
| 19 | os_name = platform.system().lower() |
| 20 | if os_name == 'darwin': |
| 21 | os_name = 'osx' |
| 22 | arch = '%s-%s' % (os_name, platform.machine()) |
| 23 | fname = 'thrift-%s.exe' % arch |
| 24 | if fname not in THRIFT_EXE_SHA1S: |
| 25 | raise Exception('Cannot download thrift compiler, architecture %s not supported' % arch) |
| 26 | remote_file( |
| 27 | name = 'thrift-binary', |
| 28 | out = 'thrift.binary', |
| 29 | url = THRIFT_EXE_BASEURL + fname, |
| 30 | sha1 = THRIFT_EXE_SHA1S[fname], |
| 31 | ) |
| 32 | genrule ( |
| 33 | name = 'thrift-exe', |
| 34 | srcs = [ ':thrift-binary' ], |
| 35 | bash = 'cp $(location :thrift-binary) $OUT && chmod +x $OUT', |
| 36 | executable = True, |
| 37 | out = 'thrift.exe' |
| 38 | ) |
| 39 | |
| 40 | prebuilt_thrift_compiler() |
| 41 | |
| 42 | # TODO: or export local thrift executable |
| 43 | # export_file( |
| 44 | # name = 'thrift-exe', |
| 45 | # src = '/usr/bin/thrift', |
| 46 | # ) |
| 47 | |
| 48 | def remote_thrift_def( |
| 49 | name, |
| 50 | url, |
| 51 | sha1): |
| 52 | # Download *.thrift definition file. |
| 53 | remote_file( |
| 54 | name = name + '-rem', |
| 55 | out = name + '.thrift', |
| 56 | url = url, |
| 57 | sha1 = sha1, |
| 58 | ) |
| 59 | # Add java namespace. |
| 60 | genrule ( |
| 61 | name = name+'-ns', |
| 62 | srcs = [':' + name + '-rem'], |
| 63 | bash = 'cp $(location :' + name + '-rem) $OUT && ' |
| 64 | + 'echo "namespace java ' + BMV2_NAMESPACE + '" | ' |
| 65 | + 'cat - $OUT > temp && mv temp $OUT', |
| 66 | out = name + '.thrift', |
| 67 | ) |
| 68 | # Generate Java sources. |
| 69 | genrule ( |
| 70 | name = name+'-gen', |
| 71 | srcs = [':' + name + '-ns'], |
| 72 | # FIXME: is there a better way to get just the output dir of this rule? |
| 73 | # ...not the full file path in $OUT |
| 74 | cmd = '$(exe :thrift-exe) -o $SRCDIR/../' + name + '-gen ' |
| 75 | + '--gen java $SRCDIR/' + name + '.thrift', |
| 76 | out = 'gen-java', |
| 77 | ) |
| 78 | # Zip them. |
| 79 | zip_file( |
| 80 | name = name, |
| 81 | out = name + '.src.zip', |
| 82 | srcs = [':' + name + '-gen'] |
| 83 | ) |
| 84 | |
| 85 | |
| 86 | remote_thrift_def( |
| 87 | name = 'simple_pre_lag', |
| 88 | url = BMV2_BASEURL + '/thrift_src/simple_pre_lag.thrift', |
| 89 | sha1 = 'f468ebebc7bb8577f11ca950939f34add5f5634c', |
| 90 | ) |
| 91 | |
| 92 | osgi_jar( |
| 93 | # If a source ending with *.src.zip is passed, Buck automatically looks for *.java files inside. |
| 94 | srcs = [':simple_pre_lag'], |
| 95 | deps = COMPILE_DEPS, |
| 96 | do_javadocs = False, |
| 97 | do_checkstyle = False |
| 98 | ) |
| 99 | |
| 100 | project_config( |
| 101 | src_target = ':onos-protocols-bmv2-thrift-api' |
Carmelo Cascone | f645e84 | 2018-07-16 18:31:52 +0200 | [diff] [blame] | 102 | ) |