Skip to content

Commit

Permalink
patchpkg: don't error on missing store refs
Browse files Browse the repository at this point in the history
Don't exit non-zero when `devbox patch` is unable to restore some of
the missing references to Python build dependencies.

Fixes #2289.
  • Loading branch information
gcurtis committed Sep 23, 2024
1 parent 6021de4 commit e21a8cc
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions internal/patchpkg/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,11 @@ func (d *DerivationBuilder) Build(ctx context.Context, pkgStorePath string) erro

func (d *DerivationBuilder) build(ctx context.Context, pkg, out *packageFS) error {
if d.RestoreRefs {
// Find store path references to build inputs that were removed
// from Python.
refs, err := d.findRemovedRefs(ctx, pkg)
if err != nil {
return err
}

// Group the references we want to restore by file path.
d.bytePatches = make(map[string][]fileSlice, len(refs))
for _, ref := range refs {
d.bytePatches[ref.path] = append(d.bytePatches[ref.path], ref)
}

// If any of those references have shared libraries, add them
// back to Python's RPATH.
if d.glibcPatcher != nil {
nixStore := cmp.Or(os.Getenv("NIX_STORE"), "/nix/store")
seen := make(map[string]bool)
for _, ref := range refs {
storePath := filepath.Join(nixStore, string(ref.data))
if seen[storePath] {
continue
}
seen[storePath] = true
d.glibcPatcher.prependRPATH(newPackageFS(storePath))
}
if err := d.restoreMissingRefs(ctx, pkg); err != nil {
// Don't break the flake build if we're unable to
// restore some of the refs. Having some is still an
// improvement.
slog.ErrorContext(ctx, "unable to restore all removed refs", "err", err)
}
}

Expand Down Expand Up @@ -152,6 +131,37 @@ func (d *DerivationBuilder) build(ctx context.Context, pkg, out *packageFS) erro
return cmd.Run()
}

func (d *DerivationBuilder) restoreMissingRefs(ctx context.Context, pkg *packageFS) error {
// Find store path references to build inputs that were removed
// from Python.
refs, err := d.findRemovedRefs(ctx, pkg)
if err != nil {
return err
}

// Group the references we want to restore by file path.
d.bytePatches = make(map[string][]fileSlice, len(refs))
for _, ref := range refs {
d.bytePatches[ref.path] = append(d.bytePatches[ref.path], ref)
}

// If any of those references have shared libraries, add them
// back to Python's RPATH.
if d.glibcPatcher != nil {
nixStore := cmp.Or(os.Getenv("NIX_STORE"), "/nix/store")
seen := make(map[string]bool)
for _, ref := range refs {
storePath := filepath.Join(nixStore, string(ref.data))
if seen[storePath] {
continue
}
seen[storePath] = true
d.glibcPatcher.prependRPATH(newPackageFS(storePath))
}
}
return nil
}

func (d *DerivationBuilder) copyDir(out *packageFS, path string) error {
path, err := out.OSPath(path)
if err != nil {
Expand Down

0 comments on commit e21a8cc

Please sign in to comment.