-
Notifications
You must be signed in to change notification settings - Fork 9
/
binary.go
49 lines (39 loc) · 1.24 KB
/
binary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package parsing
import (
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/pkggraph"
)
func transformBinary(loc pkggraph.Location, bin *schema.Binary) error {
if bin.PackageName != "" {
return fnerrors.NewWithLocation(loc, "package_name can not be set")
}
if bin.Name == "" {
return fnerrors.NewWithLocation(loc, "binary name can't be empty")
}
bin.PackageName = loc.PackageName.String()
if len(bin.GetConfig().GetCommand()) == 0 {
hasGoLayers := false
for _, layer := range bin.BuildPlan.LayerBuildPlan {
if isImagePlanGo(layer) {
hasGoLayers = true
break
}
}
// For Go, by default, assume the binary is built with the same name as the package name.
// TODO: revisit this heuristic.
if hasGoLayers {
if bin.Config == nil {
bin.Config = &schema.BinaryConfig{}
}
bin.Config.Command = []string{"/" + bin.Name}
}
}
return nil
}
func isImagePlanGo(plan *schema.ImageBuildPlan) bool {
return plan.GoBuild != nil || plan.GoPackage != ""
}