Skip to content

Commit e21a8cc

Browse files
committed
patchpkg: don't error on missing store refs
Don't exit non-zero when `devbox patch` is unable to restore some of the missing references to Python build dependencies. Fixes #2289.
1 parent 6021de4 commit e21a8cc

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

internal/patchpkg/builder.go

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,32 +96,11 @@ func (d *DerivationBuilder) Build(ctx context.Context, pkgStorePath string) erro
9696

9797
func (d *DerivationBuilder) build(ctx context.Context, pkg, out *packageFS) error {
9898
if d.RestoreRefs {
99-
// Find store path references to build inputs that were removed
100-
// from Python.
101-
refs, err := d.findRemovedRefs(ctx, pkg)
102-
if err != nil {
103-
return err
104-
}
105-
106-
// Group the references we want to restore by file path.
107-
d.bytePatches = make(map[string][]fileSlice, len(refs))
108-
for _, ref := range refs {
109-
d.bytePatches[ref.path] = append(d.bytePatches[ref.path], ref)
110-
}
111-
112-
// If any of those references have shared libraries, add them
113-
// back to Python's RPATH.
114-
if d.glibcPatcher != nil {
115-
nixStore := cmp.Or(os.Getenv("NIX_STORE"), "/nix/store")
116-
seen := make(map[string]bool)
117-
for _, ref := range refs {
118-
storePath := filepath.Join(nixStore, string(ref.data))
119-
if seen[storePath] {
120-
continue
121-
}
122-
seen[storePath] = true
123-
d.glibcPatcher.prependRPATH(newPackageFS(storePath))
124-
}
99+
if err := d.restoreMissingRefs(ctx, pkg); err != nil {
100+
// Don't break the flake build if we're unable to
101+
// restore some of the refs. Having some is still an
102+
// improvement.
103+
slog.ErrorContext(ctx, "unable to restore all removed refs", "err", err)
125104
}
126105
}
127106

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

134+
func (d *DerivationBuilder) restoreMissingRefs(ctx context.Context, pkg *packageFS) error {
135+
// Find store path references to build inputs that were removed
136+
// from Python.
137+
refs, err := d.findRemovedRefs(ctx, pkg)
138+
if err != nil {
139+
return err
140+
}
141+
142+
// Group the references we want to restore by file path.
143+
d.bytePatches = make(map[string][]fileSlice, len(refs))
144+
for _, ref := range refs {
145+
d.bytePatches[ref.path] = append(d.bytePatches[ref.path], ref)
146+
}
147+
148+
// If any of those references have shared libraries, add them
149+
// back to Python's RPATH.
150+
if d.glibcPatcher != nil {
151+
nixStore := cmp.Or(os.Getenv("NIX_STORE"), "/nix/store")
152+
seen := make(map[string]bool)
153+
for _, ref := range refs {
154+
storePath := filepath.Join(nixStore, string(ref.data))
155+
if seen[storePath] {
156+
continue
157+
}
158+
seen[storePath] = true
159+
d.glibcPatcher.prependRPATH(newPackageFS(storePath))
160+
}
161+
}
162+
return nil
163+
}
164+
155165
func (d *DerivationBuilder) copyDir(out *packageFS, path string) error {
156166
path, err := out.OSPath(path)
157167
if err != nil {

0 commit comments

Comments
 (0)