Skip to content

Commit 2a876f6

Browse files
authored
Merge pull request #340 from davidgiven/dtrg-ab
Update ab.
2 parents 6a55a6f + 141d2e1 commit 2a876f6

File tree

13 files changed

+163
-87
lines changed

13 files changed

+163
-87
lines changed

.github/workflows/ccpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
- uses: actions/checkout@v3
5353
- name: build
5454
run: |
55-
make LDFLAGS="-s -static" ack-setup.exe
55+
make LDFLAGS="-s -static" ack-setup.exe AB_SANDBOX=no
5656
- name: upload setup
5757
uses: actions/upload-artifact@v4
5858
with:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
- name: build
4040
run: |
41-
make LDFLAGS="-s -static" ack-setup.exe
41+
make LDFLAGS="-s -static" ack-setup.exe AB_SANDBOX=no
4242
4343
- name: date
4444
run: |

build/ab.mk

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ build-file-timestamps = $(shell ls -l $(build-files) | md5sum)
8484
# Wipe the build file (forcing a regeneration) if the make environment is different.
8585
# (Conveniently, this includes the pkg-config hash calculated above.)
8686

87-
ignored-variables = MAKE_RESTARTS .VARIABLES MAKECMDGOALS MAKEFLAGS MFLAGS
87+
ignored-variables = MAKE_RESTARTS .VARIABLES MAKECMDGOALS MAKEFLAGS MFLAGS PAGER _ \
88+
DESKTOP_STARTUP_ID XAUTHORITY ICEAUTHORITY SSH_AUTH_SOCK SESSION_MANAGER \
89+
INVOCATION_ID SYSTEMD_EXEC_PID MANAGER_PID SSH_AGENT_PID JOURNAL_STREAM \
90+
GPG_TTY WINDOWID MANAGERPID MAKE_TERMOUT MAKE_TERMERR OLDPWD
8891
$(shell mkdir -p $(OBJ))
8992
$(file >$(OBJ)/newvars.txt,$(foreach v,$(filter-out $(ignored-variables),$(.VARIABLES)),$(v)=$($(v))$(newline)))
9093
$(shell touch $(OBJ)/vars.txt)
@@ -104,13 +107,17 @@ clean::
104107
@echo CLEAN
105108
$(hide) rm -rf $(OBJ)
106109

110+
compile_commands.json: $(OBJ)/build.ninja
111+
+$(hide) $(NINJA) -f $(OBJ)/build.ninja -t compdb > $@
112+
107113
export PYTHONHASHSEED = 1
108114
$(OBJ)/build.ninja $(OBJ)/build.targets &:
109115
@echo "AB"
110116
$(hide) $(PYTHON) -X pycache_prefix=$(OBJ)/__pycache__ build/ab.py \
111117
-o $(OBJ) build.py \
112118
-v $(OBJ)/vars.txt \
113119
|| (rm -f $@ && false)
120+
$(hide) cp $(OBJ)/compile_commands.json compile_commands.json
114121

115122
include $(OBJ)/build.targets
116123
.PHONY: $(ninja-targets)

build/ab.py

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import importlib
1313
import importlib.util
1414
import inspect
15+
import json
1516
import os
1617
import re
1718
import string
@@ -27,6 +28,7 @@
2728
materialisingStack = []
2829
defaultGlobals = {}
2930
outputTargets = set()
31+
commandsDb = []
3032

3133
RE_FORMAT_SPEC = re.compile(
3234
r"(?:(?P<fill>[\s\S])?(?P<align>[<>=^]))?"
@@ -540,6 +542,15 @@ def shell(*args):
540542
shellFp.write(s)
541543

542544

545+
def add_commanddb_entry(commands, file):
546+
global commandsDb
547+
commandsDb += [{
548+
"directory": os.getcwd(),
549+
"command": (" && ".join(commands)),
550+
"file": file
551+
}
552+
]
553+
543554
def emit_rule(self, ins, outs, cmds=[], label=None):
544555
name = self.name
545556
fins = [self.templateexpand(f) for f in set(filenamesof(ins))]
@@ -558,19 +569,26 @@ def emit_rule(self, ins, outs, cmds=[], label=None):
558569
os.makedirs(self.dir, exist_ok=True)
559570
rule = []
560571

561-
sandbox = join(self.dir, "sandbox")
562-
emit(f"rm -rf {sandbox}", into=rule)
563-
emit(
564-
f"{G.PYTHON} build/_sandbox.py --link -s", sandbox, *fins, into=rule
565-
)
566-
for c in cmds:
567-
emit(f"(cd {sandbox} &&", c, ")", into=rule)
568-
emit(
569-
f"{G.PYTHON} build/_sandbox.py --export -s",
570-
sandbox,
571-
*fouts,
572-
into=rule,
573-
)
572+
if G.AB_SANDBOX == "yes":
573+
sandbox = join(self.dir, "sandbox")
574+
emit(f"rm -rf {sandbox}", into=rule)
575+
emit(
576+
f"{G.PYTHON} build/_sandbox.py --link -s",
577+
sandbox,
578+
*fins,
579+
into=rule,
580+
)
581+
for c in cmds:
582+
emit(f"(cd {sandbox} &&", c, ")", into=rule)
583+
emit(
584+
f"{G.PYTHON} build/_sandbox.py --export -s",
585+
sandbox,
586+
*fouts,
587+
into=rule,
588+
)
589+
else:
590+
for c in cmds:
591+
emit(c, into=rule)
574592

575593
ruletext = "".join(rule)
576594
if len(ruletext) > 7000:
@@ -581,7 +599,7 @@ def emit_rule(self, ins, outs, cmds=[], label=None):
581599
fp.write("set -e\n")
582600
fp.write(ruletext)
583601

584-
emit("build", *fouts, ":rule", *fins, rulef)
602+
emit("build", *fouts, ":rule", *fins)
585603
emit(" command=sh", rulef)
586604
else:
587605
emit("build", *fouts, ":rule", *fins)
@@ -592,7 +610,6 @@ def emit_rule(self, ins, outs, cmds=[], label=None):
592610
if label:
593611
emit(" description=", label)
594612
emit("build", name, ":phony", *fouts)
595-
596613
else:
597614
assert len(cmds) == 0, "rules with no outputs cannot have commands"
598615
emit("build", name, ":phony", *fins)
@@ -608,6 +625,7 @@ def simplerule(
608625
outs: Targets = [],
609626
deps: Targets = [],
610627
commands=[],
628+
add_to_commanddb=False,
611629
label="RULE",
612630
):
613631
self.ins = ins
@@ -623,8 +641,22 @@ def simplerule(
623641

624642
cs = [("mkdir -p %s" % dir) for dir in dirs]
625643

644+
coreCommands = []
626645
for c in commands:
627-
cs += [self.templateexpand(c)]
646+
coreCommands += [self.templateexpand(c)]
647+
cs += coreCommands
648+
649+
if add_to_commanddb:
650+
infiles = filenamesof(ins)
651+
if len(infiles) > 0:
652+
global commandsDb
653+
commandsDb += [
654+
{
655+
"directory": os.getcwd(),
656+
"command": (" && ".join(coreCommands)),
657+
"file": infiles[0],
658+
}
659+
]
628660

629661
emit_rule(
630662
self=self,
@@ -696,8 +728,9 @@ def main():
696728
if "=" in line:
697729
name, value = line.split("=", 1)
698730
G.setdefault(name.strip(), value.strip())
731+
G.setdefault("AB_SANDBOX", "yes")
699732

700-
global ninjaFp, shellFp, outputdir
733+
global ninjaFp, shellFp, jsonFp, outputdir
701734
outputdir = args.outputdir
702735
G.setdefault("OBJ", outputdir)
703736
ninjaFp = open(outputdir + "/build.ninja", "wt")
@@ -721,5 +754,8 @@ def main():
721754
fp.write("ninja-targets =")
722755
fp.write(substituteGlobalVariables(" ".join(outputTargets)))
723756

757+
with open(outputdir + "/compile_commands.json", "wt") as fp:
758+
json.dump(commandsDb, fp)
759+
724760

725761
main()

build/c.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
filenamesof,
77
flatten,
88
simplerule,
9-
emit,
9+
add_commanddb_entry,
1010
G,
1111
)
1212
from build.utils import stripext, collectattrs
@@ -116,6 +116,7 @@ def cfileimpl(self, name, srcs, deps, suffix, commands, label, toolchain, cflags
116116
outs=[outleaf],
117117
label=label,
118118
commands=commands,
119+
add_to_commanddb=True,
119120
args={"cflags": cflags},
120121
)
121122

compile_commands.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

util/ncgg/build.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ def ncgg(self, name, srcs: Targets = [], deps: Targets = [], cflags=[]):
3939
ins=["util/ncgg", cpptable],
4040
outs=["=tables.c", "=tables.h"],
4141
commands=[
42-
"$[ins]",
43-
"mv tables.H $[dir]/tables.h",
44-
"mv tables.c $[dir]/tables.c",
42+
"$[ins[0]] -o $[dir] $[ins[1:]]"
4543
],
4644
label="NCGG",
4745
)

util/ncgg/extern.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
33
* See the copyright notice in the ACK home directory, in the file "Copyright".
44
*/
5-
/* $Id$ */
65

76
extern int wordsize;
87
extern int pointersize;
@@ -31,7 +30,7 @@ extern int allsetno;
3130
extern int inproc;
3231
extern int callproc;
3332
extern int procarg[];
34-
extern int fc1,fc2,fc3,fc4;
33+
extern int fc1, fc2, fc3, fc4;
3534
extern int maxmembers;
3635
extern int regclass;
3736
extern int maxtokensize;
@@ -48,7 +47,7 @@ extern void initemhash(void);
4847
/* error.c */
4948
extern void fatal(const char* s, ...);
5049
extern void error(const char* s, ...);
51-
extern int tabovf(char *string);
50+
extern int tabovf(char* string);
5251

5352
/* output.c */
5453
extern void errorexit(void);
@@ -57,4 +56,11 @@ extern void finishio(void);
5756
extern void statistics(void);
5857

5958
/* strlookup.c */
60-
extern int strlookup(char *str);
59+
extern int strlookup(char* str);
60+
61+
/* Global parameters */
62+
extern int nerrors;
63+
extern int code_in_c;
64+
extern int tabledebug;
65+
extern int verbose;
66+
extern const char* outputdir;

util/ncgg/main.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,18 @@
22
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
33
* See the copyright notice in the ACK home directory, in the file "Copyright".
44
*/
5-
#ifndef NORCSID
6-
static char rcsid[] = "$Id$";
7-
#endif
85

96
#include <stdlib.h>
107
#include <stdio.h>
118
#include "param.h"
129
#include "hall.h"
1310
#include "expr.h"
1411
#include "extern.h"
15-
#include "lookup.h"
1612

17-
char *filename;
13+
char* filename;
1814

19-
int main(int argc, char **argv)
15+
int main(int argc, char** argv)
2016
{
21-
extern int nerrors;
22-
extern int code_in_c;
23-
extern int tabledebug;
24-
extern int verbose;
25-
2617
while (argc > 1 && argv[1][0] == '-')
2718
{
2819
switch (argv[1][1])
@@ -36,6 +27,11 @@ int main(int argc, char **argv)
3627
case 'v':
3728
verbose++;
3829
break;
30+
case 'o':
31+
outputdir = argv[2];
32+
argv++;
33+
argc--;
34+
break;
3935
default:
4036
error("Unknown flag -%c", argv[1][1]);
4137
}

util/ncgg/ncgg.6

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
cgg \- Code table translating utility
66
.SH SYNOPSIS
77
.B ~em/lib.bin/cgg
8-
[-c] [-d] [-v] table
8+
[-c] [-d] [-v] [-o outputdir] table
99
.SH DESCRIPTION
1010
cgg translates a machine description table into the internal
1111
structures needed by em_cg.
@@ -25,8 +25,10 @@ bittable described under the -u option of em_ncg(6).
2525
Give statistics about table usage at end of program.
2626
Normally only the tables that have been used more than 75%
2727
are reported.
28+
.IP -o outputdir
29+
Write the output files to the specified directory.
2830
.SH FILES
29-
tables.H, tables.c
31+
tables.h, tables.c
3032
.br
3133
code If the -c flag was given
3234
.br

0 commit comments

Comments
 (0)