Skip to content

Commit bb2e512

Browse files
committed
fix(pkgbuild): distro-specific functions must not be overwritten by base
When a PKGBUILD declares both 'prepare()' (priority 0, base) and 'prepare__ubuntu_jammy()' (priority 3, distro-specific), AddItem was overwriting the higher-priority function with the base one whenever the base directive was parsed after the distro variant — because mapFunctions ran unconditionally even though the priority gate already short-circuited variables/arrays for that case. This broke distro-specific hooks any time the base function appeared later in the file (the common pattern in PKGBUILDs that share a helper '_prepare' and have one distro override calling it). The symptom on Ubuntu jammy was the chrono-hours patch being silently skipped because the jammy-specific prepare was clobbered by the generic one. Gate mapFunctions on priority >= oldPriority so distro/codename variants survive a subsequent base assignment. Arrays still accumulate (intentional, matches makepkg's source_<arch> behaviour); this only changes function dispatch.
1 parent 8b7b370 commit bb2e512

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

pkg/pkgbuild/pkgbuild.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,15 @@ func (pkgBuild *PKGBUILD) AddItem(key string, data any) error {
224224

225225
pkgBuild.mapVariables(key, data)
226226
pkgBuild.mapArrays(key, data, priority)
227-
pkgBuild.mapFunctions(key, data)
227+
228+
// Functions, unlike arrays, do not accumulate across base/distro-specific
229+
// variants — they replace. A previously stored higher-priority variant
230+
// (e.g. prepare__ubuntu_jammy) must NOT be overwritten by a later base
231+
// prepare() call. Only assign when this directive's priority is at least
232+
// as high as the highest seen so far for this key.
233+
if priority >= oldPriority {
234+
pkgBuild.mapFunctions(key, data)
235+
}
228236

229237
return nil
230238
}

0 commit comments

Comments
 (0)