Author Topic: Running project pre-build steps executing twice  (Read 6617 times)

Orione

  • Guest
Running project pre-build steps executing twice
« on: June 19, 2010, 07:37:02 pm »
Windows Vista, Code::Blocks 10.05

I have a workspace containing 2 projects: Ut (dll) and Test (Win32 console application).
I want to compile Ut project, copy it's target DLL to Test output directory, compile Test.
As I plan to add many more DLL and to use them in other worspaces as well I set in Test pre-build steps:

xcopy /d /y ..\Ut\bin\Debug\Ut.dll .\bin\Debug\.

Build Log follows. As you can see pre-build steps is executed twice and it also seems to be executed as part of Ut project build steps.
I found a similar message in this forum dated April 2008, last reply on April 2009 but no solution seems to have been found.
So does anyone have hints?

...omitted (Ut project file compiled) ...

Creating library file: bin\Debug\libUt.dll.a
Output size is 1.25 MB
Running project pre-build steps
xcopy /d /y ..\Ut\bin\Debug\Ut.dll .\bin\Debug\.
..\Ut\bin\Debug\Ut.dll
1 File copiati
Running project pre-build steps
xcopy /d /y ..\Ut\bin\Debug\Ut.dll .\bin\Debug\.
0 File copiati

-------------- Build: Debug in Test ---------------

...omitted (Test project file compiled) ...

Output size is 916.22 KB
Process terminated with status 0 (0 minutes, 12 seconds)
0 errors, 8 warnings

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Running project pre-build steps executing twice
« Reply #1 on: June 19, 2010, 07:53:59 pm »
Thanks for reporting this.
Happens also here on linux, but seems to happen only if the second project (the one with the prebuild step depends on the first one).
It does not happen if you use per target prebuild steps, what makes sense in your case, because you copy a debug-dll to a debug-application.

I will look into it.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2228
Re: Running project pre-build steps executing twice
« Reply #2 on: June 20, 2010, 12:51:13 am »
I ran across this also: the fix is to CompilerGCC::GetNextStateBasedOnJob as:

Code: [Select]
       case bsProjectDone:
        {
            // switch to next project in workspace
            if (m_pBuildingProject)
                m_pBuildingProject->SetCurrentlyCompilingTarget(0);
            m_NextBuildState = bsProjectPreBuild;
            //(ICC 2010/05/23) CB bug: bsProjectPreBuild being invoked twice
            //return DoBuild(clean, build) >= 0 ? bsProjectPreBuild : bsNone;
            return DoBuild(clean, build) >= 0 ? bsTargetPreBuild : bsNone;
        }

        default:
            break;
    }
    return bsNone;

It should be returning  bsTargetPreBuild, not bsProjectPreBuild.
The return DoBuild() has already done the bsProjectPreBuild, so when it returns
it's time for the bsTargetPreBuild.

And while you're in there ;-)

Code: [Select]
       // create a new process
        m_ProcessOutputFiles[procIndex] = (cmd->isLink && cmd->target) ? cmd->target->GetOutputFilename() : wxString();
        Manager::Get()->GetMacrosManager()->ReplaceMacros(m_ProcessOutputFiles[procIndex]);  //(ICC 2010/06/14)

If the macros aren't replace in the output file name, OnJobEnd will get an open error trying to open such files as "bin/$(FILENAME).exe" etc. when it attempts to report the file size.

« Last Edit: June 20, 2010, 01:08:05 am by Pecan »

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Running project pre-build steps executing twice
« Reply #3 on: June 20, 2010, 01:49:56 am »
Thanks for the hint, it saves me a lot of time.
But I think it should be:

Code: [Select]
        case bsProjectDone:
        {
            // switch to next project in workspace
            if (m_pBuildingProject)
                m_pBuildingProject->SetCurrentlyCompilingTarget(0);
            m_NextBuildState = bsProjectPreBuild;
//            return DoBuild(clean, build) >= 0 ? bsProjectPreBuild : bsNone;
            return DoBuild(clean, build) >= 0 ? (clean && !build?bsTargetClean:bsTargetPreBuild) : bsNone;
        }

        default:
            break;
    }
    return bsNone;

Otherwise it runs the target's prebuild-step on workspace cleaning.
What do you think ?
And it might make it more readable to use a "real" if-statement here.


Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2228
Re: Running project pre-build steps executing twice
« Reply #4 on: June 20, 2010, 02:45:34 pm »
<..snip...>
Code: [Select]
           return DoBuild(clean, build) >= 0 ? (clean && !build?bsTargetClean:bsTargetPreBuild) : bsNone;

Otherwise it runs the target's prebuild-step on workspace cleaning.
What do you think ?
And it might make it more readable to use a "real" if-statement here.

Agreed !

And if you change it to a "real" if-statement, everyone will be better off for it.

« Last Edit: June 20, 2010, 02:50:22 pm by Pecan »

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Running project pre-build steps executing twice
« Reply #5 on: June 21, 2010, 06:05:51 am »
I applied the (modified) patch as svn r6365.
Thanks Pecan !