Conversation
| if got := versionOutput.String(); !strings.Contains(got, version) { | ||
| t.Errorf("sbt --version output does not include %q", version) | ||
| } | ||
| } |
There was a problem hiding this comment.
It would be good to have some unit tests for the sbtDownloadURL function, like for the Java buildpack (but doesn't need to be nearly as extensive):
yb/internal/buildpack/openjdk_test.go
Lines 48 to 141 in 03eed7b
| func TestSBT(t *testing.T) { | ||
| const version = "1.5.2" | ||
| ctx := testlog.WithTB(context.Background(), t) | ||
| // TODO(johnewart): SBT depends on Java -- see Ross's comment in sbt tests |
There was a problem hiding this comment.
| // TODO(johnewart): SBT depends on Java -- see Ross's comment in sbt tests | |
| // TODO(johnewart): SBT depends on Java -- see Ross's comment in Ant tests |
| func sbtDownloadURL(version string, desc *biome.Descriptor) (string, error) { | ||
| vparts := strings.SplitN(version, "+", 2) | ||
| subVersion := "" | ||
| if len(vparts) > 1 { | ||
| subVersion = vparts[1] | ||
| version = vparts[0] | ||
| } | ||
|
|
||
| parts := strings.Split(version, ".") | ||
|
|
||
| majorVersion, err := convertVersionPiece(parts, 0) | ||
| if err != nil { | ||
| return "", fmt.Errorf("parse jdk version %q: major: %w", version, err) | ||
| } | ||
| minorVersion, err := convertVersionPiece(parts, 1) | ||
| if err != nil { | ||
| return "", fmt.Errorf("parse jdk version %q: minor: %w", version, err) | ||
| } | ||
| patchVersion, err := convertVersionPiece(parts, 2) | ||
| if err != nil { | ||
| return "", fmt.Errorf("parse jdk version %q: patch: %w", version, err) | ||
| } | ||
|
|
||
| urlPattern := "https://github.com/sbt/sbt/releases/download/v{{ .MajorVersion }}.{{ .MinorVersion }}.{{ .PatchVersion }}/sbt-{{ .MajorVersion }}.{{ .MinorVersion }}.{{ .PatchVersion }}.tgz" | ||
|
|
||
| var data struct { | ||
| OS string | ||
| Arch string | ||
| MajorVersion int64 | ||
| MinorVersion int64 | ||
| PatchVersion int64 | ||
| SubVersion string // not always an int, sometimes a float | ||
| } | ||
| data.OS = map[string]string{ | ||
| biome.Linux: "linux", | ||
| biome.MacOS: "mac", | ||
| }[desc.OS] | ||
| if data.OS == "" { | ||
| return "", fmt.Errorf("unsupported os %s", desc.OS) | ||
| } | ||
| data.MajorVersion = majorVersion | ||
| data.MinorVersion = minorVersion | ||
| data.PatchVersion = patchVersion | ||
| data.SubVersion = subVersion | ||
| return templateToString(urlPattern, data) | ||
| } |
There was a problem hiding this comment.
IIUC, the URL is only dependent on version, right? I think this function can be simplified to pass the version string through verbatim.
| func sbtDownloadURL(version string, desc *biome.Descriptor) (string, error) { | |
| vparts := strings.SplitN(version, "+", 2) | |
| subVersion := "" | |
| if len(vparts) > 1 { | |
| subVersion = vparts[1] | |
| version = vparts[0] | |
| } | |
| parts := strings.Split(version, ".") | |
| majorVersion, err := convertVersionPiece(parts, 0) | |
| if err != nil { | |
| return "", fmt.Errorf("parse jdk version %q: major: %w", version, err) | |
| } | |
| minorVersion, err := convertVersionPiece(parts, 1) | |
| if err != nil { | |
| return "", fmt.Errorf("parse jdk version %q: minor: %w", version, err) | |
| } | |
| patchVersion, err := convertVersionPiece(parts, 2) | |
| if err != nil { | |
| return "", fmt.Errorf("parse jdk version %q: patch: %w", version, err) | |
| } | |
| urlPattern := "https://github.com/sbt/sbt/releases/download/v{{ .MajorVersion }}.{{ .MinorVersion }}.{{ .PatchVersion }}/sbt-{{ .MajorVersion }}.{{ .MinorVersion }}.{{ .PatchVersion }}.tgz" | |
| var data struct { | |
| OS string | |
| Arch string | |
| MajorVersion int64 | |
| MinorVersion int64 | |
| PatchVersion int64 | |
| SubVersion string // not always an int, sometimes a float | |
| } | |
| data.OS = map[string]string{ | |
| biome.Linux: "linux", | |
| biome.MacOS: "mac", | |
| }[desc.OS] | |
| if data.OS == "" { | |
| return "", fmt.Errorf("unsupported os %s", desc.OS) | |
| } | |
| data.MajorVersion = majorVersion | |
| data.MinorVersion = minorVersion | |
| data.PatchVersion = patchVersion | |
| data.SubVersion = subVersion | |
| return templateToString(urlPattern, data) | |
| } | |
| func sbtDownloadURL(version string) (string, error) { | |
| const urlPattern = "https://github.com/sbt/sbt/releases/download/v{{ .Version }}/sbt-{{ .Version }}.tgz" | |
| var data struct { | |
| Version string | |
| } | |
| data.Version = url.PathEscape(version) | |
| return templateToString(urlPattern, data) | |
| } |
| parentDir := os.TempDir() | ||
| socketDir, err := ioutil.TempDir(parentDir, "*-ybsbt") |
There was a problem hiding this comment.
This unfortunately won't work on Docker-based builds, since it creates the directory on the host instead of inside the biome.
Would it be appropriate to use a directory inside the biome home? Perhaps sys.Biome.JoinPath(sys.Biome.Dirs().Tools, "sbt-server")?
| if err != nil { | ||
| log.Errorf(ctx, "Error creating directory for SBT sockets: %v", err) | ||
| } | ||
| log.Infof(ctx, "SBT will use %s as the socket directory", socketDir) |
There was a problem hiding this comment.
I don't think the average user needs to know this information unless something went wrong, so I suggest debug-level log.
| log.Infof(ctx, "SBT will use %s as the socket directory", socketDir) | |
| log.Debugf(ctx, "SBT will use %s as the socket directory", socketDir) |
Also support
.tgzand.tbz2files in decompression bits