Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[debug] collect all binaries generated with -g #277

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions native/native_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,37 @@ func (n NativeImage) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
}
}

src := filepath.Join(layer.Path, startClass)
in, err := os.Open(src)
/**
* native-image with -g since 22.3 splits debug info in separate file
*/
compiled, err := ioutil.ReadDir(layer.Path)
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to open %s\n%w", filepath.Join(layer.Path, startClass), err)
return libcnb.Layer{}, fmt.Errorf("unable to list children of %s\n%w", n.ApplicationPath, err)
}
defer in.Close()
for _, file := range compiled {
src := filepath.Join(layer.Path, file.Name())
in, err := os.Open(src)
fileInfo, err := in.Stat()
if fileInfo.IsDir() {
/*TODO: for now skip directories, but perhaps it's better to zip its content */
continue
}
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to open %s\n%w", filepath.Join(layer.Path, startClass), err)
}
defer in.Close()

dst := filepath.Join(n.ApplicationPath, startClass)
out, err := os.OpenFile(dst, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0755)
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to open %s\n%w", dst, err)
}
defer out.Close()
dst := filepath.Join(n.ApplicationPath, file.Name())
out, err := os.OpenFile(dst, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0755)
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to open %s\n%w", dst, err)
}
defer out.Close()

if _, err := io.Copy(out, in); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to copy %s -> %s \n%w", in.Name(), out.Name(), err)
}

if _, err := io.Copy(out, in); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to copy\n%w", err)
}

return layer, nil
Expand Down