Skip to content

Commit 4ef7c66

Browse files
committed
Fits dependencies compiler into compile-config and -code
It turns out compile-dependencies for generating dataflow.dot and Makefile codegen was a special case, so refactored it into the other two main compilation steps.
1 parent 44bdeee commit 4ef7c66

File tree

7 files changed

+45
-29
lines changed

7 files changed

+45
-29
lines changed

compiler/app-has-been-compiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export DEEPDIVE_APP
1313

1414
[[ $# -gt 0 ]] ||
1515
# default set of expected compilation results
16-
set -- "$DEEPDIVE_APP"/run/{compiled/{{schema,config}.json,Makefile},Makefile,process/}
16+
set -- "$DEEPDIVE_APP"/run/{compiled/{schema,config}.json,Makefile,process/}
1717

1818
for path; do
1919
[[ -e "$path" ]] ||

compiler/compile-dependencies/compile-dependencies2make renamed to compiler/compile-code/compile-code-Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/usr/bin/env jq-f
2-
# compile-dependencies2make -- Generates a GNU Make recipes corresponding to the input dependency graph in JSON
2+
# compile-code-Makefile -- Generates a GNU Makefile with recipes for the compiled processes considering their dependencies
33
##
44

55
def mktarget(suffix): "\(.).\(suffix)";
66
def mktargets(suffix): map(mktarget(suffix)) | join(" ");
77
def mktarget: mktarget("done");
88
def mktargets: mktargets("done");
99

10+
.deepdive_.execution.dependencies |
11+
{ path: "Makefile", content: [
12+
1013
# make variables
1114
"
1215
# default commands
@@ -64,3 +67,5 @@ reset: \(keys | mktargets("reset"))
6467
" else empty end
6568

6669
)
70+
71+
] | join("") }

compiler/compile-dependencies/compile-dependencies2dot renamed to compiler/compile-code/compile-code-dataflow_dot

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env jq-f
2-
# compile-dependencies2dot -- Generates a DOT corresponding to the input dependency graph in JSON
2+
# compile-code-dataflow_dot -- Generates dependency graph of processes in Graphviz DOT language
33
##
44

55
def nodeId: sub("/"; "/\n");
@@ -13,6 +13,8 @@ def nodeType: sub("/.*$"; "");
1313
, model : "shape=septagon color=\"#ffffff\" style=filled fillcolor=\"#cc22cc\""
1414
} as $nodeAttr |
1515

16+
.deepdive_.execution.dependencies |
17+
{ path: "dataflow.dot", content: [
1618
"
1719
digraph \"\(env.DEEPDIVE_APP | sub(".*/"; "")) data flow\" {
1820
graph[rankdir=BT # bottom-to-top drawing (or RL/right-to-left may also make sense)
@@ -51,3 +53,4 @@ end
5153

5254
}
5355
"
56+
] | join("") }

compiler/compile-codegen

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,25 @@
44
# Author: Jaeho Shin <netj@cs.stanford.edu>
55
# Created: 2015-12-05
66
set -euo pipefail
7-
eval "$(jq -r '"
8-
x=\(.path | @sh)
7+
eval "$(jq -r '
8+
@sh "
9+
x=\(.path)
910
echo >&2 \" run/$x\"
10-
mkdir -p \"$(dirname \"$x\")\"
11-
echo \(.content | @sh) >\"$x\"
12-
\(.mode | if . then "chmod \(@sh) \"$x\"" else "" end)
13-
"')"
11+
# ensure parent dir exists
12+
xd=\"$(dirname \"$x\")\"
13+
mkdir -p \"$xd\"
14+
# move existing files/dirs out of the way
15+
if [[ -e \"$x\" ]]; then
16+
chmod +w \"$x\" \"$xd\" || true
17+
mv -f --no-target-directory \"$x\" \"$x\"~
18+
fi
19+
# write contents
20+
echo \(.content) >\"$x\"
21+
"
22+
23+
+ (.mode | if . then @sh "
24+
# adjust mode
25+
chmod \(.) \"$x\""
26+
else ""
27+
end)
28+
')"

compiler/compile-dependencies/compile-config2dependencies renamed to compiler/compile-config/compile-config-9.99-dependencies

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env jq-f
2-
# compile-config2dependencies -- Derives a dependency graph from deepdive.conf in JSON
2+
# compile-config-9.99-dependencies -- Derives a dependency graph for easier Makefile and .dot codegen
33
##
44
.deepdive_ as $deepdive
55

@@ -8,7 +8,8 @@
88
) as $output_relation
99

1010
# form a dependency graph
11-
| [ # every process/* and the processes or input data it depends on
11+
| .deepdive_.execution.dependencies =
12+
( [ # every process/* and the processes or input data it depends on
1213
( $deepdive.execution.processes | to_entries[]
1314
| .value |= ((.dependencies_ // [] | map($output_relation[.] // .)) + .input_ | unique)
1415
)
@@ -25,3 +26,4 @@
2526
# )
2627
]
2728
| from_entries
29+
)

compiler/deepdive-compile

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ ln -sfnv "$compileDir" run/RUNNING.COMPILE >&2
4040
# augment PATH to access compiler components
4141
PATH="$DEEPDIVE_HOME"/util/compile-config:"$PATH"
4242
PATH="$DEEPDIVE_HOME"/util/compile-code:"$PATH"
43-
PATH="$DEEPDIVE_HOME"/util/compile-dependencies:"$PATH"
4443
export DEEPDIVE_ERROR_PREFIX="[ERROR] "
4544

4645
## compile a full deepdive.conf from source code
@@ -128,20 +127,6 @@ ln -sfn "$config" config.json
128127
STEP "Validating run/compiled/config.json:"
129128
deepdive-check -a -c "$PWD"/config.json 'compiled_*' 2>&1 | sed 's/^/ /' >&2
130129

131-
if [[ -z $DEEPDIVE_COMPILE_SKIP_DATAFLOW ]]; then
132-
STEP "Analyzing data flow dependencies to compile:"
133-
# derive a dependency graph from the extractors, factors, pipelines defined in deepdive.conf
134-
compile-config2dependencies <config.json >dependencies.json
135-
# compile a Makefile from the dependency graph
136-
STEP " run/Makefile"
137-
compile-dependencies2make <dependencies.json -r >Makefile
138-
# compile an SVG from the dependency graph
139-
STEP " run/compiled/dataflow.svg"
140-
compile-dependencies2dot <dependencies.json -r >dataflow.dot
141-
dot -Tsvg <dataflow.dot >dataflow.svg
142-
STEP " (file://$(pwd -P)/dataflow.svg)" # XXX a handy file: URL for opening in a browser
143-
fi
144-
145130
STEP "Compiling executable code into:"
146131
# compile extractors and factors under process/ and factor/
147132
for cc in "$DEEPDIVE_HOME"/util/compile-code/compile-code-*; do
@@ -151,17 +136,24 @@ for cc in "$DEEPDIVE_HOME"/util/compile-code/compile-code-*; do
151136
STEP " run/compiled/code-$name.json"
152137
"$cc" config.json >code-$name.json
153138
done
139+
140+
#STEP "Validating run/compiled/code-*.json:"
141+
#deepdive-check -a -c "$PWD"/code-\*.json 'codegen_*' 2>&1 | sed 's/^/ /' >&2
154142
# TODO check path name collisions in code-*.json
143+
155144
# mark everything compiled as read-only
156145
chmod a-w *
157146

158147
if [[ -z $DEEPDIVE_COMPILE_SKIP_CODEGEN ]]; then
159148
# generate actual code under run/
160149
cd "$DEEPDIVE_APP"/run
161-
STEP "Generating executable files:"
150+
STEP "Generating files:"
162151
cat "$compileDir"/code-*.json |
163152
compile-codegen
164-
ln -sfn compiled/Makefile .
153+
# some postprocessing over generated files
154+
dot -Tsvg <dataflow.dot >dataflow.svg
155+
STEP " run/dataflow.svg"
156+
STEP " (file://$(pwd -P)/dataflow.svg)" # XXX a handy file: URL for opening in a browser
165157
fi
166158

167159
# point to the successfully compiled one, leaving the previous one as backup

stage.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ stage .build/submodule/compiler/hocon2json/target/scala-2.10/hocon2json-assembly
5757
stage src/main/resources/application.conf etc/deepdive-default.conf
5858
stage compiler/compile-config util/
5959
stage compiler/compile-check util/
60-
stage compiler/compile-dependencies util/
6160
stage compiler/compile-code util/
6261
stage compiler/compile-codegen util/
6362

0 commit comments

Comments
 (0)