Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 54 additions & 29 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,51 @@
"tasks": [
{
"label": "build: odr (library)",
"type": "shell",
"command": "cmake --build cmake-build-relwithdebinfo --target odr",
"type": "process",
"command": "cmake",
"group": "build",
"problemMatcher": ["$gcc"]
"problemMatcher": ["$gcc"],
"args": ["--build", "cmake-build-relwithdebinfo", "--target", "odr"]
},
{
"label": "build: odr_test",
"type": "shell",
"command": "cmake --build cmake-build-relwithdebinfo --target odr_test",
"type": "process",
"command": "cmake",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"]
"problemMatcher": ["$gcc"],
"args": ["--build", "cmake-build-relwithdebinfo", "--target", "odr_test"]
},
{
"label": "build: translate",
"type": "shell",
"command": "cmake --build cmake-build-relwithdebinfo --target translate",
"type": "process",
"command": "cmake",
"group": "build",
"problemMatcher": ["$gcc"]
"problemMatcher": ["$gcc"],
"args": ["--build", "cmake-build-relwithdebinfo", "--target", "translate"]
},
{
"label": "build: all CLI tools",
"type": "shell",
"command": "cmake --build cmake-build-relwithdebinfo --target translate back_translate meta server",
"type": "process",
"command": "cmake",
"group": "build",
"problemMatcher": ["$gcc"]
"problemMatcher": ["$gcc"],
"args": [
"--build",
"cmake-build-relwithdebinfo",
"--target",
"translate",
"back_translate",
"meta",
"server"
]
},
{
"label": "test: run odr_test (filtered)",
"type": "shell",
"command": "${workspaceFolder}/scripts/run-with-env.sh ./test/odr_test --gtest_filter='${input:gtestFilter}'",
"type": "process",
"command": "${workspaceFolder}/scripts/run-with-env.sh",
"options": {
"cwd": "${workspaceFolder}/cmake-build-relwithdebinfo"
},
Expand All @@ -66,55 +78,68 @@
"kind": "test",
"isDefault": true
},
"problemMatcher": []
"problemMatcher": [],
"args": ["./test/odr_test", "--gtest_filter=${input:gtestFilter}"]
},
{
"label": "cli: translate <input> <output>",
"type": "shell",
"command": "scripts/run-with-env.sh ./cmake-build-relwithdebinfo/cli/translate '${input:translateInput}' '${input:translateOutput}'",
"type": "process",
"command": "${workspaceFolder}/scripts/run-with-env.sh",
"dependsOn": ["build: translate"],
"problemMatcher": []
"problemMatcher": [],
"args": [
"./cmake-build-relwithdebinfo/cli/translate",
"${input:translateInput}",
"${input:translateOutput}"
]
},
{
"label": "compare: reference output (headless)",
"detail": "Runs compare-html in Docker (Firefox headless) against test/data/reference-output. Build + run odr_test first to populate output.",
"type": "shell",
"type": "process",
"command": "test/scripts/compare_output.sh",
"problemMatcher": []
},
{
"label": "compare: reference output (server on :8000)",
"detail": "Runs compare-html-server in Docker; open http://localhost:8000 to inspect diffs interactively. Ctrl-C in the terminal to stop.",
"type": "shell",
"type": "process",
"command": "test/scripts/compare_output_server.sh",
"isBackground": true,
"problemMatcher": []
},
{
"label": "env: regenerate .vscode/.env",
"detail": "Re-run after every `conan install` to refresh Conan cache paths.",
"type": "shell",
"command": "python3 scripts/gen-vscode-env.py",
"problemMatcher": []
"type": "process",
"command": "python3",
"problemMatcher": [],
"args": ["scripts/gen-vscode-env.py"]
},
{
"label": "profile: Instruments Time Profiler (odr_test, filtered)",
"detail": "Records a .trace with Instruments; opens in Instruments.app when done.",
"type": "shell",
"command": "rm -rf profile.trace && ${workspaceFolder}/scripts/run-with-env.sh xctrace record --template 'Time Profiler' --output profile.trace --launch -- ./test/odr_test --gtest_filter='${input:gtestFilter}' && open profile.trace",
"type": "process",
"command": "${workspaceFolder}/scripts/profile.sh",
"options": {
"cwd": "${workspaceFolder}/cmake-build-relwithdebinfo"
},
"dependsOn": ["build: odr_test"],
"problemMatcher": []
"problemMatcher": [],
"args": ["./test/odr_test", "--gtest_filter=${input:gtestFilter}"]
},
{
"label": "profile: Instruments Time Profiler (translate)",
"detail": "Records a .trace of the translate CLI on one file.",
"type": "shell",
"command": "rm -rf profile.trace && scripts/run-with-env.sh xctrace record --template 'Time Profiler' --output profile.trace --launch -- ./cmake-build-relwithdebinfo/cli/translate '${input:translateInput}' '${input:translateOutput}' && open profile.trace",
"type": "process",
"command": "${workspaceFolder}/scripts/profile.sh",
"dependsOn": ["build: translate"],
"problemMatcher": []
"problemMatcher": [],
"args": [
"./cmake-build-relwithdebinfo/cli/translate",
"${input:translateInput}",
"${input:translateOutput}"
]
}
]
}
2 changes: 2 additions & 0 deletions scripts/conan_install
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."

conan install . --output-folder=cmake-build-relwithdebinfo --build=missing -s build_type=RelWithDebInfo -s "&:build_type=RelWithDebInfo"
conan install . --output-folder=cmake-build-debug --build=missing -s build_type=RelWithDebInfo -s "&:build_type=Debug"
Expand Down
2 changes: 2 additions & 0 deletions scripts/conan_lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."

conan lock create .

Expand Down
22 changes: 10 additions & 12 deletions scripts/gen-vscode-env.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#!/usr/bin/env python3
"""Extract the runtime environment from the Conan-generated CMake test preset
into a plain KEY=VALUE file that VS Code launch configs (CodeLLDB `envFile`) and
tasks can consume.
"""Export the Conan test environment for VS Code tasks and CodeLLDB.

The paths point into the Conan cache and change whenever dependencies are
re-installed, so re-run this after every `conan install` (there is a VS Code task
"env: regenerate .vscode/.env" that does exactly this).

Usage: scripts/gen-vscode-env.py [BUILD_DIR]
BUILD_DIR defaults to cmake-build-relwithdebinfo.
Usage: scripts/gen-vscode-env.py [BUILD_DIR]. Regenerate after conan install.
BUILD_DIR defaults to cmake-build-relwithdebinfo.
"""
import json
import os
import re
import shlex
import sys
from pathlib import Path

Expand All @@ -29,14 +24,17 @@


def resolve(value: str) -> str:
# Resolve `$penv{VAR}` (parent/current environment) references to the value
# present when this script runs; CodeLLDB envFile has no variable expansion.
# Resolve CMake parent-environment references before quoting literal values.
return re.sub(r"\$penv\{(\w+)\}", lambda m: os.environ.get(m.group(1), ""), value)


out = repo / ".vscode" / ".env"
out.parent.mkdir(exist_ok=True)
lines = [f"{k}={resolve(v)}" for k, v in env.items()]
for key in env:
if not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", key):
sys.exit(f"invalid environment variable name: {key!r}")
# Single-quote expansion is shared by Bash and CodeLLDB's dotenv reader.
lines = [f"{k}={shlex.quote(resolve(v))}" for k, v in env.items()]
out.write_text("\n".join(lines) + "\n")
print(f"wrote {len(lines)} vars to {out}")
for line in lines:
Expand Down
53 changes: 21 additions & 32 deletions scripts/git_hooks/git-hooks
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function hook_dirs

git rev-parse --git-dir &> /dev/null
if [ $? -eq 0 ]; then
if [ $(git rev-parse --is-bare-repository) = 'false' ]; then
cd $(git rev-parse --show-toplevel)
if [ "$(git rev-parse --is-bare-repository)" = 'false' ]; then
cd "$(git rev-parse --show-toplevel)" || return
echo "${PWD}/scripts/git_hooks${hook}"
fi
fi
Expand All @@ -23,17 +23,13 @@ function list_hooks_in_dir
{
path="${1}"
level="${2}"
find --help 2>&1 | grep -- '-L' 2>/dev/null >/dev/null
if [ $? -eq 1 ] ; then
find "${path}/" -mindepth ${level} -maxdepth ${level} -perm -111 -type f 2>/dev/null | grep -v "^.$" | sort
else
find -L "${path}/" -mindepth ${level} -maxdepth ${level} -perm -111 -type f 2>/dev/null | grep -v "^.$" | sort
fi
find -L "${path}/" -mindepth "${level}" -maxdepth "${level}" \
-perm -111 -type f -print0 2>/dev/null | sort -z
}

function list_hooks
{
GITDIR=`git rev-parse --git-dir`
GITDIR=$(git rev-parse --git-common-dir)
cat "${GITDIR}/hooks/pre-commit" 2> /dev/null | grep 'git-hooks' > /dev/null 2> /dev/null
if [ $? = 0 ]; then
echo "Git hooks ARE installed in this repository."
Expand All @@ -45,14 +41,11 @@ function list_hooks

echo 'Listing Project hooks:'
echo '---'
for dir in `hook_dirs`; do
echo "${dir}:"
for hook in `list_hooks_in_dir "${dir}" 2`; do
echo -n *`basename \`dirname "${hook}"\``
echo -e "/`basename "${hook}"` - `${hook} --about`"
done
echo ""
done
dir="$(hook_dirs)"
echo "${dir}:"
while IFS= read -r -d '' hook; do
echo "*$(basename "$(dirname "${hook}")")/$(basename "${hook}") - $("${hook}" --about)"
done < <(list_hooks_in_dir "${dir}" 2)
}

function run_hooks
Expand All @@ -63,16 +56,14 @@ function run_hooks
return 1
fi
shift 1
for hook in `list_hooks_in_dir "${dir}" 1`
do
export last_run_hook="${hook} $@"
if [ ! -z ${GIT_HOOKS_VERBOSE} ]; then
while IFS= read -r -d '' hook; do
export last_run_hook="${hook} $*"
if [ -n "${GIT_HOOKS_VERBOSE:-}" ]; then
echo -n "@@ Running hook: "
echo -n `basename \`dirname "${hook}"\``
echo "/`basename "${hook}"`"
echo "$(basename "$(dirname "${hook}")")/$(basename "${hook}")"
fi
${hook} "$@"
done
"${hook}" "$@"
done < <(list_hooks_in_dir "${dir}" 1)
}

function run_hook
Expand All @@ -84,12 +75,10 @@ function run_hook
return 1
fi
shift 1
for dir in `hook_dirs "${hook}"`; do
if [ ! -d "${dir}" ] ; then
continue
fi
dir="$(hook_dirs "${hook}")"
if [ -d "${dir}" ]; then
run_hooks "${dir}" "$@"
done
fi
set +e
}

Expand All @@ -113,12 +102,12 @@ function install_hooks_into

function install_hooks
{
GITDIR=`git rev-parse --git-dir`
GITDIR=$(git rev-parse --git-common-dir)
if [ ! $? -eq 0 ]; then
echo "${1} must be run inside a git repository"
return 1
fi
cd "${GITDIR}"
cd "${GITDIR}" || return
if [ "${1}" = "--install" ]; then
if [ -d hooks.old ]; then
echo "hooks.old already exists, perhaps you already installed?"
Expand Down
8 changes: 8 additions & 0 deletions scripts/profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Record the command in Instruments without replacing an earlier trace.
set -euo pipefail
repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
trace="$(mktemp -d "${TMPDIR:-/tmp}/odr-profile.XXXXXX")/profile.trace"
"$repo/scripts/run-with-env.sh" xctrace record --template 'Time Profiler' \
--output "$trace" --launch -- "$@"
open "$trace"
2 changes: 2 additions & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."

# setup git hooks
scripts/git_hooks/git-hooks --install
Expand Down
Loading
Loading