Skip to content

Commit

Permalink
Allow the new API for CMakeBuildConfiguration to be extended (#1051)
Browse files Browse the repository at this point in the history
PR #1010 added the ability to extend CMakeBuildConfiguration and
CMakeBuildConfigurationProvider by making the classes public
API, they used to be internal API.

This change makes it easier to reuse the code in the provider
and configuration by allowing extenders to provide their own
implementations of CMakeBuildConfiguration. This has been
achieved by adding createCMakeBuildConfiguration methods to
control which CMakeBuildConfiguration is constructed.

Follow up to #1010
  • Loading branch information
jonahgraham authored Jan 23, 2025
1 parent 9c4ace1 commit 978eea5
Showing 1 changed file with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
import org.eclipse.core.runtime.Platform;

/**
* A ICBuildConfigurationProvider specialized for CMake
*
* Extenders can provide their own specialised CMakeConfiguration by extending this class and {@link CMakeBuildConfiguration}.
* Extenders need to override at least {@link #getId()}, and the various createCMakeBuildConfiguration methods.
* See the example project <a href="https://github.com/eclipse-cdt/cdt/tree/main/cmake/org.eclipse.cdt.cmake.example">
* org.eclipse.cdt.cmake.example</a> for a full example.
*
* @since 1.6
*/
public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProvider {
Expand All @@ -41,6 +48,30 @@ public String getId() {
return ID;
}

/**
* Extenders should override this method to construct their specialized build configuration.
*/
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name)
throws CoreException {
return new CMakeBuildConfiguration(config, name);
}

/**
* Extenders should override this method to construct their specialized build configuration.
*/
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name,
IToolChain toolChain) {
return new CMakeBuildConfiguration(config, name, toolChain);
}

/**
* Extenders should override this method to construct their specialized build configuration.
*/
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name,
IToolChain toolChain, ICMakeToolChainFile toolChainFile, String launchMode) {
return new CMakeBuildConfiguration(config, name, toolChain, toolChainFile, launchMode);
}

@Override
public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name)
throws CoreException {
Expand All @@ -66,13 +97,13 @@ public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfigurat
}

if (toolChain != null) {
return new CMakeBuildConfiguration(config, name, toolChain);
return createCMakeBuildConfiguration(config, name, toolChain);
} else {
// No valid combinations
return null;
}
}
CMakeBuildConfiguration cmakeConfig = new CMakeBuildConfiguration(config, name);
CMakeBuildConfiguration cmakeConfig = createCMakeBuildConfiguration(config, name);
ICMakeToolChainFile tcFile = cmakeConfig.getToolChainFile();
IToolChain toolChain = cmakeConfig.getToolChain();
if (toolChain == null) {
Expand All @@ -81,7 +112,7 @@ public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfigurat
}
if (tcFile != null && !toolChain.equals(tcFile.getToolChain())) {
// toolchain changed
return new CMakeBuildConfiguration(config, name, tcFile.getToolChain(), tcFile,
return createCMakeBuildConfiguration(config, name, tcFile.getToolChain(), tcFile,
cmakeConfig.getLaunchMode());
} else {
return cmakeConfig;
Expand Down Expand Up @@ -136,7 +167,7 @@ public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChai
config = configManager.createBuildConfiguration(this, project, name, monitor);
}

CMakeBuildConfiguration cmakeConfig = new CMakeBuildConfiguration(config, name, toolChain, file, launchMode);
CMakeBuildConfiguration cmakeConfig = createCMakeBuildConfiguration(config, name, toolChain, file, launchMode);
configManager.addBuildConfiguration(config, cmakeConfig);
return cmakeConfig;
}
Expand Down

0 comments on commit 978eea5

Please sign in to comment.