Skip to content

Commit

Permalink
[debug] collect all binaries generated with -g
Browse files Browse the repository at this point in the history
  • Loading branch information
vvlevchenko committed Jul 14, 2023
1 parent 6024850 commit 7df9263
Showing 1 changed file with 27 additions and 12 deletions.
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

0 comments on commit 7df9263

Please sign in to comment.