1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 03:53:21 +02:00

[Bug 340300] Fix parallel make when using pre-build steps

Pre-build will always run in parallel to compilation of source files
unless each and every source file depends on pre-build. Also, when
parallel build was enabled, the "Make build target" under "Workbench
Build Behavior" was ignored. Instead of doing make -j all, Eclipse ran
make -j pre-build main-build. While the intentions are good, make will
attempt to build pre-build and main-build in parallel for previous
stated reasons.

This patch changes two things:

1. Eclipse will consistently respect the "Workbench Build Behavior" for
both single- and multi-process build.
2. The generated makefile is changed to guarantee pre-build is run
first.

   Changed from

       all: pre-build main-build

   to

       all:
           $(MAKE) --no-print-directory pre-build
           $(MAKE) --no-print-directory main-build

Change-Id: Icf3a1057ee3b3cc8a04a433820492a4f469e17dd
Signed-off-by: Morten Kristiansen <millibit@gmail.com>
This commit is contained in:
Morten Kristiansen 2016-12-25 15:58:07 +01:00 committed by Jonah Graham
parent 425e72de58
commit 10428dd53a
3 changed files with 26 additions and 45 deletions

View file

@ -34,7 +34,9 @@ endif
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
# All Target # All Target
all: pre-build main-build all:
$(MAKE) --no-print-directory pre-build
$(MAKE) --no-print-directory main-build
# Main-build Target # Main-build Target
main-build: preAndPostBuildSteps main-build: preAndPostBuildSteps

View file

@ -160,27 +160,6 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
} }
protected String[] getTargets(int kind, IBuilder builder) { protected String[] getTargets(int kind, IBuilder builder) {
String targetsArray[] = null;
if(kind != IncrementalProjectBuilder.CLEAN_BUILD && !builder.isCustomBuilder() && builder.isManagedBuildOn()){
IConfiguration cfg = builder.getParent().getParent();
String preBuildStep = cfg.getPrebuildStep();
try {
preBuildStep = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(
preBuildStep,
"", //$NON-NLS-1$
" ", //$NON-NLS-1$
IBuildMacroProvider.CONTEXT_CONFIGURATION,
cfg);
} catch (BuildMacroException e) {
}
if(preBuildStep != null && preBuildStep.length() != 0){
targetsArray = new String[]{"pre-build", "main-build"}; //$NON-NLS-1$ //$NON-NLS-2$
}
}
if(targetsArray == null){
String targets = ""; //$NON-NLS-1$ String targets = ""; //$NON-NLS-1$
switch (kind) { switch (kind) {
case IncrementalProjectBuilder.AUTO_BUILD : case IncrementalProjectBuilder.AUTO_BUILD :
@ -195,8 +174,8 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
break; break;
} }
targetsArray = CommandLineUtil.argumentsToArray(targets); String targetsArray[] = CommandLineUtil.argumentsToArray(targets);
}
return targetsArray; return targetsArray;
} }

View file

@ -1349,7 +1349,9 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator2 {
} }
*/ */
// If a prebuild step exists, redefine the all target to be // If a prebuild step exists, redefine the all target to be
// all: {pre-build} main-build // all:
// $(MAKE) pre-build
// $(MAKE) main-build
// and then reset the "traditional" all target to main-build // and then reset the "traditional" all target to main-build
// This will allow something meaningful to happen if the generated // This will allow something meaningful to happen if the generated
// makefile is // makefile is
@ -1361,17 +1363,15 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator2 {
// Add the comment for the "All" target // Add the comment for the "All" target
buffer.append(COMMENT_SYMBOL).append(WHITESPACE).append(ManagedMakeMessages.getResourceString(ALL_TARGET)).append(NEWLINE); buffer.append(COMMENT_SYMBOL).append(WHITESPACE).append(ManagedMakeMessages.getResourceString(ALL_TARGET)).append(NEWLINE);
buffer.append(defaultTarget).append(WHITESPACE); // Invoke make multiple times to ensure pre-build is executed before main-build
buffer.append(PREBUILD).append(WHITESPACE); buffer.append(defaultTarget).append(NEWLINE);
buffer.append(TAB).append(MAKE).append(WHITESPACE).append(NO_PRINT_DIR).append(WHITESPACE).append(PREBUILD).append(NEWLINE);
// Reset defaultTarget for now and for subsequent use, below buffer.append(TAB).append(MAKE).append(WHITESPACE).append(NO_PRINT_DIR).append(WHITESPACE).append(MAINBUILD).append(NEWLINE);
defaultTarget = MAINBUILD; buffer.append(NEWLINE);
buffer.append(defaultTarget);
// Update the defaultTarget, main-build, by adding a colon, which is // Update the defaultTarget, main-build, by adding a colon, which is
// needed below // needed below
defaultTarget = defaultTarget.concat(COLON); defaultTarget = MAINBUILD.concat(COLON);
buffer.append(NEWLINE).append(NEWLINE);
// Add the comment for the "main-build" target // Add the comment for the "main-build" target
buffer.append(COMMENT_SYMBOL).append(WHITESPACE).append(ManagedMakeMessages.getResourceString(MAINBUILD_TARGET)).append(NEWLINE); buffer.append(COMMENT_SYMBOL).append(WHITESPACE).append(ManagedMakeMessages.getResourceString(MAINBUILD_TARGET)).append(NEWLINE);