diff --git a/internal/integrations/golang/buildkit.go b/internal/integrations/golang/buildkit.go index dd0027255..e6a583f3a 100644 --- a/internal/integrations/golang/buildkit.go +++ b/internal/integrations/golang/buildkit.go @@ -7,6 +7,7 @@ package golang import ( "context" "fmt" + "path" "strings" "github.com/moby/buildkit/client/llb" @@ -73,12 +74,9 @@ func buildUsingBuildkit(ctx context.Context, env pkggraph.SealedContext, bin GoB goBuild = append(goBuild, quoteArgs(goBuildArgs(version, bin.StripBinary))...) goBuild = append(goBuild, fmt.Sprintf("-o=/out/%s", bin.BinaryName)) - relPath, err := makePkg(bin.GoWorkspacePath, bin.SourcePath) - if err != nil { - return nil, err - } + pkg := path.Join(bin.GoModule, bin.SourcePath) - goBuild = append(goBuild, relPath) + goBuild = append(goBuild, pkg) state := (llbutil.RunGo{ Base: prepareGoMod(base, src, conf.TargetPlatform()).Root(), diff --git a/internal/integrations/golang/generate.pb.go b/internal/integrations/golang/generate.pb.go index 4ca3bc624..da091c2d4 100644 --- a/internal/integrations/golang/generate.pb.go +++ b/internal/integrations/golang/generate.pb.go @@ -35,6 +35,8 @@ type FrameworkExt struct { GoModule string `protobuf:"bytes,2,opt,name=go_module,json=goModule,proto3" json:"go_module,omitempty"` // Relative path to go.work, or to go.mod. GoWorkspacePath string `protobuf:"bytes,4,opt,name=go_workspace_path,json=goWorkspacePath,proto3" json:"go_workspace_path,omitempty"` + // Path to the Go package within the module. + RelPackage string `protobuf:"bytes,5,opt,name=rel_package,json=relPackage,proto3" json:"rel_package,omitempty"` } func (x *FrameworkExt) Reset() { @@ -90,6 +92,13 @@ func (x *FrameworkExt) GetGoWorkspacePath() string { return "" } +func (x *FrameworkExt) GetRelPackage() string { + if x != nil { + return x.RelPackage + } + return "" +} + var File_internal_integrations_golang_generate_proto protoreflect.FileDescriptor var file_internal_integrations_golang_generate_proto_rawDesc = []byte{ @@ -97,7 +106,7 @@ var file_internal_integrations_golang_generate_proto_rawDesc = []byte{ 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1b, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, - 0x67, 0x65, 0x73, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x22, 0x8c, 0x01, 0x0a, 0x0c, 0x46, + 0x67, 0x65, 0x73, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x22, 0xad, 0x01, 0x0a, 0x0c, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b, 0x45, 0x78, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x67, 0x6f, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x67, 0x6f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x67, 0x6f, @@ -105,12 +114,14 @@ var file_internal_integrations_golang_generate_proto_rawDesc = []byte{ 0x6f, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x2a, 0x0a, 0x11, 0x67, 0x6f, 0x5f, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x67, 0x6f, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x50, - 0x61, 0x74, 0x68, 0x4a, 0x04, 0x08, 0x03, 0x10, 0x04, 0x52, 0x0e, 0x67, 0x6f, 0x5f, 0x6d, 0x6f, - 0x64, 0x75, 0x6c, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x42, 0x3b, 0x5a, 0x39, 0x6e, 0x61, 0x6d, - 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x6c, 0x61, 0x62, 0x73, 0x2e, 0x64, 0x65, 0x76, 0x2f, 0x66, - 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, - 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, - 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x74, 0x68, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, 0x6c, 0x5f, 0x70, 0x61, 0x63, 0x6b, 0x61, + 0x67, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, 0x65, 0x6c, 0x50, 0x61, 0x63, + 0x6b, 0x61, 0x67, 0x65, 0x4a, 0x04, 0x08, 0x03, 0x10, 0x04, 0x52, 0x0e, 0x67, 0x6f, 0x5f, 0x6d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x42, 0x3b, 0x5a, 0x39, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x6c, 0x61, 0x62, 0x73, 0x2e, 0x64, 0x65, 0x76, 0x2f, + 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, + 0x6e, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2f, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/internal/integrations/golang/generate.proto b/internal/integrations/golang/generate.proto index 8fc130315..bc6766f8b 100644 --- a/internal/integrations/golang/generate.proto +++ b/internal/integrations/golang/generate.proto @@ -20,4 +20,7 @@ message FrameworkExt { // Relative path to go.work, or to go.mod. string go_workspace_path = 4; + + // Path to the Go package within the module. + string rel_package = 5; } \ No newline at end of file diff --git a/internal/integrations/golang/gobinary.go b/internal/integrations/golang/gobinary.go index 436a8f568..41b712201 100644 --- a/internal/integrations/golang/gobinary.go +++ b/internal/integrations/golang/gobinary.go @@ -28,7 +28,7 @@ type GoBinary struct { GoWorkspacePath string `json:"workspacePath"` GoModule string `json:"module"` // Go module name. GoVersion string `json:"goVersion"` - SourcePath string `json:"sourcePath"` // Relative to ns workspace root. + SourcePath string `json:"sourcePath"` // Relative to GoModule. BinaryName string `json:"binaryName"` BinaryOnly bool @@ -59,6 +59,11 @@ func FromLocation(loc pkggraph.Location, pkgName string) (*GoBinary, error) { return nil, err } + pkgInsideMod, err := filepath.Rel(filepath.Dir(modFile), absSrc) + if err != nil { + return nil, err + } + gowork, _ := findroot.Find("go work", filepath.Dir(modFile), findroot.LookForFile("go.work")) if gowork == "" { gowork = filepath.Dir(modFile) @@ -73,7 +78,7 @@ func FromLocation(loc pkggraph.Location, pkgName string) (*GoBinary, error) { PackageName: loc.PackageName, GoWorkspacePath: relMod, GoModule: mod.Module.Mod.Path, - SourcePath: loc.Rel(pkgName), + SourcePath: pkgInsideMod, GoVersion: mod.Go.Version, }, nil } diff --git a/internal/integrations/golang/golang.go b/internal/integrations/golang/golang.go index 0ac5ba24e..5a98469f2 100644 --- a/internal/integrations/golang/golang.go +++ b/internal/integrations/golang/golang.go @@ -93,7 +93,7 @@ func (impl) PrepareBuild(ctx context.Context, _ assets.AvailableBuildAssets, ser GoWorkspacePath: ext.GoWorkspacePath, GoModule: ext.GoModule, GoVersion: ext.GoVersion, - SourcePath: server.Location.Rel(), + SourcePath: ext.RelPackage, BinaryName: serverName(server), } @@ -222,6 +222,7 @@ func (impl) PreParseServer(ctx context.Context, loc pkggraph.Location, ext *pars GoVersion: bin.GoVersion, GoModule: bin.GoModule, GoWorkspacePath: bin.GoWorkspacePath, + RelPackage: bin.SourcePath, }) if err != nil { return err diff --git a/internal/integrations/golang/localbuild.go b/internal/integrations/golang/localbuild.go index 346870f99..23bb05919 100644 --- a/internal/integrations/golang/localbuild.go +++ b/internal/integrations/golang/localbuild.go @@ -9,6 +9,7 @@ import ( "fmt" "io/fs" "os" + "path" "path/filepath" specs "github.com/opencontainers/image-spec/specs-go/v1" @@ -100,10 +101,7 @@ func compile(ctx context.Context, sdk golang.LocalSDK, absWorkspace string, targ modulePath := filepath.Join(absWorkspace, bin.GoWorkspacePath) out := filepath.Join(targetDir, bin.BinaryName) - pkg, err := makePkg(bin.GoWorkspacePath, bin.SourcePath) - if err != nil { - return err - } + pkg := path.Join(bin.GoModule, bin.SourcePath) var cmd localexec.Command cmd.Label = "go build"