1
/*******************************************************************************
2
* Copyright (c) 2011 Broadcom Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Broadcom Corporation - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.managedbuilder.core.regressions;
13
import java.io.BufferedReader;
14
import java.io.InputStreamReader;
15
import java.util.regex.Matcher;
16
import java.util.regex.Pattern;
18
import org.eclipse.cdt.core.CCorePlugin;
19
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
20
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
21
import org.eclipse.cdt.managedbuilder.testplugin.AbstractBuilderTest;
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.resources.IncrementalProjectBuilder;
26
import org.eclipse.core.runtime.Path;
29
* This tests that an environment variable, which is part of the build
30
* (in this case referenced by a -I), makes it through to makefile
31
* correctly when it changes.
33
public class Bug_335476 extends AbstractBuilderTest {
35
private final String VAR_NAME = "INC";
37
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
38
ICdtVariableManager buildMacroManager = CCorePlugin.getDefault().getCdtVariableManager();
41
protected void setUp() throws Exception {
43
setWorkspace("regressions");
44
app = loadProject("bug_335476");
45
// Ensure Debug is the active configuration
46
setActiveConfigurationByName(app, "Debug");
50
* Build the project a few times, changing the value of the environment variable each time
54
public void runTest(int build_kind) throws Exception {
55
// Environment containingg the "Lala" environment variable
56
final IFile lala = app.getFile(new Path(".settings/org.eclipse.cdt.core.prefs.lala"));
57
// Environment containing the "Foo" environment variable
58
final IFile foo = app.getFile(new Path(".settings/org.eclipse.cdt.core.prefs.foo"));
60
final IFile env = app.getFile(new Path(".settings/org.eclipse.cdt.core.prefs"));
63
for (int i = 0; i < 5; i++) {
64
// Actual expected value
65
final String expected = current == foo ? "foo" : "lala";
66
// Update the environment to reflect the new value.
67
env.setContents(current.getContents(), IResource.NONE, null);
69
// Ask for a full build
70
app.build(build_kind, null);
72
// Check the makefile for the correct environment
73
IFile makefile = app.getFile("Debug/src/subdir.mk");
74
BufferedReader reader = new BufferedReader(new InputStreamReader(makefile.getContents()));
76
Pattern p = Pattern.compile(".*?-I.*?\"(.*?)\".*");
77
boolean found = false;
78
while (reader.ready()) {
79
String line = reader.readLine();
80
if (!line.contains("gcc"))
82
Matcher m = p.matcher(line);
83
assertTrue(m.matches());
84
String buildVar = m.group(1);
86
// Check that the Environment manager + the build manager have the variable
87
// (which tells us how far the variable has got through the system...)
88
String value = envManager.getVariable(VAR_NAME, CCorePlugin.getDefault().getProjectDescription(app, false).getActiveConfiguration(), false).getValue();
89
String value2 = buildMacroManager.resolveValue("${" + VAR_NAME + "}", "", ";", CCorePlugin.getDefault().getProjectDescription(app, false).getActiveConfiguration());
91
assertTrue(i + " EnvManager " + expected + " exepected, but was: " + value, expected.equals(value));
92
assertTrue(i + " CdtVarManager " + expected + " exepected, but was: " + value2, expected.equals(value2));
93
assertTrue(i + " Makefile: " + expected + " exepected, but was: " + buildVar, expected.equals(buildVar));
96
// Check that we at least matched
102
// Change environment
110
public void testChangingEnvironmentBuildSystem_FULL_BUILD() throws Exception {
111
runTest(IncrementalProjectBuilder.FULL_BUILD);
114
public void testChangingEnvironmentBuildSystem_INC_BUILD() throws Exception {
115
runTest(IncrementalProjectBuilder.INCREMENTAL_BUILD);