ned14 / pcpp

A C99 preprocessor written in pure Python
Other
215 stars 39 forks source link

Multiple input files doesn't seem to work properly #30

Closed csm10495 closed 5 years ago

csm10495 commented 5 years ago

I think based off the code:

            if len(self.args.inputs) == 1:
                self.parse(self.args.inputs[0])
            else:
                input = ''
                for i in self.args.inputs:
                    input += '#include "' + i.name + '"\n'

It seems to act like the each file is just # included, which is clever, though I always get errors in finding the files like below:

pcpp.exe "C:\Users\csm10495\Source\Repos\IOAndCallbacks\IOAndCallbacks\main.cpp" "C:\Users\csm10495\Source\Repos\IOAndCallbacks\IOAndCallbacks\io.cpp" -D _WIN32 
None:1 error: Include file 'C:\Users\csm10495\Source\Repos\IOAndCallbacks\IOAndCallbacks\main.cpp' not found
#include "C:\Users\csm10495\Source\Repos\IOAndCallbacks\IOAndCallbacks\main.cpp"
None:2 error: Include file 'C:\Users\csm10495\Source\Repos\IOAndCallbacks\IOAndCallbacks\io.cpp' not found
#include "C:\Users\csm10495\Source\Repos\IOAndCallbacks\IOAndCallbacks\io.cpp"

Single inputs seem to work fine

This has to do with it not having a path to look for the file in... we can sort-of cheat to make this work by defaulting:

        self.path = ['/']

in the Preprocessor class, since now we always have a root path to start with and build off of. I guess a potential issue is if you code files in the root, they may get incorrectly included as opposed to the correct one (via -I)

@ned14 is this a valid fix? I'm happy to PR if needed :)

ned14 commented 5 years ago

When checking this, am I correct that multiple input files is completely broken? As in, it just doesn't work at all?

csm10495 commented 5 years ago

Yep. Try it with 2+ input files. Making that change in the Preprocessor class seems to fix it, though it's a bit of a hack.

ned14 commented 5 years ago

Bah. I do apologise. There were problems in this area before which I thought was fixed, but as just demonstrated, not writing a unit test to check for a specific situation means that specific situation breaks. I'll need to write a test specifically for this case, and then fix the bug so it never happens again.

ned14 commented 5 years ago

Turns out that this bug was much bigger than you reported, #include didn't work if no -I had been specified, which was rather serious. Thanks for reporting this bug!