Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IWYU fails to compile hpp file, with error unable to handle compilation, expected exactly one compiler job in #1247

Closed
vikramojha89 opened this issue Apr 21, 2023 · 8 comments

Comments

@vikramojha89
Copy link

vikramojha89 commented Apr 21, 2023

While trying to run IWYU on hpp file, its giving above issue "unable to handle compilation, expected exactly one compiler job in"

The problem is it copies duplicate command, In log I can see it has two path for iwyu copied twice

Below is snippet for output
"/path/iwyu/iwyu-0.16/install/glnxa64/bin/include-what-you-use" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "foo.hpp" "some_other_compiler_options" "c++header" "foo.cpp" ; "/path/iwyu/iwyu-0.16/install/glnxa64/bin/include-what-you-use" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "foo.hpp" "some_other_compiler_options" "c++header" "foo.cpp" ;

Reproduction steps

foo.hpp

`#include
#include

int prettyprint();

void foo();`

Command used

python iwyu_tool.py -j12 -o iwyu -p compile_commands.json foo.hpp

Compiler

clang -12
OS: Debian 11

Include-what-you-use

clang version 12.0.1
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir:
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@MX32
Selected multilib: .;@m64

@vikramojha89 vikramojha89 changed the title IWYU fails to fails to compile hpp file, unable to handle compilation, expected exactly one compiler job in IWYU fails to compile hpp file, with error unable to handle compilation, expected exactly one compiler job in Apr 21, 2023
@kimgr
Copy link
Contributor

kimgr commented Apr 21, 2023

iwyu_tool.py just reads compile_commands.json, looks up the input filename and invokes include-what-you-use with the corresponding compile command. So I suspect your compile_command.json has that double-command in it for foo.hpp. How did you generate it? The ; separator makes me think CMake?

@vikramojha89
Copy link
Author

vikramojha89 commented Apr 22, 2023

I tried debugging iwyu_tool.py here inside main

invocations = [ Invocation.from_compile_command(e, extra_args) for e in compilation_db ]

invocations.command returns exactly one command to execute. Same is sent to execute function, during execution somehow its not doing it right.

Just to add this runs fine if I use cpp file, instead of hpp file, I see only one iwyu executable path.

@kimgr
Copy link
Contributor

kimgr commented Apr 22, 2023

Does it make any difference if you leave out -j12?

Could you show the entry from the compilation database for foo.hpp?

@vikramojha89
Copy link
Author

vikramojha89 commented Apr 25, 2023

Hi Kim,

Without -j option also it didn't work.

I was manually creating a compile_commands.json by fetching compiler options, filename and directory. (This works for *.cpp file)

I now used a compdb to genreate compile_commands .json for hpp file, it runs but still it doesn't give proper output

Compile_commands.json

[
{
  "directory": "exploring-cpp-modules/iwyu/build",
  "command": "/usr/bin/c++ -std=gnu++11 -o CMakeFiles/Foo.dir/foo.cxx.o -c exploring-cpp-modules/iwyu/foo.cxx",
  "file": "exploring-cpp-modules/iwyu/foo.cxx",
  "output": "CMakeFiles/Foo.dir/foo.cxx.o"
},

{
  "directory": "exploring-cpp-modules/iwyu/build",
  "command": "/usr/bin/c++ -std=gnu++11 -c exploring-cpp-modules/iwyu/foo.hpp",
  "file": "exploring-cpp-modules/iwyu/foo.hpp"
}
]

CMake

cmake_minimum_required(VERSION 3.10)

project(Foo)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED true)


add_executable(Foo foo.cxx)
target_link_libraries(Foo foo.hpp)

Source File

foo.cxx

#include "foo.hpp"

void prettyprint() {
    std::cout<<"Hello";
}

void foo() {
    std::cout<<"foo";
}

int main() {
    return 0;
}

foo.hpp

#include <vector>
#include <iostream>

void prettyprint();

void foo();

@kimgr
Copy link
Contributor

kimgr commented Apr 26, 2023

it runs but still it doesn't give proper output

What does this mean? Can you show the output you get?

@vikramojha89
Copy link
Author

vikramojha89 commented Apr 27, 2023

ya sorry I missed the output

In file included from exploring-cpp-modules/iwyu/foo.hpp:1: In file included from /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/vector:64: In file included from /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/allocator.h:46: In file included from /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10/bits/c++allocator.h:33: In file included from /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/ext/new_allocator.h:33: In file included from /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/new:41: In file included from /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/exception:147: In file included from /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/exception_ptr.h:38: /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/cxxabi_init_exception.h:38:10: fatal error: 'stddef.h' file not found #include <stddef.h> ^~~~~~~~~~

@kimgr
Copy link
Contributor

kimgr commented Apr 27, 2023

@kimgr
Copy link
Contributor

kimgr commented May 23, 2023

This turned into a duplicate of #100. Closing.

@kimgr kimgr closed this as completed May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants