Compiler generates absolute #include paths from .capnp imports with leading /'s.

As specified in https://capnproto.org/language.html#imports and implemented
in the C++ compiler output plugin.
This commit is contained in:
Alex Helfet 2017-03-26 18:43:57 +01:00
parent 6b52d615a2
commit a379aa89ac

View file

@ -1293,7 +1293,11 @@ int main() {
for (j = 0; j < capn_len(file_req.imports); j++) {
struct CodeGeneratorRequest_RequestedFile_Import im;
get_CodeGeneratorRequest_RequestedFile_Import(&im, file_req.imports, j);
str_addf(&HDR, "#include \"%s%s.h\"\n", im.name.str, nameinfix);
// Ignore leading slashes when generating C file #include's.
// This signifies an absolute import in a library directory.
const char *base_path = im.name.str[0] == '/' ? &im.name.str[1] : im.name.str;
str_addf(&HDR, "#include \"%s%s.h\"\n", base_path, nameinfix);
}
str_addf(&HDR, "\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n");