Skip to content

Commit

Permalink
Target data: populate os/arch as well as distro information
Browse files Browse the repository at this point in the history
Fixes #1371

Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano committed Jul 9, 2024
1 parent f2a3bd7 commit 4a5aed6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions platform/target_data.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package platform

import (
"runtime"

"github.com/buildpacks/imgutil"

"github.com/buildpacks/lifecycle/buildpack"
Expand Down Expand Up @@ -87,10 +89,16 @@ func matches(target1, target2 string) bool {
return target1 == target2
}

// GetTargetOSFromFileSystem populates the target metadata you pass in if the information is available
// returns a boolean indicating whether it populated any data.
// GetTargetOSFromFileSystem populates the provided target metadata with information from /etc/os-release
// if it is available.
func GetTargetOSFromFileSystem(d fsutil.Detector, tm *files.TargetMetadata, logger log.Logger) {
if d.HasSystemdFile() {
if tm.OS == "" {
tm.OS = "linux"
}
if tm.Arch == "" {
tm.Arch = runtime.GOARCH // in a future world where we support cross platform builds, this should be removed
}
contents, err := d.ReadSystemdFile()
if err != nil {
logger.Warnf("Encountered error trying to read /etc/os-release file: %s", err.Error())
Expand Down
3 changes: 3 additions & 0 deletions platform/target_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package platform_test

import (
"fmt"
"runtime"
"testing"

"github.com/apex/log"
Expand Down Expand Up @@ -129,6 +130,8 @@ func testTargetData(t *testing.T, when spec.G, it spec.S) {
t: t,
HasFile: true}
platform.GetTargetOSFromFileSystem(&d, &tm, logr)
h.AssertEq(t, "linux", tm.OS)
h.AssertEq(t, runtime.GOARCH, tm.Arch)
h.AssertEq(t, "opensesame", tm.Distro.Name)
h.AssertEq(t, "3.14", tm.Distro.Version)
})
Expand Down

0 comments on commit 4a5aed6

Please sign in to comment.