daml/scala-protoc-plugins/scalapb/protoc-gen-scalapb.go
Andreas Herrmann 39a38d3a37
Update to Java 11 (#11512)
* Update to Java 11

changelog_begin
changelog_end

* Fix RoundingMode deprecation warnings

* Fix dep-ann warning

* Integer constructor

* JavaX annotation dependency

* javax.xml.bind was removed in Java 11

Using Guava as a replacement, since it is already a project dependency.

* JDK 11 no longer has a separate JRE tree

* Remove unused jdk_nix import

* remove now redundant jdk11_nix

* Java 8 --> 9 increased Instant.now() precision

See https://bugs.openjdk.java.net/browse/JDK-8068730

The precision of `Instant.now()` increased between Java 8 and Java 9.
On Linux and MacOS this doesn't seem to be a problem, as the precision
still seems to be at micro seconds. However, on Windows this now causes
errors of the following form:
```
java.lang.IllegalArgumentException: Conversion of Instant
2021-11-05T13:58:56.726875100Z to microsecond granularity would result
in loss of precision.
```
Suggesting that it now offers sub-microsecond precision.

`TimestampConversion.instantToMicros` had a check to fail if the
conversion lead to a loss of precision. In the specific failing test
case this is not a concern, so this adds a `roundInstantToMicros`
variant that avoids this kind of error.

* TMP round timestamps

* Revert "TMP round timestamps"

This reverts commit af8e261278.

* Skip versions before 1.6.0 in migration tests

changelog_begin
changelog_end

Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
2021-11-18 14:48:37 +00:00

87 lines
2.3 KiB
Go

package main
import (
"log"
"os"
"os/exec"
"path"
"syscall"
)
func main() {
// This works due to the expected sandbox layout:
//
// ./bazel-out/host/bin/external/build_stack_rules_proto/scala/compiler_plugin_deploy.jar
// ./bazel-out/host/bin/external/build_stack_rules_proto/scala/linux_amd64_stripped
// ./bazel-out/host/bin/external/build_stack_rules_proto/scala/linux_amd64_stripped/protoc-gen-scala
jar := mustFindInSandbox(path.Dir(os.Args[0]), "compiler_plugin_deploy.jar")
err, exitCode := run("external/local_jdk/bin/java", append([]string{"-jar", jar}, os.Args...), ".", nil)
if err != nil {
log.Printf("%v", err)
}
os.Exit(exitCode)
}
func mustFindInSandbox(dir, file string) string {
attempts := 0
for {
// Just in case we have a bug that will loop forever in some random
// filesystem pattern we haven't thought of
if attempts > 1000 {
log.Fatalf("Too many attempts to find %s within %s", file, dir)
}
if dir == "" {
log.Fatalf("Failed to find %s within %s", file, dir)
}
abs := path.Join(dir, file)
if exists(abs) {
return abs
}
dir = path.Dir(dir)
attempts++
}
}
// exists - return true if a file entry exists
func exists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
// run a command
func run(entrypoint string, args []string, dir string, env []string) (error, int) {
cmd := exec.Command(entrypoint, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = env
cmd.Dir = dir
err := cmd.Run()
var exitCode int
if err != nil {
// try to get the exit code
if exitError, ok := err.(*exec.ExitError); ok {
ws := exitError.Sys().(syscall.WaitStatus)
exitCode = ws.ExitStatus()
} else {
// This will happen (in OSX) if `name` is not available in $PATH,
// in this situation, exit code could not be get, and stderr will be
// empty string very likely, so we use the default fail code, and format err
// to string and set to stderr
log.Printf("Could not get exit code for failed program: %v, %v", entrypoint, args)
exitCode = -1
}
} else {
// success, exitCode should be 0 if go is ok
ws := cmd.ProcessState.Sys().(syscall.WaitStatus)
exitCode = ws.ExitStatus()
}
return err, exitCode
}