Как конвертировать Makefile awk в BUILD.gn
Оригинальный Makefile вроде
hello2.cc: hello.cc
awk '$1 != "//" { print }' < hello.cc > hello2.cc
Я начну с официального примера GN
git clone --depth=1 https://gn.googlesource.com/gn
cp -a gn/tools/gn/example .
cd example
gn gen out
ninja -C out
convert.sh
#!/bin/bash
echo "1=$1"
echo "2=$2"
awk '$1 != "//" { print }' < "$1" > "$2"
Мой проект BUILD.gn
action("awk") {
script = "convert.sh"
sources = [ "hello.cc" ]
outputs = [ "$target_out_dir/hello2.cc" ]
args = rebase_path(sources, root_build_dir)
# +
# [ rebase_path(target_gen_dir, root_build_dir) ]
}
executable("hello") {
sources = [
"hello2.cc", # I just modify this line
]
deps = [
":hello_shared",
":hello_static",
":awk",
]
}
shared_library("hello_shared") {
sources = [
"hello_shared.cc",
"hello_shared.h",
]
defines = [ "HELLO_SHARED_IMPLEMENTATION" ]
}
static_library("hello_static") {
sources = [
"hello_static.cc",
"hello_static.h",
]
}
Вывод 'ninja -C out -v', означает ли это, что скрипт должен быть только на python?
ninja: Entering directory `out'
[1/4] python ../convert.sh ../hello.cc
FAILED: obj/hello2.cc
python ../convert.sh ../hello.cc
File "../convert.sh", line 2
echo "1=$1"
^
SyntaxError: invalid syntax
ninja: build stopped: subcommand failed.
1 ответ
Решение
Ключевым моментом является сценарий по умолчанию Python. Вот работающие настройки
.gn
buildconfig = "//build/BUILDCONFIG.gn"
script_executable = "/bin/bash" # ADDED this line
Бежать gn gen out
снова измените BUILD.gn как
action("awk") {
script = "convert.sh"
sources = [ "hello.cc" ]
outputs = [ "$target_out_dir/hello2.cc" ]
args = rebase_path(sources, root_build_dir) +
rebase_path(outputs, root_build_dir)
}
executable("hello") {
sources = [
"$target_out_dir/hello2.cc",
]
include_dirs = [ "//" ] # to support #include in original .cc
deps = [
":hello_shared",
":hello_static",
":awk",
]
}
shared_library("hello_shared") {
sources = [
"hello_shared.cc",
"hello_shared.h",
]
defines = [ "HELLO_SHARED_IMPLEMENTATION" ]
}
static_library("hello_static") {
sources = [
"hello_static.cc",
"hello_static.h",
]
}