Skip to content

Commit 0dcace3

Browse files
luhringimjasonh
authored andcommitted
debug: build unsupported platforms with a warning
Signed-off-by: Dan Luhring <[email protected]>
1 parent 1c83f79 commit 0dcace3

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

pkg/build/gobuild.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -309,28 +309,27 @@ func getDelve(ctx context.Context, platform v1.Platform) (string, error) {
309309
cloneDir := filepath.Join(tmpInstallDir, "delve")
310310
err = os.MkdirAll(cloneDir, 0755)
311311
if err != nil {
312-
return "", fmt.Errorf("making dir for delve clone: %v", err)
312+
return "", fmt.Errorf("making dir for delve clone: %w", err)
313313
}
314314
err = git.Clone(ctx, cloneDir, delveCloneURL)
315315
if err != nil {
316-
return "", fmt.Errorf("cloning delve repo: %v", err)
316+
return "", fmt.Errorf("cloning delve repo: %w", err)
317317
}
318318
osArchDir := fmt.Sprintf("%s_%s", platform.OS, platform.Architecture)
319319
delveBinaryPath := filepath.Join(tmpInstallDir, "bin", osArchDir, "dlv")
320320

321321
// install delve to tmp directory
322322
args := []string{
323323
"build",
324-
"-C",
325-
cloneDir,
326-
"./cmd/dlv",
327324
"-o",
328325
delveBinaryPath,
326+
"./cmd/dlv",
329327
}
330328

331329
gobin := getGoBinary()
332330
cmd := exec.CommandContext(ctx, gobin, args...)
333331
cmd.Env = env
332+
cmd.Dir = cloneDir
334333

335334
var output bytes.Buffer
336335
cmd.Stderr = &output
@@ -924,6 +923,10 @@ func (g *gobuild) configForImportPath(ip string) Config {
924923
return config
925924
}
926925

926+
func (g gobuild) useDebugging(platform v1.Platform) bool {
927+
return g.debug && doesPlatformSupportDebugging(platform)
928+
}
929+
927930
func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, platform *v1.Platform) (oci.SignedImage, error) {
928931
if err := g.semaphore.Acquire(ctx, 1); err != nil {
929932
return nil, err
@@ -965,7 +968,7 @@ func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, pl
965968
}
966969
}
967970
if g.debug && !doesPlatformSupportDebugging(*platform) {
968-
return nil, fmt.Errorf("debugging is not supported for %s", platform)
971+
log.Printf("image for platform %q will be built without debugging enabled because debugging is not supported for that platform", *platform)
969972
}
970973

971974
if !g.platformMatcher.matches(platform) {
@@ -1078,7 +1081,7 @@ func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, pl
10781081
})
10791082

10801083
delvePath := "" // path for delve in image
1081-
if g.debug {
1084+
if g.useDebugging(*platform) {
10821085
// get delve locally
10831086
delveBinary, err := getDelve(ctx, *platform)
10841087
if err != nil {
@@ -1144,7 +1147,7 @@ func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, pl
11441147
updatePath(cfg, `C:\ko-app`)
11451148
cfg.Config.Env = append(cfg.Config.Env, `KO_DATA_PATH=C:\var\run\ko`)
11461149
} else {
1147-
if g.debug {
1150+
if g.useDebugging(*platform) {
11481151
cfg.Config.Entrypoint = append([]string{delvePath}, delveArgs...)
11491152
cfg.Config.Entrypoint = append(cfg.Config.Entrypoint, appPath)
11501153
}

pkg/internal/git/clone.go

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
// Copyright 2024 ko Build Authors All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// MIT License
16+
//
17+
// Copyright (c) 2016-2022 Carlos Alexandro Becker
18+
//
19+
// Permission is hereby granted, free of charge, to any person obtaining a copy
20+
// of this software and associated documentation files (the "Software"), to deal
21+
// in the Software without restriction, including without limitation the rights
22+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23+
// copies of the Software, and to permit persons to whom the Software is
24+
// furnished to do so, subject to the following conditions:
25+
//
26+
// The above copyright notice and this permission notice shall be included in all
27+
// copies or substantial portions of the Software.
28+
//
29+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
// SOFTWARE.
36+
137
package git
238

339
import (
@@ -10,15 +46,15 @@ import (
1046
func Clone(ctx context.Context, dir string, repoURL string) error {
1147
rc := runConfig{
1248
dir: dir,
13-
args: []string{"clone", "--depth", "1", repoURL},
49+
args: []string{"clone", "--depth", "1", repoURL, "."},
1450
}
1551

1652
cmd := exec.CommandContext(ctx, "git", "clone", repoURL, dir)
1753
cmd.Dir = dir
1854

1955
_, err := run(ctx, rc)
2056
if err != nil {
21-
return fmt.Errorf("running git clone: %v", err)
57+
return fmt.Errorf("running git clone: %w", err)
2258
}
2359

2460
return nil

0 commit comments

Comments
 (0)