Skip to content

Commit a6cf180

Browse files
authored
Merge pull request #830 from davidgiven/dtrg-ab
Update ab.
2 parents a7de3f6 + c356f2d commit a6cf180

File tree

7 files changed

+89
-31
lines changed

7 files changed

+89
-31
lines changed

.github/workflows/ccpp.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ jobs:
6666
path: 'fluxengine-testdata'
6767
- name: brew
6868
run: |
69-
brew install sqlite pkg-config libusb protobuf wxwidgets fmt make coreutils dylibbundler libjpeg libmagic nlohmann-json cli11 boost glfw3 md4c ninja python freetype2 mbedtls
69+
brew install sqlite pkg-config libusb protobuf wxwidgets fmt make coreutils dylibbundler libjpeg libmagic nlohmann-json cli11 boost glfw3 md4c ninja python freetype2 mbedtls@3
70+
brew link mbedtls@3
7071
brew upgrade
7172
- name: make
7273
run: gmake -C fluxengine

arch/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from glob import glob
55
import sys
66

7-
archs = [f for f in glob("*", root_dir="arch") if isfile(f"arch/{f}/{f}.proto")]
7+
archs = {basename(dirname(f)) for f in glob("arch/*/*.proto")}
88

99
ps = []
1010
pls = []

build/ab.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ def _filetarget(value, cwd):
388388
return t
389389

390390

391+
def getcwd():
392+
return cwdStack[-1]
393+
394+
391395
def targetof(value, cwd=None):
392396
if not cwd:
393397
cwd = cwdStack[-1]
@@ -544,12 +548,14 @@ def shell(*args):
544548

545549
def add_commanddb_entry(commands, file):
546550
global commandsDb
547-
commandsDb += [{
548-
"directory": os.getcwd(),
549-
"command": (" && ".join(commands)),
550-
"file": file
551-
}
552-
]
551+
commandsDb += [
552+
{
553+
"directory": os.getcwd(),
554+
"command": (" && ".join(commands)),
555+
"file": file,
556+
}
557+
]
558+
553559

554560
def emit_rule(self, ins, outs, cmds=[], label=None):
555561
name = self.name

build/utils.py

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
Targets,
55
filenameof,
66
filenamesof,
7-
cwdStack,
7+
getcwd,
88
error,
99
simplerule,
10-
G
10+
G,
1111
)
12-
from os.path import relpath, splitext, join, basename, isfile
12+
from os.path import relpath, splitext, join, basename, isfile, normpath
13+
from os import walk
1314
from glob import iglob
1415
import fnmatch
1516
import subprocess
1617
import shutil
18+
import re
19+
import functools
1720

1821

1922
def filenamesmatchingof(xs, pattern):
@@ -35,9 +38,61 @@ def collectattrs(*, targets, name, initial=[]):
3538
return sorted(s)
3639

3740

41+
@functools.cache
42+
def _glob_to_re(glob_str):
43+
opts = re.compile('([.]|[*][*]/|[*]|[?])|(.)')
44+
out = ''
45+
for (pattern_match, literal_text) in opts.findall(glob_str):
46+
if pattern_match == '.':
47+
out += '[.]'
48+
elif pattern_match == '**/':
49+
out += '(?:.*/)?'
50+
elif pattern_match == '*':
51+
out += '[^/]*'
52+
elif pattern_match == '?':
53+
out += '.'
54+
elif literal_text:
55+
out += literal_text
56+
return re.compile(out)
57+
58+
def _glob_filter(paths, pattern):
59+
r = _glob_to_re(pattern)
60+
for f in paths:
61+
if r.match(f):
62+
yield f
63+
64+
def _glob_matches(path, pattern):
65+
r = _glob_to_re(pattern)
66+
return r.match(path)
67+
68+
def glob(include=["*"], exclude=[], dir=None, relative_to="."):
69+
if not dir:
70+
dir = getcwd()
71+
if dir.startswith("./"):
72+
dir = normpath(join(getcwd(), dir))
73+
if relative_to.startswith("./"):
74+
relative_to = normpath(join(getcwd(), relative_to))
75+
76+
def iterate():
77+
for dirpath, dirnames, filenames in walk(
78+
dir, topdown=True, followlinks=True
79+
):
80+
dirpath = relpath(dirpath, dir)
81+
filenames = [normpath(join(dirpath, f)) for f in filenames]
82+
matching = set()
83+
for p in include:
84+
matching.update(_glob_filter(filenames, p))
85+
for p in exclude:
86+
matching = [n for n in matching if not _glob_matches(n, p)]
87+
for f in matching:
88+
yield normpath(relpath(join(dir, f), relative_to))
89+
90+
return list(iterate())
91+
92+
3893
def itemsof(pattern, root=None, cwd=None):
3994
if not cwd:
40-
cwd = cwdStack[-1]
95+
cwd = getcwd()
4196
if not root:
4297
root = "."
4398

dep/lexy/build.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from build.c import cxxlibrary
2-
from glob import glob
2+
from build.utils import glob
33

44
cxxlibrary(
55
name="lexy",
66
srcs=[],
77
hdrs={
88
h: f"./include/{h}"
9-
for h in glob("**/*.hpp", root_dir="dep/lexy/include", recursive=True)
9+
for h in glob(
10+
["**/*.hpp"], dir="dep/lexy/include", relative_to="dep/lexy/include"
11+
)
1012
},
1113
)

extras/build.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from build.ab import simplerule, simplerule
2-
from build.utils import objectify
2+
from build.utils import objectify, glob
33
from build.c import clibrary
44
from build.zip import zip
5-
from glob import glob
65
from os.path import *
76
import config
87

@@ -31,16 +30,14 @@
3130
label="ICONSET",
3231
)
3332

34-
template_files = [
35-
f
36-
for f in glob("**", recursive=True, root_dir="extras/FluxEngine.app.template")
37-
if isfile(join("extras/FluxEngine.app.template", f))
38-
]
3933
zip(
4034
name="fluxengine_template",
4135
items={
4236
join("FluxEngine.app", k): join("extras/FluxEngine.app.template", k)
43-
for k in template_files
37+
for k in glob(
38+
dir="extras/FluxEngine.app.template",
39+
relative_to="extras/FluxEngine.app.template",
40+
)
4441
},
4542
)
4643

src/gui2/build.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from build.c import cxxprogram, cxxlibrary, simplerule, clibrary
22
from build.ab import simplerule
33
from build.pkg import package
4-
from glob import glob
4+
from build.utils import glob
55
from functools import reduce
66
import operator
77
from os.path import *
@@ -26,17 +26,14 @@
2626

2727
def headers_from(path):
2828
hdrs = {
29-
k: f"{path}/{k}" for k in glob("**/*.h*", root_dir=path, recursive=True)
29+
k: f"{path}/{k}" for k in glob(["**/*.h*"], dir=path, relative_to=path)
3030
}
3131
assert hdrs, f"path {path} contained no headers"
3232
return hdrs
3333

3434

3535
def sources_from(path, except_for=[]):
36-
srcs = [
37-
join(path, f) for f in glob("**/*.[ch]*", root_dir=path, recursive=True)
38-
]
39-
srcs = [f for f in srcs if f not in except_for]
36+
srcs = glob(["**/*.[ch]*"], exclude=except_for, dir=path)
4037
assert srcs, f"path {path} contained no sources"
4138
return srcs
4239

@@ -352,7 +349,7 @@ def romfs(name, id, dir):
352349

353350
simplerule(
354351
name=name,
355-
ins=[f for f in glob(dir + "/**", recursive=True) if isfile(f)],
352+
ins=glob(dir=dir),
356353
outs=["=romfs.cc"],
357354
deps=[f".+{id}_mkromfs"],
358355
commands=[
@@ -429,9 +426,9 @@ def plugin(name, id, srcs, hdrs, romfsdir, deps):
429426
"dep/imhex/plugins/builtin/source/content/welcome_screen.cpp",
430427
]
431428
+ glob(
432-
"dep/imhex/plugins/builtin/source/content/data_processor_nodes/*"
429+
dir="dep/imhex/plugins/builtin/source/content/data_processor_nodes"
433430
)
434-
+ glob("dep/imhex/plugins/builtin/source/content/tutorials/*"),
431+
+ glob(dir="dep/imhex/plugins/builtin/source/content/tutorials"),
435432
)
436433
+ [
437434
"./imhex_overrides/main_menu_items.cpp",

0 commit comments

Comments
 (0)