Skip to content

Commit bdb81ca

Browse files
committed
Update ab.
1 parent 4305197 commit bdb81ca

File tree

3 files changed

+30
-72
lines changed

3 files changed

+30
-72
lines changed

build/_sandbox.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main():
2626
print("link", sf)
2727
os.makedirs(dirname(sf), exist_ok=True)
2828
try:
29-
os.link(abspath(f), sf)
29+
os.symlink(abspath(f), sf)
3030
except PermissionError:
3131
shutil.copy(f, sf)
3232

@@ -38,6 +38,11 @@ def main():
3838
df = dirname(f)
3939
if df:
4040
os.makedirs(df, exist_ok=True)
41+
42+
try:
43+
os.remove(f)
44+
except FileNotFoundError:
45+
pass
4146
os.rename(sf, f)
4247

4348

build/ab.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
MAKENOT4 := $(if $(findstring 3.9999, $(lastword $(sort 3.9999 $(MAKE_VERSION)))),yes,no)
2-
MAKE4.3 := $(if $(findstring 4.3, $(firstword $(sort 4.3 $(MAKE_VERSION)))),yes,no)
3-
MAKE4.1 := $(if $(findstring no_no,$(MAKENOT4)_$(MAKE4.3)),yes,no)
42

53
ifeq ($(MAKENOT3),yes)
64
$(error You need GNU Make 4.x for this (if you're on OSX, use gmake).)

build/ab.py

Lines changed: 24 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from copy import copy
77
import functools
88
import importlib
9-
import importlib.abc
109
import importlib.util
1110
from importlib.machinery import (
1211
SourceFileLoader,
@@ -19,10 +18,9 @@
1918
import hashlib
2019
import re
2120
import ast
22-
import os
2321
from collections import namedtuple
2422

25-
COMPRESS_MK_FILE = True
23+
VERBOSE_MK_FILE = False
2624

2725
verbose = False
2826
quiet = False
@@ -225,16 +223,13 @@ def format_field(self, value, format_spec):
225223
if not value:
226224
return ""
227225
if type(value) == str:
228-
return compressf(value)
226+
return value
229227
if _isiterable(value):
230228
value = list(value)
231229
if type(value) != list:
232230
value = [value]
233231
return " ".join(
234-
[
235-
compressf(selfi.templateexpand(f))
236-
for f in filenamesof(value)
237-
]
232+
[selfi.templateexpand(f) for f in filenamesof(value)]
238233
)
239234

240235
return Formatter().format(s)
@@ -467,30 +462,6 @@ def filenameof(x):
467462
return xs[0]
468463

469464

470-
def compressf(a):
471-
if not COMPRESS_MK_FILE:
472-
return a
473-
global globalId
474-
if len(a) > 5:
475-
if a not in wordCache:
476-
wordCache[a] = globalId
477-
outputFp.write(f"f{globalId}={a}\n")
478-
globalId = globalId + 1
479-
a = f"$(f{wordCache[a]})"
480-
return a
481-
482-
483-
def compress(args):
484-
if not COMPRESS_MK_FILE:
485-
return args
486-
487-
compressed = []
488-
for a in args:
489-
compressed += [compressf(a)]
490-
491-
return compressed
492-
493-
494465
def emit(*args, into=None):
495466
s = " ".join(args) + "\n"
496467
if into is not None:
@@ -507,77 +478,61 @@ def emit_rule(self, ins, outs, cmds=[], label=None):
507478
nonobjs = [f for f in fouts if not f.startswith("$(OBJ)")]
508479

509480
emit("")
510-
for k, v in self.args.items():
511-
emit(f"# {k} = {v}")
481+
if VERBOSE_MK_FILE:
482+
for k, v in self.args.items():
483+
emit(f"# {k} = {v}")
512484

513485
lines = []
514486
if nonobjs:
515487
emit("clean::", into=lines)
516-
emit("\t$(hide) rm -f", *compress(nonobjs), into=lines)
488+
emit("\t$(hide) rm -f", *nonobjs, into=lines)
517489

518490
hashable = cmds + fins_list + fouts
519491
hash = hashlib.sha1(bytes("\n".join(hashable), "utf-8")).hexdigest()
520492
hashfile = join(self.dir, f"hash_{hash}")
521493

522494
global globalId
523-
emit(".PHONY:", compressf(name), into=lines)
495+
emit(".PHONY:", name, into=lines)
524496
if outs:
525497
outsn = globalId
526498
globalId = globalId + 1
527499
insn = globalId
528500
globalId = globalId + 1
529501

530-
emit(f"OUTS_{outsn}", "=", *compress(fouts), into=lines)
531-
emit(f"INS_{insn}", "=", *compress(fins), into=lines)
532-
emit(
533-
compressf(name),
534-
":",
535-
compressf(hashfile),
536-
f"$(OUTS_{outsn})",
537-
into=lines,
538-
)
539-
emit("ifeq ($(MAKE4.3),yes)", into=lines)
540-
emit(
541-
compressf(hashfile),
542-
f"$(OUTS_{outsn})",
543-
"&:",
544-
f"$(INS_{insn})",
545-
into=lines,
546-
)
547-
emit("else", into=lines)
548-
emit(f"$(OUTS_{outsn})", ":", compressf(hashfile), into=lines)
549-
emit(compressf(hashfile), ":", f"$(INS_{insn})", into=lines)
550-
emit("endif", into=lines)
502+
emit(f"OUTS_{outsn}", "=", *fouts, into=lines)
503+
emit(f"INS_{insn}", "=", *fins, into=lines)
504+
emit(name, ":", f"$(OUTS_{outsn})")
505+
emit(hashfile, ":")
506+
emit(f"\t@mkdir -p {self.dir}")
507+
emit(f"\t@touch {hashfile}")
508+
emit(f"$(OUTS_{outsn})", "&:",f"$(INS_{insn})", hashfile, into=lines)
551509

552510
if label:
553511
emit("\t$(hide)", "$(ECHO) $(PROGRESSINFO)" + label, into=lines)
554512

555513
sandbox = join(self.dir, "sandbox")
556-
emit("\t$(hide)", f"rm -rf {compressf(sandbox)}", into=lines)
514+
emit("\t$(hide)", f"rm -rf {sandbox}", into=lines)
557515
emit(
558516
"\t$(hide)",
559-
compressf("$(PYTHON) build/_sandbox.py --link -s"),
560-
compressf(sandbox),
517+
"$(PYTHON) build/_sandbox.py --link -s",
518+
sandbox,
561519
f"$(INS_{insn})",
562520
into=lines,
563521
)
564522
for c in cmds:
565-
emit(f"\t$(hide) cd {compressf(sandbox)} && (", c, ")", into=lines)
523+
emit(f"\t$(hide) cd {sandbox} && (", c, ")", into=lines)
566524
emit(
567525
"\t$(hide)",
568-
compressf("$(PYTHON) build/_sandbox.py --export -s"),
569-
compressf(sandbox),
526+
"$(PYTHON) build/_sandbox.py --export -s",
527+
sandbox,
570528
f"$(OUTS_{outsn})",
571529
into=lines,
572530
)
573531
else:
574532
assert len(cmds) == 0, "rules with no outputs cannot have commands"
575-
emit(compressf(name), ":", *compress(fins), into=lines)
533+
emit(name, ":", *fins, into=lines)
576534

577535
outputFp.write("".join(lines))
578-
579-
if outs:
580-
emit(f"\t$(hide) touch {compressf(hashfile)}")
581536
emit("")
582537

583538

@@ -645,8 +600,8 @@ def export(self, name=None, items: TargetsMap = {}, deps: Targets = []):
645600
self.outs = deps + outs
646601

647602
emit("")
648-
emit(".PHONY:", compressf(name))
649-
emit(compressf(name), ":", *compress(filenamesof(outs + deps)))
603+
emit(".PHONY:", name)
604+
emit(name, ":", *filenamesof(outs + deps))
650605

651606

652607
def main():

0 commit comments

Comments
 (0)