1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 259768: "Use optimal jobs number" highly misleading.

Builder.getParallelizationNum() to return always positive value
This commit is contained in:
Andrew Gvozdev 2011-11-14 13:12:38 -05:00
parent 7f438e269a
commit f04bd57f83
8 changed files with 176 additions and 177 deletions

View file

@ -14,7 +14,6 @@ import org.eclipse.cdt.core.settings.model.ICMultiItemsHolder;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue;
import org.eclipse.cdt.managedbuilder.internal.core.Builder; import org.eclipse.cdt.managedbuilder.internal.core.Builder;
import org.eclipse.cdt.newmake.core.IMakeCommonBuildInfo;
/** /**
* This class is to combine multiple configurations to one to support * This class is to combine multiple configurations to one to support
@ -26,12 +25,13 @@ import org.eclipse.cdt.newmake.core.IMakeCommonBuildInfo;
public interface IMultiConfiguration extends IConfiguration, ICMultiItemsHolder { public interface IMultiConfiguration extends IConfiguration, ICMultiItemsHolder {
/** /**
* Check if the configuration's builder is operating in parallel mode. * Check if all configurations' builders are operating in parallel mode.
* @return {@code true} if parallel mode is enabled, {@code false} otherwise. * @return {@code true} if parallel mode is enabled for all configurations,
* {@code false} otherwise.
*/ */
boolean getParallelDef(); boolean getParallelDef();
/** /**
* Set parallel execution mode for the configuration's builder. * Set same parallel execution mode for all configurations' builders.
* @see Builder#setParallelBuildOn(boolean) * @see Builder#setParallelBuildOn(boolean)
* *
* @param parallel - the flag to enable or disable parallel mode. * @param parallel - the flag to enable or disable parallel mode.
@ -39,18 +39,16 @@ public interface IMultiConfiguration extends IConfiguration, ICMultiItemsHolder
void setParallelDef(boolean parallel); void setParallelDef(boolean parallel);
/** /**
* Returns maximum number of parallel threads/jobs used by the configuration's builder. * Returns maximum number of parallel threads/jobs used by the configurations' builders.
* Note that this function can return negative value to indicate "optimal" number.
*
* @see #setParallelDef(boolean) * @see #setParallelDef(boolean)
* @see Builder#getParallelizationNum()
* *
* @return - maximum number of parallel threads or jobs used by the builder or negative number. * @return - maximum number of parallel threads or jobs used by each builder or 0 if the numbers
* For exact interpretation see table in {@link IMakeCommonBuildInfo#getParallelizationNum()} * don't match.
*/ */
int getParallelNumber(); int getParallelNumber();
/** /**
* Sets maximum number of parallel threads/jobs to be used by builder. * Sets maximum number of parallel threads/jobs to be used by each builder.
* Note that the number will be set only if the builder is in "parallel" * Note that the number will be set only if the builder is in "parallel"
* mode. * mode.
* *
@ -61,10 +59,9 @@ public interface IMultiConfiguration extends IConfiguration, ICMultiItemsHolder
void setParallelNumber(int jobs); void setParallelNumber(int jobs);
/** /**
* returns the Internal Builder parallel mode * Check if all configurations' internal builders are operating in parallel mode.
* if true, internal builder will work in parallel mode * @return {@code true} if parallel mode is enabled for all configurations,
* otherwise it will use only one thread * {@code false} otherwise.
* @return boolean
* *
* @deprecated since CDT 9.0. Use {@link #getParallelDef()} * @deprecated since CDT 9.0. Use {@link #getParallelDef()}
*/ */

View file

@ -65,7 +65,7 @@ public class InternalBuildRunner extends AbstractBuildRunner {
public boolean invokeBuild(int kind, IProject project, IConfiguration configuration, public boolean invokeBuild(int kind, IProject project, IConfiguration configuration,
IBuilder builder, IConsole console, IMarkerGenerator markerGenerator, IBuilder builder, IConsole console, IMarkerGenerator markerGenerator,
IncrementalProjectBuilder projectBuilder, IProgressMonitor monitor) throws CoreException { IncrementalProjectBuilder projectBuilder, IProgressMonitor monitor) throws CoreException {
boolean isParallel = Math.abs(builder.getParallelizationNum()) > 1; boolean isParallel = builder.getParallelizationNum() > 1;
// boolean buildIncrementaly = true; // boolean buildIncrementaly = true;
boolean resumeOnErr = !builder.isStopOnError(); boolean resumeOnErr = !builder.isStopOnError();

View file

@ -206,7 +206,7 @@ public class ParallelBuilder {
if(cwd == null) cwd = des.getDefaultBuildDirLocation(); if(cwd == null) cwd = des.getDefaultBuildDirLocation();
int threads = 1; int threads = 1;
if (cfg instanceof Configuration) { if (cfg instanceof Configuration) {
threads = Math.abs(((Configuration)cfg).getParallelNumber()); threads = ((Configuration)cfg).getParallelNumber();
} }
ParallelBuilder builder = new ParallelBuilder(cwd, dirs, out, err, monitor, resumeOnErrors, buildIncrementally); ParallelBuilder builder = new ParallelBuilder(cwd, dirs, out, err, monitor, resumeOnErrors, buildIncrementally);
builder.enqueueAll(des); builder.enqueueAll(des);

View file

@ -67,6 +67,7 @@ import org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator;
import org.eclipse.cdt.newmake.core.IMakeCommonBuildInfo; import org.eclipse.cdt.newmake.core.IMakeCommonBuildInfo;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
@ -123,7 +124,7 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
// parallelization // parallelization
private String parallelBuildCmd; private String parallelBuildCmd;
private Boolean isParallelBuildEnabled; private Boolean isParallelBuildEnabled;
private Integer parallelJobsNumber; // negative number denotes "optimal" value, see getOptimalParallelJobNum() private Integer parallelNumberAttribute; // negative number denotes "optimal" value, see getOptimalParallelJobNum()
private boolean isTest; private boolean isTest;
@ -331,7 +332,7 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
ignoreErrCmd = builder.ignoreErrCmd; ignoreErrCmd = builder.ignoreErrCmd;
isParallelBuildEnabled = builder.isParallelBuildEnabled; isParallelBuildEnabled = builder.isParallelBuildEnabled;
parallelJobsNumber = builder.parallelJobsNumber; parallelNumberAttribute = builder.parallelNumberAttribute;
parallelBuildCmd = builder.parallelBuildCmd; parallelBuildCmd = builder.parallelBuildCmd;
if(builder.outputEntries != null){ if(builder.outputEntries != null){
@ -381,9 +382,9 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
} catch (CoreException e) { } catch (CoreException e) {
} }
} }
if (getParallelizationNum() != builder.getParallelizationNum() && supportsParallelBuild()) { if (getParallelizationNumAttribute() != builder.getParallelizationNumAttribute() && supportsParallelBuild()) {
try { try {
setParallelizationNum(builder.getParallelizationNum()); setParallelizationNum(builder.getParallelizationNumAttribute());
} catch (CoreException e) { } catch (CoreException e) {
} }
} }
@ -631,29 +632,29 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
private void decodeParallelizationNumber(String value) { private void decodeParallelizationNumber(String value) {
if (VALUE_OPTIMAL.equals(value)) { if (VALUE_OPTIMAL.equals(value)) {
parallelJobsNumber = -getOptimalParallelJobNum(); parallelNumberAttribute = -getOptimalParallelJobNum();
} else if (VALUE_UNLIMITED.equals(value)) { } else if (VALUE_UNLIMITED.equals(value)) {
if (!isInternalBuilder()) { if (!isInternalBuilder()) {
parallelJobsNumber = Integer.MAX_VALUE; parallelNumberAttribute = Integer.MAX_VALUE;
} else { } else {
ManagedBuilderCorePlugin.error("'unlimited' number of jobs is not allowed for Internal Builder, switching to 'optimal'"); ManagedBuilderCorePlugin.error("'unlimited' number of jobs is not allowed for Internal Builder, switching to 'optimal'");
parallelJobsNumber = -getOptimalParallelJobNum(); parallelNumberAttribute = -getOptimalParallelJobNum();
} }
} else { } else {
try { try {
parallelJobsNumber = Integer.decode(value); parallelNumberAttribute = Integer.decode(value);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
ManagedBuilderCorePlugin.log(e); ManagedBuilderCorePlugin.log(e);
parallelJobsNumber = getOptimalParallelJobNum(); parallelNumberAttribute = getOptimalParallelJobNum();
} }
if (parallelJobsNumber <= 0) { if (parallelNumberAttribute <= 0) {
// compatibility with legacy representation - it was that inconsistent // compatibility with legacy representation - it was that inconsistent
if (isInternalBuilder()) { if (isInternalBuilder()) {
// "optimal" for Internal Builder // "optimal" for Internal Builder
parallelJobsNumber = -getOptimalParallelJobNum(); parallelNumberAttribute = -getOptimalParallelJobNum();
} else { } else {
// unlimited for External Builder // unlimited for External Builder
parallelJobsNumber = Integer.MAX_VALUE; parallelNumberAttribute = Integer.MAX_VALUE;
} }
} }
} }
@ -918,8 +919,8 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
if (isParallelBuildEnabled != null) if (isParallelBuildEnabled != null)
element.setAttribute(ATTRIBUTE_PARALLEL_BUILD_ON, isParallelBuildEnabled.toString()); element.setAttribute(ATTRIBUTE_PARALLEL_BUILD_ON, isParallelBuildEnabled.toString());
if (isParallelBuildOn() && parallelJobsNumber != null) if (isParallelBuildOn() && parallelNumberAttribute != null)
element.setAttribute(ATTRIBUTE_PARALLELIZATION_NUMBER, encodeParallelizationNumber(parallelJobsNumber)); element.setAttribute(ATTRIBUTE_PARALLELIZATION_NUMBER, encodeParallelizationNumber(parallelNumberAttribute));
// Note: build file generator cannot be specified in a project file because // Note: build file generator cannot be specified in a project file because
// an IConfigurationElement is needed to load it! // an IConfigurationElement is needed to load it!
@ -1016,8 +1017,8 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
if (isParallelBuildEnabled != null) if (isParallelBuildEnabled != null)
element.setAttribute(ATTRIBUTE_PARALLEL_BUILD_ON, isParallelBuildEnabled.toString()); element.setAttribute(ATTRIBUTE_PARALLEL_BUILD_ON, isParallelBuildEnabled.toString());
if (isParallelBuildOn() && parallelJobsNumber != null) if (isParallelBuildOn() && parallelNumberAttribute != null)
element.setAttribute(ATTRIBUTE_PARALLELIZATION_NUMBER, encodeParallelizationNumber(parallelJobsNumber)); element.setAttribute(ATTRIBUTE_PARALLELIZATION_NUMBER, encodeParallelizationNumber(parallelNumberAttribute));
// Note: build file generator cannot be specified in a project file because // Note: build file generator cannot be specified in a project file because
// an IConfigurationElement is needed to load it! // an IConfigurationElement is needed to load it!
@ -1095,10 +1096,11 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
public String getArguments() { public String getArguments() {
String args = getArgumentsAttribute(); String args = getArgumentsAttribute();
String stopOnErrCmd = getStopOnErrCmd(isStopOnError()); String stopOnErrCmd = getStopOnErrCmd(isStopOnError());
String parallelCmd = isParallelBuildOn() ? getParallelizationCmd(getParallelizationNum()) : EMPTY_STRING; int parallelNum = getParallelizationNum();
String parallelCmd = isParallelBuildOn() ? getParallelizationCmd(parallelNum) : EMPTY_STRING;
String reversedStopOnErrCmd = getStopOnErrCmd(!isStopOnError()); String reversedStopOnErrCmd = getStopOnErrCmd(!isStopOnError());
String reversedParallelBuildCmd = !isParallelBuildOn() ? getParallelizationCmd(getParallelizationNum()) : EMPTY_STRING; String reversedParallelBuildCmd = !isParallelBuildOn() ? getParallelizationCmd(parallelNum) : EMPTY_STRING;
args = removeCmd(args, reversedStopOnErrCmd); args = removeCmd(args, reversedStopOnErrCmd);
args = removeCmd(args, reversedParallelBuildCmd); args = removeCmd(args, reversedParallelBuildCmd);
@ -1169,14 +1171,12 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
public String getParallelizationCmd(int num) { public String getParallelizationCmd(int num) {
String pattern = getParrallelBuildCmd(); String pattern = getParrallelBuildCmd();
if(pattern.length() == 0){ if (pattern.length() == 0 || num == 0) {
return EMPTY_STRING;
}if(num == 0){
return EMPTY_STRING; return EMPTY_STRING;
} }
// "unlimited" number of jobs results in not adding the number to parallelization cmd // "unlimited" number of jobs results in not adding the number to parallelization cmd
// that behavior corresponds that of "make" flag "-j". // that behavior corresponds that of "make" flag "-j".
return processParallelPattern(pattern, num == Integer.MAX_VALUE, Math.abs(num)); return processParallelPattern(pattern, num == Integer.MAX_VALUE, num);
} }
/** /**
@ -1188,6 +1188,8 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
* <br>Where # is num or empty if {@code empty} is {@code true}) * <br>Where # is num or empty if {@code empty} is {@code true})
*/ */
private String processParallelPattern(String pattern, boolean empty, int num){ private String processParallelPattern(String pattern, boolean empty, int num){
Assert.isTrue(num > 0);
int start = pattern.indexOf(PARALLEL_PATTERN_NUM_START); int start = pattern.indexOf(PARALLEL_PATTERN_NUM_START);
int end = -1; int end = -1;
boolean hasStartChar = false; boolean hasStartChar = false;
@ -2527,46 +2529,40 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
} }
/** /**
* {@inheritDoc} * Returns the internal representation of maximum number of parallel jobs
* * to be used for a build.
* Returns the number of parallel jobs to be used for a build.
* Note that "optimal" value is represented by negative number. * Note that "optimal" value is represented by negative number.
* See the table at {@link IMakeCommonBuildInfo#getParallelizationNum()}. *
* The value of the number is encoded as follows:
* <pre>
* Status Returns
* No parallel 1
* Optimal -CPU# (negative number of processors)
* Specific >0 (positive number)
* Unlimited Integer.MAX (N/A for Internal Builder)
* </pre>
*/ */
@Override public int getParallelizationNumAttribute() {
public int getParallelizationNum() {
if (!isParallelBuildOn()) if (!isParallelBuildOn())
return 1; return 1;
if(parallelJobsNumber == null){ if(parallelNumberAttribute == null){
if(superClass != null){
return ((Builder)superClass).getParallelizationNum();
}
return 1;
}
return parallelJobsNumber.intValue();
}
public int getParallelizationNumAttribute(){
if(parallelJobsNumber == null){
if(superClass != null){ if(superClass != null){
return ((Builder)superClass).getParallelizationNumAttribute(); return ((Builder)superClass).getParallelizationNumAttribute();
} }
return 1; return 1;
} }
return parallelJobsNumber.intValue(); return parallelNumberAttribute.intValue();
}
@Override
public int getParallelizationNum() {
return Math.abs(getParallelizationNumAttribute());
} }
/**
* {@inheritDoc}
*
* @param jobs - maximum number of jobs or threads. If the number is 0
* or negative, negative "optimal" number will be set, see
* {@link #getOptimalParallelJobNum()}.
*/
@Override @Override
public void setParallelizationNum(int jobs) throws CoreException { public void setParallelizationNum(int jobs) throws CoreException {
if (isParallelBuildOn() && (parallelJobsNumber == null || parallelJobsNumber != jobs)) { if (isParallelBuildOn() && (parallelNumberAttribute == null || parallelNumberAttribute != jobs)) {
String curCmd = getParallelizationCmd(getParallelizationNum()); String curCmd = getParallelizationCmd(getParallelizationNum());
String args = getArgumentsAttribute(); String args = getArgumentsAttribute();
String updatedArgs = removeCmd(args, curCmd); String updatedArgs = removeCmd(args, curCmd);
@ -2579,10 +2575,10 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
jobs = -1; jobs = -1;
} }
if (jobs > 0) { if (jobs > 0) {
parallelJobsNumber = jobs; parallelNumberAttribute = jobs;
} else { } else {
// "optimal" // "optimal"
parallelJobsNumber = -getOptimalParallelJobNum(); parallelNumberAttribute = -getOptimalParallelJobNum();
} }
setDirty(true); setDirty(true);
} }
@ -2647,7 +2643,7 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
* *
* @param on - the flag to enable or disable parallel mode. * @param on - the flag to enable or disable parallel mode.
* <br>{@code true} to enable, in this case the maximum number of jobs * <br>{@code true} to enable, in this case the maximum number of jobs
* will be set to negative "optimal" number, see {@link #getOptimalParallelJobNum()}. * will be set to "optimal" number, see {@link #getOptimalParallelJobNum()}.
* <br>{@code false} to disable, the number of jobs will be set to 1. * <br>{@code false} to disable, the number of jobs will be set to 1.
*/ */
@Override @Override
@ -2668,9 +2664,9 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
if (isParallelBuildEnabled) { if (isParallelBuildEnabled) {
// "optimal" // "optimal"
parallelJobsNumber = -getOptimalParallelJobNum(); parallelNumberAttribute = -getOptimalParallelJobNum();
} else { } else {
parallelJobsNumber = 1; parallelNumberAttribute = 1;
} }
setDirty(true); setDirty(true);
} }

View file

@ -2273,8 +2273,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
* mode. * mode.
* *
* @param jobs - maximum number of jobs or threads. If the number is 0 * @param jobs - maximum number of jobs or threads. If the number is 0
* or negative, negative "optimal" number will be set, see * or negative, "optimal" number will be set,
* {@link Builder#getOptimalParallelJobNum()}. * see {@link Builder#getOptimalParallelJobNum()}.
*/ */
public void setParallelNumber(int jobs){ public void setParallelNumber(int jobs){
try { try {
@ -2286,13 +2286,9 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
/** /**
* Returns maximum number of parallel threads/jobs used by the configuration's builder. * Returns maximum number of parallel threads/jobs used by the configuration's builder.
* Note that this function can return negative value to indicate "optimal" number.
*
* @see #setParallelDef(boolean) * @see #setParallelDef(boolean)
* @see Builder#getParallelizationNum()
* *
* @return - maximum number of parallel threads or jobs used by the builder or negative number. * @return - maximum number of parallel threads or jobs used by the builder.
* For exact interpretation see table in {@link IMakeCommonBuildInfo#getParallelizationNum()}
*/ */
public int getParallelNumber(){ public int getParallelNumber(){
return getBuilder().getParallelizationNum(); return getBuilder().getParallelizationNum();

View file

@ -44,15 +44,7 @@ public interface IMakeCommonBuildInfo {
boolean supportsStopOnError(boolean on); boolean supportsStopOnError(boolean on);
/** /**
* @return the current number of parallel jobs. * @return the maximum number of parallel jobs to be used for build.
* The value of the number is encoded as follows:
* <pre>
* Status Returns
* No parallel 1
* Unlimited Integer.MAX (N/A for Internal Builder)
* Optimal -CPU# (negative number of processors)
* Specific >0 (positive number)
* </pre>
*/ */
int getParallelizationNum(); int getParallelizationNum();
@ -61,21 +53,25 @@ public interface IMakeCommonBuildInfo {
* Note that the number will be set only if the builder is in "parallel" * Note that the number will be set only if the builder is in "parallel"
* mode. * mode.
* *
* @param jobs - number of jobs according table {@link #getParallelizationNum()}. * @param jobs - maximum number of jobs.
* Any number <=0 is treated as setting "optimal" property, * Any number <=0 is treated as setting "optimal" property,
* the value of the number itself is ignored. * the value of the number itself is ignored in this case.
*/ */
void setParallelizationNum(int jobs) throws CoreException; void setParallelizationNum(int jobs) throws CoreException;
/** /**
* @return {@code true} if builder supports parallel build, * @return {@code true} if builder supports parallel build,
* {@code false} otherwise. * {@code false} otherwise.
*/ */
boolean supportsParallelBuild(); boolean supportsParallelBuild();
/** /**
* @return {@code true} if builder support for parallel build is enabled, * @return {@code true} if builder support for parallel build is enabled,
* {@code false} otherwise. * {@code false} otherwise.
*/ */
boolean isParallelBuildOn(); boolean isParallelBuildOn();
/** /**
* Set parallel execution mode for the builder. * Set parallel execution mode for the builder.
* @see Builder#setParallelBuildOn(boolean) * @see Builder#setParallelBuildOn(boolean)

View file

@ -25,7 +25,6 @@ import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.MultiConfiguration; import org.eclipse.cdt.managedbuilder.internal.core.MultiConfiguration;
import org.eclipse.cdt.managedbuilder.internal.ui.Messages; import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
import org.eclipse.cdt.newmake.core.IMakeBuilderInfo; import org.eclipse.cdt.newmake.core.IMakeBuilderInfo;
import org.eclipse.cdt.newmake.core.IMakeCommonBuildInfo;
import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
import org.eclipse.cdt.ui.newui.ICPropertyProvider; import org.eclipse.cdt.ui.newui.ICPropertyProvider;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -231,12 +230,12 @@ public class BuildBehaviourTab extends AbstractCBuildPropertyTab {
* 0: isStopOnError * 0: isStopOnError
* 1: supportsStopOnError(true) * 1: supportsStopOnError(true)
* 2: bld.supportsStopOnError(false) * 2: bld.supportsStopOnError(false)
* 3: cfg.getParallelDef() * 3: N/A
* Mode 2: * Mode 2:
* 0: b.isAutoBuildEnable() * 0: b.isAutoBuildEnable()
* 1: b.isIncrementalBuildEnabled() * 1: b.isIncrementalBuildEnabled()
* 2: b.isCleanBuildEnabled() * 2: b.isCleanBuildEnabled()
* 3: getParallelDef() * 3: N/A
*/ */
static int[] calc3states(ICPropertyProvider p, IConfiguration mcfg, int mode) { static int[] calc3states(ICPropertyProvider p, IConfiguration mcfg, int mode) {
if (p.isMultiCfg() && mcfg instanceof ICMultiItemsHolder) { if (p.isMultiCfg() && mcfg instanceof ICMultiItemsHolder) {
@ -253,8 +252,7 @@ public class BuildBehaviourTab extends AbstractCBuildPropertyTab {
(m1 ? bldr0.supportsStopOnError(true) : bldr0.isIncrementalBuildEnabled() ); (m1 ? bldr0.supportsStopOnError(true) : bldr0.isIncrementalBuildEnabled() );
b[2] = m0 ? bldr0.canKeepEnvironmentVariablesInBuildfile() : b[2] = m0 ? bldr0.canKeepEnvironmentVariablesInBuildfile() :
(m1 ? bldr0.supportsStopOnError(false) : bldr0.isCleanBuildEnabled()); (m1 ? bldr0.supportsStopOnError(false) : bldr0.isCleanBuildEnabled());
b[3] = m0 ? bldr0.keepEnvironmentVariablesInBuildfile() : b[3] = m0 ? bldr0.keepEnvironmentVariablesInBuildfile() : false;
(m1 ? ((Configuration)cfgs[0]).getParallelDef() : getParallelDef(mcfg));
for (int i=1; i<cfgs.length; i++) { for (int i=1; i<cfgs.length; i++) {
IBuilder bldr = cfgs[i].getBuilder(); IBuilder bldr = cfgs[i].getBuilder();
if (b[0] != (m0 ? bldr.isManagedBuildOn() : if (b[0] != (m0 ? bldr.isManagedBuildOn() :
@ -266,9 +264,7 @@ public class BuildBehaviourTab extends AbstractCBuildPropertyTab {
if (b[2] != (m0 ? bldr.canKeepEnvironmentVariablesInBuildfile() : if (b[2] != (m0 ? bldr.canKeepEnvironmentVariablesInBuildfile() :
(m1 ? bldr.supportsStopOnError(false) : bldr.isCleanBuildEnabled()))) (m1 ? bldr.supportsStopOnError(false) : bldr.isCleanBuildEnabled())))
res[2] = TRI_UNKNOWN; res[2] = TRI_UNKNOWN;
if ((b[3] != (m0 ? bldr.keepEnvironmentVariablesInBuildfile() : if (b[3] != (m0 ? bldr.keepEnvironmentVariablesInBuildfile() : false)) {
(m1 ? ((Configuration)cfgs[i]).getParallelDef() : getParallelDef(mcfg))))
|| ((IMultiConfiguration) mcfg).getParallelNumber() == 0) {
res[3] = TRI_UNKNOWN; res[3] = TRI_UNKNOWN;
} }
} }
@ -304,60 +300,22 @@ public class BuildBehaviourTab extends AbstractCBuildPropertyTab {
bldr.supportsStopOnError(false)); bldr.supportsStopOnError(false));
} }
// Parallel build
boolean isParallelSupported = bldr.supportsParallelBuild();
boolean isExternalBuilder = ! isInternalBuilderEnabled();
b_parallel.setVisible(isParallelSupported); updateParallelBlock();
b_parallelOptimal.setVisible(isParallelSupported);
b_parallelSpecific.setVisible(isParallelSupported);
b_parallelUnlimited.setVisible(isParallelSupported && isExternalBuilder);
s_parallelNumber.setVisible(isParallelSupported);
if (isParallelSupported) {
if (extStates == null) {
setTriSelection(b_parallel, getParallelDef());
} else {
setTriSelection(b_parallel, extStates[3]);
}
boolean isParallelSelected = b_parallel.getSelection();
int optimalParallelNumber = bldr.getOptimalParallelJobNum();
b_parallelOptimal.setText(MessageFormat.format(Messages.BuilderSettingsTab_UseOptimalJobs, optimalParallelNumber));
b_parallelOptimal.setEnabled(isParallelSelected);
b_parallelSpecific.setEnabled(isParallelSelected);
b_parallelUnlimited.setEnabled(isParallelSelected && isExternalBuilder);
// Build commands
extStates = calc3states(page, icfg, 2); extStates = calc3states(page, icfg, 2);
if (extStates == null) { if (extStates != null) {
setTriSelection(b_autoBuild, bldr.isAutoBuildEnable()); // multiple configurations selected
setTriSelection(b_cmdBuild, bldr.isIncrementalBuildEnabled());
setTriSelection(b_cmdClean, bldr.isCleanBuildEnabled());
} else { // multiple configurations selected
setTriSelection(b_autoBuild, extStates[0]); setTriSelection(b_autoBuild, extStates[0]);
setTriSelection(b_cmdBuild, extStates[1]); setTriSelection(b_cmdBuild, extStates[1]);
setTriSelection(b_cmdClean, extStates[2]); setTriSelection(b_cmdClean, extStates[2]);
}
if ((extStates == null || extStates[3] != TRI_UNKNOWN) && isParallelSelected) {
// single configuration or matching multiple configurations here
int parallelNumber = getParallelNumber();
boolean isOptimal = parallelNumber <= 0;
boolean isUnlimited = parallelNumber == Integer.MAX_VALUE;
b_parallelOptimal.setSelection(isOptimal);
b_parallelSpecific.setSelection(!isOptimal && !isUnlimited);
b_parallelUnlimited.setSelection(isUnlimited);
s_parallelNumber.setEnabled(b_parallelSpecific.getEnabled() && b_parallelSpecific.getSelection());
s_parallelNumber.setSelection(s_parallelNumber.isEnabled() ? parallelNumber : optimalParallelNumber);
} else { } else {
b_parallelOptimal.setSelection(true); setTriSelection(b_autoBuild, bldr.isAutoBuildEnable());
b_parallelSpecific.setSelection(false); setTriSelection(b_cmdBuild, bldr.isIncrementalBuildEnabled());
b_parallelUnlimited.setSelection(false); setTriSelection(b_cmdClean, bldr.isCleanBuildEnabled());
s_parallelNumber.setEnabled(false);
s_parallelNumber.setSelection(optimalParallelNumber);
}
} }
// Build commands
if (page.isMultiCfg()) { if (page.isMultiCfg()) {
MultiConfiguration mc = (MultiConfiguration)icfg; MultiConfiguration mc = (MultiConfiguration)icfg;
t_autoBuild.setText(mc.getBuildAttribute(IBuilder.BUILD_TARGET_AUTO, EMPTY_STR)); t_autoBuild.setText(mc.getBuildAttribute(IBuilder.BUILD_TARGET_AUTO, EMPTY_STR));
@ -386,6 +344,86 @@ public class BuildBehaviourTab extends AbstractCBuildPropertyTab {
canModify = true; canModify = true;
} }
private void updateParallelBlock() {
// note: for multi-config selection bldr is from Active cfg
boolean isAnyInternalBuilder = bldr.isInternalBuilder();
boolean isAnyExternalBuilder = ! bldr.isInternalBuilder();
boolean isParallelSupported = bldr.supportsParallelBuild();
boolean isParallelOn = bldr.isParallelBuildOn();
int triSelection = isParallelOn ? TRI_YES : TRI_NO;
int parallelizationNumInternal = bldr.getParallelizationNumAttribute();
int optimalParallelNumber = bldr.getOptimalParallelJobNum();
int parallelNumber = bldr.getParallelizationNum();
boolean isUnlimited = parallelizationNumInternal == Integer.MAX_VALUE;
if (icfg instanceof ICMultiItemsHolder) {
IConfiguration[] cfgs = (IConfiguration[])((ICMultiItemsHolder)icfg).getItems();
boolean isAnyParallelOn = isParallelOn;
boolean isAnyParallelSupported = isParallelSupported;
boolean isParallelDiffers = false;
for (IConfiguration cfg : cfgs) {
Builder builder = (Builder) cfg.getBuilder();
isParallelDiffers = isParallelDiffers
|| builder.isParallelBuildOn() != isParallelOn
|| builder.getParallelizationNumAttribute() != parallelizationNumInternal;
isAnyParallelOn = isAnyParallelOn || builder.isParallelBuildOn();
isAnyParallelSupported = isAnyParallelSupported || builder.supportsParallelBuild();
isAnyInternalBuilder = isAnyInternalBuilder || builder.isInternalBuilder();
isAnyExternalBuilder = isAnyExternalBuilder || !builder.isInternalBuilder();
}
// reset initial display to "optimal" to enhance user experience:
if ((!isParallelSupported && isAnyParallelSupported) // parallel is supported by other than Active cfg
|| (!isParallelOn && isAnyParallelOn) // prevent showing the 1 job as parallel in the spinner
|| (isUnlimited && isAnyInternalBuilder) // can't show "unlimited" as it won't be selectable if Internal Builder present
) {
isParallelSupported = true;
parallelizationNumInternal = -optimalParallelNumber;
parallelNumber = optimalParallelNumber;
isUnlimited = false;
}
if (isParallelSupported && isParallelDiffers) {
triSelection = TRI_UNKNOWN;
}
}
b_parallel.setVisible(isParallelSupported);
b_parallelOptimal.setVisible(isParallelSupported);
b_parallelSpecific.setVisible(isParallelSupported);
b_parallelUnlimited.setVisible(isParallelSupported && isAnyExternalBuilder);
s_parallelNumber.setVisible(isParallelSupported);
if (isParallelSupported) {
setTriSelection(b_parallel, triSelection);
boolean isParallelSelected = b_parallel.getSelection();
b_parallelOptimal.setText(MessageFormat.format(Messages.BuilderSettingsTab_UseOptimalJobs, optimalParallelNumber));
b_parallelOptimal.setEnabled(isParallelSelected);
b_parallelSpecific.setEnabled(isParallelSelected);
b_parallelUnlimited.setEnabled(isParallelSelected && !isAnyInternalBuilder);
if (isParallelSelected) {
boolean isOptimal = parallelizationNumInternal <= 0;
b_parallelOptimal.setSelection(isOptimal);
b_parallelSpecific.setSelection(!isOptimal && !isUnlimited);
b_parallelUnlimited.setSelection(isUnlimited);
s_parallelNumber.setEnabled(b_parallelSpecific.getEnabled() && b_parallelSpecific.getSelection());
s_parallelNumber.setSelection(s_parallelNumber.isEnabled() ? parallelNumber : optimalParallelNumber);
} else {
b_parallelOptimal.setSelection(true);
b_parallelSpecific.setSelection(false);
b_parallelUnlimited.setSelection(false);
s_parallelNumber.setEnabled(false);
s_parallelNumber.setSelection(optimalParallelNumber);
}
}
}
/** /**
* Sets up text + corresponding button * Sets up text + corresponding button
* Checkbox can be implemented either by Button or by TriButton * Checkbox can be implemented either by Button or by TriButton
@ -489,7 +527,7 @@ public class BuildBehaviourTab extends AbstractCBuildPropertyTab {
} }
b2.setStopOnError(b1.isStopOnError()); b2.setStopOnError(b1.isStopOnError());
b2.setParallelBuildOn(b1.isParallelBuildOn()); b2.setParallelBuildOn(b1.isParallelBuildOn());
b2.setParallelizationNum(b1.getParallelizationNum()); b2.setParallelizationNum(((Builder) b1).getParallelizationNumAttribute());
if (b2.canKeepEnvironmentVariablesInBuildfile()) if (b2.canKeepEnvironmentVariablesInBuildfile())
b2.setKeepEnvironmentVariablesInBuildfile(b1.keepEnvironmentVariablesInBuildfile()); b2.setKeepEnvironmentVariablesInBuildfile(b1.keepEnvironmentVariablesInBuildfile());
((Builder)b2).setBuildPath(((Builder)b1).getBuildPathAttribute()); ((Builder)b2).setBuildPath(((Builder)b1).getBuildPathAttribute());
@ -531,22 +569,6 @@ public class BuildBehaviourTab extends AbstractCBuildPropertyTab {
updateData(getResDesc()); updateData(getResDesc());
} }
private static boolean getParallelDef(IConfiguration cfg) {
if (cfg instanceof Configuration)
return ((Configuration)cfg).getParallelDef();
if (cfg instanceof IMultiConfiguration)
return ((IMultiConfiguration)cfg).getParallelDef();
return false;
}
private boolean getParallelDef() {
if (icfg instanceof Configuration)
return ((Configuration)icfg).getParallelDef();
if (icfg instanceof IMultiConfiguration)
return ((IMultiConfiguration)icfg).getParallelDef();
return false;
}
private void setParallelDef(boolean def) { private void setParallelDef(boolean def) {
if (icfg instanceof Configuration) if (icfg instanceof Configuration)
((Configuration)icfg).setParallelDef(def); ((Configuration)icfg).setParallelDef(def);
@ -554,16 +576,6 @@ public class BuildBehaviourTab extends AbstractCBuildPropertyTab {
((IMultiConfiguration)icfg).setParallelDef(def); ((IMultiConfiguration)icfg).setParallelDef(def);
} }
/**
* @see IMakeCommonBuildInfo#getParallelizationNum() for interpretation of the number.
*/
private int getParallelNumber() {
if (icfg instanceof Configuration)
return ((Configuration)icfg).getParallelNumber();
if (icfg instanceof IMultiConfiguration)
return ((IMultiConfiguration)icfg).getParallelNumber();
return 0;
}
private void setParallelNumber(int num) { private void setParallelNumber(int num) {
if (icfg instanceof Configuration) if (icfg instanceof Configuration)
((Configuration)icfg).setParallelNumber(num); ((Configuration)icfg).setParallelNumber(num);

View file

@ -87,6 +87,7 @@ public class BuilderSettingsTab extends AbstractCBuildPropertyTab {
setupLabel(g1, Messages.BuilderSettingsTab_5, 1, GridData.BEGINNING); setupLabel(g1, Messages.BuilderSettingsTab_5, 1, GridData.BEGINNING);
t_buildCmd = setupBlock(g1, b_useDefault); t_buildCmd = setupBlock(g1, b_useDefault);
t_buildCmd.addModifyListener(new ModifyListener() { t_buildCmd.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
if (! canModify) if (! canModify)
return; return;
@ -111,6 +112,7 @@ public class BuilderSettingsTab extends AbstractCBuildPropertyTab {
setupLabel(group_dir, Messages.BuilderSettingsTab_22, 1, GridData.BEGINNING); setupLabel(group_dir, Messages.BuilderSettingsTab_22, 1, GridData.BEGINNING);
t_dir = setupText(group_dir, 1, GridData.FILL_HORIZONTAL); t_dir = setupText(group_dir, 1, GridData.FILL_HORIZONTAL);
t_dir.addModifyListener(new ModifyListener() { t_dir.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
if (canModify) if (canModify)
setBuildPath(t_dir.getText()); setBuildPath(t_dir.getText());