online-judge-tools / verification-helper

a testing framework for snippet libraries used in competitive programming

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

oj-bundle で `#include "atcoder/fenwicktree"` のような include が展開されない

kjnh10 opened this issue · comments

commented

またac-libraryに関しては(自作ライブラリについても同様ですが)expander.pyで展開出来る呼び出し方法を展開できないので少し修正した方が良いかもしれません。

これは重要な指摘ですね。これは気付いていませんでした。

  • #include <atcoder/fenwicktree.hpp> が展開されないのは仕様です。競プロ用途ならこれは妥当な仕様だと考えていますが、不便だと感じるユーザが多いなら ac-library 専用に特殊なオプションを足すなどはありだとは思います。
  • #include "atcoder/fenwicktree" が展開されないのはバグです。これはかなり不便なので、はやめに直しておくべきでしょう。

@kjnh10 このふたつについて issue を建てておくのを任せていいですか?

Originally posted by @kmyk in #336 (comment)

commented

後者に関しては拡張子がないとg++がそのファイルのprecompileをやめるのが原因のようです。

g++に何か適当なオプションを渡せばprecompileが走るようになるならこれが一番よさそうですが、
そうでない場合はテンポラリに.hpp付きのファイルを作ってそれをprecompileするようにすればできそうです。

@kjnh10 issue の作成ありがとうございます。
ところで、#336 (comment) のふたつのうち、前者は「仕様の修正の提案」であり、後者は「バグの報告」です。これらの異なる 2 種類のものをまとめて話すと面倒 (#340 (comment) でも「後者に関しては」などのような限定が必要になってる、"bug" などの label が貼りにくい) ので、この issue では後者についてのみ議論することにさせてください。


(後者について、) 手元で試すと再現しませんでした。以下のように、拡張子がないファイルについても適切に動作しているように見えます。
@kjnh10 バグを再現させるための具体的な手順を教えてもらえますか?

$ cat foo.cpp 
#include "bar"
world
$ cat bar
hello
$ oj-bundle foo.cpp > foo.bundled.cpp
INFO:onlinejudge_verify.config:config file loaded: .verify-helper/config.toml: {'languages': {'awk': {'compile': "bash -c 'echo hello > {tempdir}/hello'", 'execute': 'env AWKPATH={basedir} awk -f {path}', 'bundle': 'false', 'list_dependencies': 'sed \'s/^@include "\\(.*\\)"$/\\1/ ; t ; d\' {path}'}}}
WARNING:onlinejudge_verify.languages.list:config.toml: languages.awk: Adding new languages using `config.toml` is supported but not recommended. Please consider making pull requests for your languages, see https://github.com/kmyk/online-judge-verify-helper/issues/116
DEBUG:onlinejudge_verify.languages.cplusplus_bundle:foo.cpp: line 1: #include "bar"
g++: warning: /home/user/GitHub/online-judge-verify-helper/bar: linker input file unused because linking not done
$ cat foo.bundled.cpp 
#line 1 "bar"
hello
#line 2 "foo.cpp"
world
commented

main.cpp

#include "bar"

bar

#include "./bar.hpp"

bar.hpp

hello

とすると再現しないでしょうか?

get_uncommented_codeが以下のメッセージを吐いているのが原因だと思います。
g++: warning: /home/koji0708/go/src/github.com/kjnh10/pcl/library/cpp/include/bar: linker input file unused because linking not done

GCC は C++ のみのコンパイラではないという事情のため、拡張子がないから言語判別ができずに壊れているようですね。
-x c++ とかを付けると直りそう (https://askubuntu.com/a/380563)

$ cat foo.cpp
#include "bar"

$ cat bar
#include "./baz.hpp"

$ cat baz.hpp
hello

$ oj-bundle foo.cpp > foo.bundled.cpp
INFO:onlinejudge_verify.config:config file loaded: .verify-helper/config.toml: {'languages': {'awk': {'compile': "bash -c 'echo hello > {tempdir}/hello'", 'execute': 'env AWKPATH={basedir} awk -f {path}', 'bundle': 'false', 'list_dependencies': 'sed \'s/^@include "\\(.*\\)"$/\\1/ ; t ; d\' {path}'}}}
WARNING:onlinejudge_verify.languages.list:config.toml: languages.awk: Adding new languages using `config.toml` is supported but not recommended. Please consider making pull requests for your languages, see https://github.com/kmyk/online-judge-verify-helper/issues/116
DEBUG:onlinejudge_verify.languages.cplusplus_bundle:foo.cpp: line 1: #include "bar"
g++: warning: /home/user/GitHub/online-judge-verify-helper/bar: linker input file unused because linking not done

$ cat foo.bundled.cpp 
#line 1 "bar"
#include "./baz.hpp"
#line 2 "foo.cpp"

$ g++ -fpreprocessed -dD -E bar 
g++: warning: bar: linker input file unused because linking not done

$ g++ -x c++ -fpreprocessed -dD -E bar
# 1 "bar"
#include "./baz.hpp"

#341 によって解決したので close