Skip to content

Commit

Permalink
[refactor] Use common naming convention.
Browse files Browse the repository at this point in the history
NINJA_subgraph.py and NINJA-steps.sh.
  • Loading branch information
Andy C committed Jun 28, 2022
1 parent e671fc9 commit 6958f0a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions build/native-steps.sh → build/NINJA-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Also some non-Ninja wrappers.
#
# Usage:
# build/native-steps.sh <function name>
# build/NINJA-steps.sh <function name>

set -o nounset
set -o errexit
Expand Down Expand Up @@ -225,6 +225,6 @@ strip_() {
}

# test/cpp-unit.sh sources this
if test $(basename $0) = 'native-steps.sh'; then
if test $(basename $0) = 'NINJA-steps.sh'; then
"$@"
fi
14 changes: 7 additions & 7 deletions build/NINJA_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,39 +133,39 @@ def NinjaGraph(n, u):
# Preprocess one translation unit
n.rule('preprocess',
# compile_one detects the _build/preprocessed path
command='build/native-steps.sh compile_one $compiler $variant $in $out',
command='build/NINJA-steps.sh compile_one $compiler $variant $in $out',
description='compile_one $compiler $variant $in $out')
n.newline()

# Preprocess one translation unit
n.rule('line_count',
command='build/native-steps.sh line_count $out $in',
command='build/NINJA-steps.sh line_count $out $in',
description='line_count $out $in')
n.newline()

# 'together' build
n.rule('compile_and_link',
# multiple outputs
command='build/native-steps.sh compile_and_link $compiler $variant $out $in',
command='build/NINJA-steps.sh compile_and_link $compiler $variant $out $in',
description='compile_and_link $compiler $variant $out $in')
n.newline()

# Compile one translation unit
n.rule('compile_one',
command='build/native-steps.sh compile_one $compiler $variant $in $out $out.d',
command='build/NINJA-steps.sh compile_one $compiler $variant $in $out $out.d',
depfile='$out.d',
description='compile_one $compiler $variant $in $out')
n.newline()

# Link objects together
n.rule('link',
command='build/native-steps.sh link $compiler $variant $out $in',
command='build/NINJA-steps.sh link $compiler $variant $out $in',
description='link $compiler $variant $out $in')
n.newline()

# 1 input and 2 outputs
n.rule('strip',
command='build/native-steps.sh strip_ $in $out',
command='build/NINJA-steps.sh strip_ $in $out',
description='strip $in $out')
n.newline()

Expand Down Expand Up @@ -281,7 +281,7 @@ def ShellFunctions(f, argv0):
# Could run with /bin/sh, but use bash for now, bceause dash has bad errors messages!
#!/bin/sh
. build/native-steps.sh
. build/NINJA-steps.sh
main() {
### Compile oil-native into _bin/$compiler-$variant-sh/ (not with ninja)
Expand Down
8 changes: 2 additions & 6 deletions mycpp/build-steps.sh → mycpp/NINJA-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
# Build steps invoked by Ninja.
#
# Usage:
# ./build-steps.sh <function name>
#
# TODO: build/actions.sh should be renamed build/build-steps.sh? "actions"
# implies a side effect, where as "steps" largely know their outputs an outputs
# largely
# mycpp/NINJA-steps.sh <function name>

set -o nounset
set -o pipefail
Expand Down Expand Up @@ -129,7 +125,7 @@ compile() {
# Note: needed -lstdc++ for 'operator new', which we're no longer using. But
# probably exceptions too.

set -x
#set -x
$CXX -o $out $flags -I $REPO_ROOT "$@" -lstdc++
}

Expand Down
26 changes: 13 additions & 13 deletions mycpp/NINJA_subgraph.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python2
"""
mycpp/build_graph.py
mycpp/NINJA_subgraph.py
This is a library invoked by build/native_graph.py.
Code Layout:
mycpp/
build_graph.py # This file describes dependencies programmatically
build-steps.sh # Invoked by Ninja rules
NINJA_subgraph.py # This file describes dependencies programmatically
NINJA-steps.sh # Invoked by Ninja rules
build.sh # wrappers invoked by the Toil and devtools/release.sh
Expand Down Expand Up @@ -185,46 +185,46 @@ def NinjaGraph(n, u):
description='touch $out')
n.newline()
n.rule('asdl-mypy',
command='mycpp/build-steps.sh asdl-mypy $in $out',
command='mycpp/NINJA-steps.sh asdl-mypy $in $out',
description='asdl-mypy $in $out')
n.newline()
n.rule('asdl-cpp',
command='mycpp/build-steps.sh asdl-cpp $in $out_prefix',
command='mycpp/NINJA-steps.sh asdl-cpp $in $out_prefix',
description='asdl-cpp $in $out_prefix')
n.newline()
n.rule('translate',
command='mycpp/build-steps.sh translate $out $in',
command='mycpp/NINJA-steps.sh translate $out $in',
description='translate $out $in')
n.newline()
n.rule('wrap-cc',
command='mycpp/build-steps.sh wrap-cc $name $in $preamble_path $out',
command='mycpp/NINJA-steps.sh wrap-cc $name $in $preamble_path $out',
description='wrap-cc $name $in $preamble_path $out')
n.newline()
n.rule('compile',
# note: $in can be MULTIPLE files, shell-quoted
command='mycpp/build-steps.sh compile $variant $out $more_cxx_flags $in',
command='mycpp/NINJA-steps.sh compile $variant $out $more_cxx_flags $in',
description='compile $variant $out $more_cxx_flags $in')
n.newline()
n.rule('task',
# note: $out can be MULTIPLE FILES, shell-quoted
command='mycpp/build-steps.sh task $in $out',
command='mycpp/NINJA-steps.sh task $in $out',
description='task $in $out')
n.newline()
n.rule('example-task',
# note: $out can be MULTIPLE FILES, shell-quoted
command='mycpp/build-steps.sh example-task $name $impl $bin $out',
command='mycpp/NINJA-steps.sh example-task $name $impl $bin $out',
description='example-task $name $impl $bin $out')
n.newline()
n.rule('typecheck',
command='mycpp/build-steps.sh typecheck $main_py $out $skip_imports',
command='mycpp/NINJA-steps.sh typecheck $main_py $out $skip_imports',
description='typecheck $main_py $out $skip_imports')
n.newline()
n.rule('logs-equal',
command='mycpp/build-steps.sh logs-equal $out $in',
command='mycpp/NINJA-steps.sh logs-equal $out $in',
description='logs-equal $out $in')
n.newline()
n.rule('benchmark-table',
command='mycpp/build-steps.sh benchmark-table $out $in',
command='mycpp/NINJA-steps.sh benchmark-table $out $in',
description='benchmark-table $out $in')
n.newline()

Expand Down
2 changes: 1 addition & 1 deletion mycpp/examples.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# examples.sh: Hooks for specific files

# COPIED FROM DEFUNCT run.sh. Because some examples require it. NOT
# TESTED. TODO: Fold this into Ninja's build-steps.sh.
# TESTED. TODO: Delete after it runs under Ninja.

# -I with ASDL files.
compile-with-asdl() {
Expand Down
10 changes: 6 additions & 4 deletions test/cpp-unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -o nounset
set -o pipefail
set -o errexit

source build/native-steps.sh # for compile_and_link function
source build/NINJA-steps.sh # for compile_and_link function

# https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer
export ASAN_OPTIONS='detect_leaks=0'
Expand All @@ -28,7 +28,11 @@ readonly UNIT_TESTS_SRC=(
mycpp/mylib.cc # TODO: port to mylib2!
)

# TODO: fold these two variants into Ninja
# Note: It would be nice to fold these 2 variants into Ninja, but we don't have
# fine-grained dependencies for say _build/cpp/arg_types.cc and
# cpp/frontend_flag_spec.cc.
#
# Ditto with the tests in asdl/test.sh.

cpp-unit-tests-asan() {
### Run unit tests in the cpp/ dir
Expand All @@ -51,8 +55,6 @@ cpp-unit-tests() {
"${UNIT_TESTS_SRC[@]}" \
cpp/dumb_alloc.cc

#gdb --args $bin "$@"

$bin "$@"
}

Expand Down

0 comments on commit 6958f0a

Please sign in to comment.