Skip to content

Instantly share code, notes, and snippets.

@ichizok
Last active February 18, 2022 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ichizok/ed944b9591a7ae0ce6ef1ea804597bb5 to your computer and use it in GitHub Desktop.
Save ichizok/ed944b9591a7ae0ce6ef1ea804597bb5 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
work_dir=$(mktemp -d)
trap "rm -fr '${work_dir}'" EXIT
if [[ $1 = - ]]; then
build_log=${work_dir}/build.log
tee "${build_log}"
elif [[ -f $1 ]]; then
build_log=$1
fi
if ! [[ -f "$build_log" ]]; then
echo "Usage: $0 build_log" >&2
exit 1
fi
compile_commands_json=${work_dir}/compile_commands.json
compiledb -f -o "${compile_commands_json}" < "${build_log}"
python3 > compile_commands.json <<EOT
import copy
import json
import os
with open('${compile_commands_json}') as fp:
r = json.load(fp)
for item in r:
if item['file'] == 'os_mac_conv.c':
obj = copy.copy(item)
obj['arguments'] = [arg.replace('mac_conv.o', 'macos.o').replace('mac_conv.c', 'macosx.m') for arg in obj['arguments']]
obj['file'] = 'os_macosx.m'
r += [obj]
print(json.dumps(r, indent=1))
EOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment