mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 17:35:35 +02:00
Bug 438092 - Advanced Autotools flags not set for C++ projects
- enhance the FlagConfigureOption to handle multiple flags at once by accepting the | delimiter in the name and generate separate multiple flag outputs using the children flag value options - add a new CFLAGS|CXXFLAGS flag so that both CFLAGS and CXXFLAGS will be set at the same time (to handle both C and C++ source) - modify the Autotools tests to verify the fix works Change-Id: I4e97c1a16381a3a10404e2fd20f8e49d99590db5 Reviewed-on: https://git.eclipse.org/r/28941 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> Tested-by: Jeff Johnston <jjohnstn@redhat.com>
This commit is contained in:
parent
1f29931ff1
commit
753276a27d
6 changed files with 131 additions and 23 deletions
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %Bundle-Name.0
|
||||
Bundle-SymbolicName: org.eclipse.cdt.autotools.core;singleton:=true
|
||||
Bundle-Version: 1.3.0.qualifier
|
||||
Bundle-Version: 1.4.0.qualifier
|
||||
Bundle-Activator: org.eclipse.cdt.autotools.core.AutotoolsPlugin
|
||||
Bundle-Localization: plugin
|
||||
Require-Bundle: org.eclipse.ui;bundle-version="3.4.0",
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<artifactId>org.eclipse.cdt.autotools.core</artifactId>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
</project>
|
||||
|
|
|
@ -40,6 +40,10 @@ public class AutotoolsOptionConstants {
|
|||
public final static String CATEGORY_FEATURES = "features"; // $NON-NLS-1$
|
||||
public final static String OPT_ENABLE_MAINTAINER_MODE = "enable-maintainer-mode"; // $NON-NLS-1$
|
||||
public final static String FLAG_CFLAGS = "CFLAGS"; // $NON-NLS-1$
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public final static String FLAG_CFLAGS_CXXFLAGS = "CFLAGS|CXXFLAGS"; // $NON-NLS-1$
|
||||
public final static String OPT_CFLAGS_DEBUG = "cflags-debug"; // $NON-NLS-1$
|
||||
public final static String OPT_CFLAGS_GPROF = "cflags-gprof"; // $NON-NLS-1$
|
||||
public final static String OPT_CFLAGS_GCOV = "cflags-gcov"; // $NON-NLS-1$
|
||||
|
|
|
@ -103,7 +103,7 @@ public class AutotoolsConfiguration implements IAConfiguration {
|
|||
new Option(AutotoolsOptionConstants.OPT_PROGRAM_TRANSFORM_NAME, "program_transform_name", IConfigureOption.STRING), // $NON-NLS-1$
|
||||
new Option(AutotoolsOptionConstants.CATEGORY_FEATURES, IConfigureOption.CATEGORY),
|
||||
new Option(AutotoolsOptionConstants.OPT_ENABLE_MAINTAINER_MODE, "enable_maintainer_mode", IConfigureOption.BIN), // $NON-NLS-1$
|
||||
new Option(AutotoolsOptionConstants.FLAG_CFLAGS, IConfigureOption.FLAG),
|
||||
new Option(AutotoolsOptionConstants.FLAG_CFLAGS_CXXFLAGS, IConfigureOption.FLAG),
|
||||
new Option(AutotoolsOptionConstants.OPT_CFLAGS_DEBUG, "cflags_debug", IConfigureOption.FLAGVALUE), // $NON-NLS-1$ // $NON-NLS-2$
|
||||
new Option(AutotoolsOptionConstants.OPT_CFLAGS_GPROF, "cflags_gprof", IConfigureOption.FLAGVALUE), // $NON-NLS-1$ // $NON-NLS-2$
|
||||
new Option(AutotoolsOptionConstants.OPT_CFLAGS_GCOV, "cflags_gcov", IConfigureOption.FLAGVALUE), // $NON-NLS-1$ // $NON-NLS-2$
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2011 Red Hat Inc.
|
||||
* Copyright (c) 2011, 2014 Red Hat Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Red Hat Inc. - initial API and implementation
|
||||
* Red Hat Inc. - add support for specifying multiple flag names at once
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.autotools.core.configure;
|
||||
|
||||
|
@ -37,27 +38,35 @@ public class FlagConfigureOption extends AbstractConfigurationOption {
|
|||
}
|
||||
|
||||
public String getParameter() {
|
||||
StringBuffer parm = new StringBuffer(getName()+"=\""); //$NON-NLS-1$
|
||||
boolean haveParm = false;
|
||||
if (isParmSet()) {
|
||||
String separator = "";
|
||||
for (int i = 0; i < children.size(); ++i) {
|
||||
String fvname = children.get(i);
|
||||
IConfigureOption o = cfg.getOption(fvname);
|
||||
if (o.isParmSet()) {
|
||||
if (o instanceof IFlagConfigureValueOption) {
|
||||
parm.append(separator + ((IFlagConfigureValueOption)o).getFlags()); //$NON-NLS-1$
|
||||
separator = " ";
|
||||
haveParm = true;
|
||||
StringBuffer parms = new StringBuffer();
|
||||
// Multiple flags are designated by putting multiple flags together using "|" as delimiter
|
||||
String[] flagNames = getName().split("\\|"); //$NON-NLS-1$
|
||||
String flagSeparator = "";
|
||||
for (String flagName : flagNames) {
|
||||
parms.append(flagSeparator);
|
||||
flagSeparator = " "; //$NON-NLS-1$
|
||||
StringBuffer parm = new StringBuffer(flagName+"=\""); //$NON-NLS-1$
|
||||
boolean haveParm = false;
|
||||
if (isParmSet()) {
|
||||
String separator = "";
|
||||
for (int i = 0; i < children.size(); ++i) {
|
||||
String fvname = children.get(i);
|
||||
IConfigureOption o = cfg.getOption(fvname);
|
||||
if (o.isParmSet()) {
|
||||
if (o instanceof IFlagConfigureValueOption) {
|
||||
parm.append(separator + ((IFlagConfigureValueOption)o).getFlags()); //$NON-NLS-1$
|
||||
separator = " ";
|
||||
haveParm = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (haveParm) {
|
||||
parm.append("\""); //$NON-NLS-1$
|
||||
return parm.toString();
|
||||
if (haveParm) {
|
||||
parm.append("\""); //$NON-NLS-1$
|
||||
parms.append(parm);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
return parms.toString();
|
||||
}
|
||||
|
||||
public String getParameterName() {
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
package org.eclipse.cdt.autotools.tests;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
|
@ -62,6 +62,101 @@ public class UpdateConfigureTest extends TestCase {
|
|||
testProject.open(new NullProgressMonitor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setting the special advanced options for gcov, gprof, and debug flags. Verify that
|
||||
* the configure script sets both the C and C++ flags.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testGprofGcovDebugFlagOptions() throws Exception {
|
||||
Path p = new Path("zip/project2.zip");
|
||||
ProjectTools.addSourceContainerWithImport(testProject, "src", p, null);
|
||||
assertTrue(testProject.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
|
||||
ProjectTools.setConfigDir(testProject, "src");
|
||||
ProjectTools.markExecutable(testProject, "src/autogen.sh");
|
||||
assertTrue(ProjectTools.build());
|
||||
ICConfigurationDescription cfgDes = CoreModel.getDefault().getProjectDescription(testProject).getActiveConfiguration();
|
||||
IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDes);
|
||||
assertTrue(cfg.getName().equals("Build (GNU)"));
|
||||
Map<String, IAutotoolsOption> opts = AutotoolsPlugin.getDefault().getAutotoolCfgOptions(testProject, cfg.getId());
|
||||
|
||||
IAutotoolsOption k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_GPROF);
|
||||
k.setValue("true");
|
||||
|
||||
// Now update the options we changed
|
||||
AutotoolsPlugin.getDefault().updateAutotoolCfgOptions(testProject, cfg.getId(), opts);
|
||||
|
||||
// Rebuild project
|
||||
assertTrue(ProjectTools.build());
|
||||
|
||||
org.eclipse.core.runtime.Path x = new org.eclipse.core.runtime.Path("config.log");
|
||||
assertTrue(testProject.exists(x));
|
||||
|
||||
IResource r = testProject.findMember(x);
|
||||
|
||||
File f = r.getLocation().toFile();
|
||||
|
||||
FileReader fr = new FileReader(f);
|
||||
|
||||
char[] cbuf = new char[2000];
|
||||
fr.read(cbuf);
|
||||
|
||||
String s = new String(cbuf);
|
||||
|
||||
assertTrue(s.contains("testProject2/src/configure CFLAGS=-pg CXXFLAGS=-pg"));
|
||||
|
||||
fr.close();
|
||||
|
||||
// Reset gprof opt and set gcov opt
|
||||
opts = AutotoolsPlugin.getDefault().getAutotoolCfgOptions(testProject, cfg.getId());
|
||||
k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_GPROF);
|
||||
k.setValue("false");
|
||||
|
||||
k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_GCOV);
|
||||
k.setValue("true");
|
||||
|
||||
// Now update the options we changed
|
||||
AutotoolsPlugin.getDefault().updateAutotoolCfgOptions(testProject, cfg.getId(), opts);
|
||||
|
||||
// Rebuild project
|
||||
assertTrue(ProjectTools.build());
|
||||
|
||||
r = testProject.findMember(x);
|
||||
f = r.getLocation().toFile();
|
||||
fr = new FileReader(f);
|
||||
fr.read(cbuf);
|
||||
|
||||
s = new String(cbuf);
|
||||
|
||||
assertTrue(s.contains("testProject2/src/configure CFLAGS=-fprofile-arcs -ftest-coverage CXXFLAGS=-fprofile-arcs -ftest-coverage"));
|
||||
|
||||
fr.close();
|
||||
|
||||
// Reset gcov opt and set debug opt
|
||||
opts = AutotoolsPlugin.getDefault().getAutotoolCfgOptions(testProject, cfg.getId());
|
||||
k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_GCOV);
|
||||
k.setValue("false");
|
||||
|
||||
k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_DEBUG);
|
||||
k.setValue("true");
|
||||
|
||||
// Now update the options we changed
|
||||
AutotoolsPlugin.getDefault().updateAutotoolCfgOptions(testProject, cfg.getId(), opts);
|
||||
|
||||
// Rebuild project
|
||||
assertTrue(ProjectTools.build());
|
||||
|
||||
r = testProject.findMember(x);
|
||||
f = r.getLocation().toFile();
|
||||
fr = new FileReader(f);
|
||||
fr.read(cbuf);
|
||||
|
||||
s = new String(cbuf);
|
||||
|
||||
assertTrue(s.contains("testProject2/src/configure CFLAGS=-g CXXFLAGS=-g"));
|
||||
|
||||
fr.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting and updating configuration options for an Autotools Project. The top-level
|
||||
* contains autogen.sh which will build configure, but not run it.
|
||||
|
@ -106,7 +201,7 @@ public class UpdateConfigureTest extends TestCase {
|
|||
assertFalse(k.canUpdate());
|
||||
assertEquals(k.getType(), IAutotoolsOption.CATEGORY);
|
||||
|
||||
k = opts.get(AutotoolsOptionConstants.FLAG_CFLAGS);
|
||||
k = opts.get(AutotoolsOptionConstants.FLAG_CFLAGS_CXXFLAGS);
|
||||
assertFalse(k.canUpdate());
|
||||
assertEquals(k.getType(), IAutotoolsOption.FLAG);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue