Skip to content

Commit 48c9501

Browse files
authored
Merge pull request #339 from pkgxdev/smartter-flatten
improve smart flattening
2 parents 8111599 + 9c2199c commit 48c9501

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed

lib/porcelain/fix-up.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,64 @@ async function consolidate_lib64(pkg_prefix: Path) {
150150
Deno.symlinkSync("lib", lib64.string)
151151
}
152152

153+
// headers that must not be flattened into include/ as they would shadow
154+
// system/libc headers (compared case-insensitively for macOS HFS+/APFS)
155+
const SYSTEM_HEADERS = new Set([
156+
"assert.h",
157+
"complex.h",
158+
"ctype.h",
159+
"errno.h",
160+
"fenv.h",
161+
"float.h",
162+
"inttypes.h",
163+
"iso646.h",
164+
"limits.h",
165+
"locale.h",
166+
"math.h",
167+
"setjmp.h",
168+
"signal.h",
169+
"stdalign.h",
170+
"stdarg.h",
171+
"stdatomic.h",
172+
"stdbool.h",
173+
"stddef.h",
174+
"stdint.h",
175+
"stdio.h",
176+
"stdlib.h",
177+
"stdnoreturn.h",
178+
"string.h",
179+
"tgmath.h",
180+
"threads.h",
181+
"time.h",
182+
"uchar.h",
183+
"wchar.h",
184+
"wctype.h",
185+
// POSIX
186+
"dirent.h",
187+
"fcntl.h",
188+
"glob.h",
189+
"grp.h",
190+
"netdb.h",
191+
"poll.h",
192+
"pthread.h",
193+
"pwd.h",
194+
"regex.h",
195+
"sched.h",
196+
"search.h",
197+
"semaphore.h",
198+
"spawn.h",
199+
"strings.h",
200+
"syslog.h",
201+
"termios.h",
202+
"unistd.h",
203+
"utime.h",
204+
"wordexp.h",
205+
// common C++ / platform headers that cause trouble
206+
"memory.h",
207+
"version.h",
208+
"module.h",
209+
])
210+
153211
async function flatten_headers(pkg_prefix: Path) {
154212
// if include/ contains exactly one subdirectory and no loose files, flatten it
155213
// eg. include/foo/*.h → include/*.h with include/foo → symlink to .
@@ -168,6 +226,19 @@ async function flatten_headers(pkg_prefix: Path) {
168226
const subdir = subdirs[0]
169227
const name = subdir.basename()
170228

229+
// check for headers that would shadow system headers (case-insensitive for macOS)
230+
const dominated: string[] = []
231+
for await (const [path] of subdir.ls()) {
232+
const lower = path.basename().toLowerCase()
233+
if (SYSTEM_HEADERS.has(lower)) {
234+
dominated.push(path.basename())
235+
}
236+
}
237+
if (dominated.length > 0) {
238+
console.log({ skipping_flatten: name, would_shadow: dominated })
239+
return
240+
}
241+
171242
// move all contents up
172243
for await (const [path] of subdir.ls()) {
173244
Deno.renameSync(path.string, include.join(path.basename()).string)

projects/flatten.org/package.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
versions:
2+
- 1.0.0
3+
4+
build:
5+
# test header flattening exclusions
6+
- run: echo "// empty header" > String.h
7+
working-directory: "{{prefix}}/include/flatten"
8+
9+
test:
10+
- test ! -f '{{prefix}}/include/String.h'
11+
- test -f '{{prefix}}/include/flatten/String.h'
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import requests
22

3+
34
def get_website_content(url):
45
response = requests.get(url)
56
return response.text
67

8+
79
def main():
8-
content = get_website_content("https://example.com")
10+
content = get_website_content("https://google.com")
911
print(content)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import requests
22

3+
34
def get_website_content(url):
45
response = requests.get(url)
56
return response.text
67

8+
79
def main():
8-
content = get_website_content("https://example.com")
10+
content = get_website_content("https://google.com")
911
print(content)

0 commit comments

Comments
 (0)