aboutsummaryrefslogtreecommitdiffstats
path: root/executor/embed.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-05-08 15:58:36 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-05-08 14:09:37 +0000
commit18ce20b34413f355241bcb0135a5793b7e2d0240 (patch)
treebfab931201c861e2185d5a3f5835b79622e12d46 /executor/embed.go
parent0df1eb567cf9907957f671f67fa3f7a9152aeed7 (diff)
executor: fix embeding of headers
common_usb.h is included by both common_linux.h and common_netbsd.h. The current version may fail to replace one of these common_usb.h, if say common_linux.h is already replaced, but common_netbsd.h is not yet. Make the replacement algorithm more robust and just replace everything on each iteration until we can't replace anything anymore. Fixes #4783
Diffstat (limited to 'executor/embed.go')
-rw-r--r--executor/embed.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/executor/embed.go b/executor/embed.go
index a02413a12..9a8a83141 100644
--- a/executor/embed.go
+++ b/executor/embed.go
@@ -8,6 +8,7 @@ import (
"embed"
"fmt"
"io/fs"
+ "maps"
"path"
"regexp"
)
@@ -36,9 +37,9 @@ var CommonHeader = func() []byte {
}
}
// To not hardcode concrete order in which headers need to be replaced
- // we just iteratively try to replace whatever headers can be replaced
- // on the current step.
- for len(headers) != 0 {
+ // we just iteratively try to replace whatever headers can be replaced.
+ unused := maps.Clone(headers)
+ for {
relacedSomething := false
for file := range headers {
replace := []byte("#include \"" + path.Base(file) + "\"")
@@ -53,13 +54,16 @@ var CommonHeader = func() []byte {
panic(err)
}
data = bytes.ReplaceAll(data, replace, contents)
- delete(headers, file)
+ delete(unused, file)
relacedSomething = true
}
if !relacedSomething {
- panic(fmt.Sprintf("can't find includes for %v", headers))
+ break
}
}
+ if len(unused) != 0 {
+ panic(fmt.Sprintf("can't find includes for %v", unused))
+ }
// Remove `//` comments, but keep lines which start with `//%`.
for _, remove := range []string{
"(\n|^)\\s*//$",