Author Topic: Compiler generated files bug?  (Read 3779 times)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Compiler generated files bug?
« on: October 20, 2017, 01:39:08 pm »
I want to use protobuf and use advanced compiler options for this.
I use
Code
protoc -I$file_dir --cpp_out=proto $file
for the compiler command. So all source files will be created in the "proto" sub folder of the project
and i use this for the autogenerated files:
Code
proto/$file_name.pb.cc
proto/$file_name.pb.h
But this does not work.
It searches the file in the base path of the project. So ignores the "proto" part of the directory....

i looked into the code and this is quite specious:
Code
         wxFileName tmp 
...
tmp.SetFullName(tool->generatedFiles[i]);
                wxString tmps = tmp.GetFullPath();
                // any macro replacements here, should also be done in
                // CompilerCommandGenerator::GenerateCommandLine !!!
                tmps.Replace(_T("$file_basename"), pf->file.GetName()); // old way - remove later
                tmps.Replace(_T("$file_name"),     pf->file.GetName());
                tmps.Replace(_T("$file_dir"),      pf->file.GetPath());
                tmps.Replace(_T("$file_ext"),      pf->file.GetExt());
                tmps.Replace(_T("$file"),          pf->file.GetFullName());
                Manager::Get()->GetMacrosManager()->ReplaceMacros(tmps);

                ProjectFile* pfile = AddFile(targetIndex, UnixFilename(tmps));

is it a good idea to give wxFileName a string that cans contain "$" charachters? Why not replace the path before passing it to a wxFileName object?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Compiler generated files bug?
« Reply #1 on: October 20, 2017, 07:53:14 pm »
Does it work if you do the replacements before the c-tor of wxfilename?
(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 BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Compiler generated files bug?
« Reply #2 on: October 23, 2017, 09:21:57 pm »
The problem is this line:
Code
tmp.SetFullName(tool->generatedFiles[i]);
it sets only the name of the file, but if you use a path in the generated files this won't work...

My actual solution:
Code
wxString tmps = tmp.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + tool->generatedFiles[i];

i don't know the full logic about all this, but i think this is the better solution instead of the current one...

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Compiler generated files bug?
« Reply #3 on: October 24, 2017, 12:17:13 am »
The logic is that the file is expected to be created in the same directory as the original file.
If you want to create it in a relative path then you need to use a path join operation.
The proposed code could probably work, you should check if setfullname doesn't do anything fancy...

I am not sure if some normalization shouldn't be done after the join. Unfortunately all wxFileName functions are rather expensive, so they should be avoided as much as possible.

Can you open a ticket on sf.net and provide a sample project which is miscompiled with the current version?
(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!]