Author Topic: Arduino - incorrect parsing  (Read 753 times)

Offline zdena

  • Multiple posting newcomer
  • *
  • Posts: 23
Arduino - incorrect parsing
« on: June 10, 2019, 02:59:39 pm »
Hello,
I use C::B for Arduino programming via original Arduino-builder.

During Building I have got all messages from Arduino-builder in the C::B "Build log" tab. On the end are the warnings and errors ?parsed? into the "Build messages" tab. It is still OK. :)

But Arduino-builder works in the (strange) way that:
  • main file (named Project_Name.ino) is copied in some temp\Project_Name\build\sketch\ and renamed to the Projedct_Name.cpp.
  • Other Sources and Headers from the project directory are copied there and from there are all compiled.
  • Another libraries (cpp sources and h headers) stay where they are and are compiled from there.
The problem is that warnings and errors concerning the Sources and Headers from the project directory are refered to the files in temporary directory but not to the original sources. :(

Is there a way (if yes, which way please) how to (conditionally) redirect the output parsing?

Something like this:

   if (warning is from ...\Project_Name\build\sketch\file.cpp)
      then {go to ...\Project_Name\file.cpp }
      else {change nothing}

I expect that "Advanced compiler options -> Output parsing" could solve this, but I'm really not familiar with regular expression unfortunately. :-[

Thanks Zdena
Windows 10 64b
Arduino 1.8.5 with (modified) Arduino Builder 1.4.5 through (modified) C::B 17.12 32b
Occasional C(C++) hobbyist almost only for Arduino.
Czechia - please pardon my English

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11932
    • Travis build status
Re: Arduino - incorrect parsing
« Reply #1 on: June 10, 2019, 08:14:29 pm »
There is not such thing.
You have two options:
1. Start reading the code of the compiler and find where to apply path remapping.
2. Start reading arduino-builder's code and find how to insert #line (https://docs.microsoft.com/en-us/cpp/preprocessor/hash-line-directive-c-cpp?view=vs-2019) directive which will do the remapping and this would work in any IDE. I guess you can try to convince the arduino devs to do this themselves, but I don't know if they would be willing to do this.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline zdena

  • Multiple posting newcomer
  • *
  • Posts: 23
Re: Arduino - incorrect parsing
« Reply #2 on: June 12, 2019, 02:17:48 pm »
Thank you oBFusCATed for your hints.

I thought about it a few days and what about:

  3. Start reading C::B's code and apply path remapping somewhere there?

Is it possible? Or this way is totally wrong?
Windows 10 64b
Arduino 1.8.5 with (modified) Arduino Builder 1.4.5 through (modified) C::B 17.12 32b
Occasional C(C++) hobbyist almost only for Arduino.
Czechia - please pardon my English

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6610
    • My Best Post
Re: Arduino - incorrect parsing
« Reply #3 on: June 12, 2019, 03:42:19 pm »
4. Write a small program the prepends the #line to the start of each temp file created by arduino-builder.

Note: I would first edit one of the temp files to verify whether the #line command works as you want.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11932
    • Travis build status
Re: Arduino - incorrect parsing
« Reply #4 on: June 12, 2019, 07:14:42 pm »
  3. Start reading C::B's code and apply path remapping somewhere there?
This is the same as 1. I've forgotten to mention that I'm talking about the C::B's compiler plugin.
But the chances for this getting included in svn trunk is really slim.
The implementation must be efficient, minimal and clean for this to happen.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline zdena

  • Multiple posting newcomer
  • *
  • Posts: 23
Re: Arduino - incorrect parsing
« Reply #5 on: June 12, 2019, 09:24:10 pm »
4. Write a small program the prepends the #line to the start of each temp file created by arduino-builder.
Good hint. And even no program needed. Just to put the #line directive at the begin of each project source file. For example:
Code: [Select]
#line 2 "D:\\KomplexCB\\_Vysilani_100\\Komplex00\\Adafruit_HDC1000.cpp"And it works 8)  But with complete absolute path only.  :(

I wanted to use builtin variable:
Code: [Select]
#line 2 "$(PROJECT_DIR)Adafruit_HDC1000.cpp"or somehow to make it universal but it doesn't work.
Is it possible to do it? Or the prepocessor doesn't accept C::B variables?

For completeness: If I use
Code: [Select]
#line 2 __FILE__it refers to the temp again
Code: [Select]
C:\Users\zdena\AppData\Local\Temp\Komplex00\build\sketch\Adafruit_HDC1000.cpp
Windows 10 64b
Arduino 1.8.5 with (modified) Arduino Builder 1.4.5 through (modified) C::B 17.12 32b
Occasional C(C++) hobbyist almost only for Arduino.
Czechia - please pardon my English

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2455
Re: Arduino - incorrect parsing
« Reply #6 on: June 12, 2019, 10:32:28 pm »
Variable expansion does not happen in the code, only in command lines....
If you are hardcore you could probably create a squirrel pre build step http://wiki.codeblocks.org/index.php/Scripting_commands
In the attached archive you will find an example project:
Basically it replaces all occurrences of
Code: [Select]
#line $(CURRENTFILENAME)to
Code: [Select]
#line 1 CURRENT_ABSOLUTE_FILENAME
the problem is, this is a onetime shot... It literally replaces the line, so it wont work a second time.
It would probably be possible to create a script that creates temporary files and copy it to somewhere, but this is really out of scope...
The easiest thing would be to modify the arduino builder... i mean, they make the bullshit by copying files around...

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11932
    • Travis build status
Re: Arduino - incorrect parsing
« Reply #7 on: June 13, 2019, 12:31:42 am »
zdena: Sorry but you're solving the wrong problem. Fixing it in arduino-builder would be the most robust and probably easiest solution. Have you talked to arduino devs?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline zdena

  • Multiple posting newcomer
  • *
  • Posts: 23
Re: Arduino - incorrect parsing
« Reply #8 on: June 13, 2019, 01:04:30 pm »
oBFusCATed: You are right. I was afraid to come in the next community and to find how to report an issue, but I agree it will be the most proper way to push the modification of arduino-builder. As also BlueHazzard suggests.

I found just now that the arduino-builder already puts the line with #line direction with absolute path at the beginning of file before copying it to the temporary. But only into the .ino file. So It should be enough to do the same with all source files. If I think correct.

So for sure I will check the behavior of the last arduino-builder versions (including nightlies) and then I ask the developers.

Thank you all for your patience for now.
Windows 10 64b
Arduino 1.8.5 with (modified) Arduino Builder 1.4.5 through (modified) C::B 17.12 32b
Occasional C(C++) hobbyist almost only for Arduino.
Czechia - please pardon my English

Offline zdena

  • Multiple posting newcomer
  • *
  • Posts: 23
Re: Arduino - incorrect parsing
« Reply #9 on: June 21, 2019, 10:00:19 pm »
So, my fabulous friend created issue for the matter, then analysed the sources of the arduino-builder, created pull request for change and finally wrote the patch.

If we are lucky the patch will go to the master branch in this century.

Meanwhile, anybody can build the patched arduino-builder from https://github.com/arduino/arduino-builder/pull/325. It really works.  :)
Windows 10 64b
Arduino 1.8.5 with (modified) Arduino Builder 1.4.5 through (modified) C::B 17.12 32b
Occasional C(C++) hobbyist almost only for Arduino.
Czechia - please pardon my English