Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 580b5788622b87cb1f800c80bcef59f28108a8cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*******************************************************************************
 * Copyright (c) 2017 Intel Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Intel Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.core.autotools.core;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.cdt.core.build.CBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainManager;
import org.eclipse.cdt.core.autotools.core.internal.Activator;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;

public class AutotoolsBuildConfigurationProvider implements ICBuildConfigurationProvider {

	public static final String ID = Activator.PLUGIN_ID + ".provider"; //$NON-NLS-1$

	private ICBuildConfigurationManager configManager = Activator.getService(ICBuildConfigurationManager.class);

	@Override
	public String getId() {
		return ID;
	}

	@Override
	public ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
		IToolChain toolChain = null;

		// try the toolchain for the local target
		Map<String, String> properties = new HashMap<>();
		properties.put(IToolChain.ATTR_OS, Platform.getOS());
		properties.put(IToolChain.ATTR_ARCH, Platform.getOSArch());
		IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
		for (IToolChain tc : toolChainManager.getToolChainsMatching(properties)) {
			toolChain = tc;
			break;
		}

		// local didn't work, try and find one that does
		if (toolChain == null) {
			for (IToolChain tc : toolChainManager.getToolChainsMatching(new HashMap<>())) {
				toolChain = tc;
				break;
			}
		}

		if (toolChain != null) {
			return new AutotoolsBuildConfiguration(config, name, toolChain);
		} else {
			return null;
		}
	}

	@Override
	public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
			IProgressMonitor monitor) throws CoreException {
		// See if there is one already
		for (IBuildConfiguration config : project.getBuildConfigs()) {
			ICBuildConfiguration cconfig = config.getAdapter(ICBuildConfiguration.class);
			if (cconfig != null) {
				CBuildConfiguration cmakeConfig = cconfig.getAdapter(AutotoolsBuildConfiguration.class);
				if (cmakeConfig != null && cmakeConfig.getToolChain().equals(toolChain)
						&& launchMode.equals(cmakeConfig.getLaunchMode())) {
					return cconfig;
				}
			}
		}

		// get matching toolchain file if any
		Map<String, String> properties = new HashMap<>();
		String os = toolChain.getProperty(IToolChain.ATTR_OS);
		if (os != null && !os.isEmpty()) {
			properties.put(IToolChain.ATTR_OS, os);
		}
		String arch = toolChain.getProperty(IToolChain.ATTR_ARCH);
		if (!arch.isEmpty()) {
			properties.put(IToolChain.ATTR_ARCH, arch);
		}

		// create config
		String configName = "autotools." + launchMode + '.' + toolChain.getId(); //$NON-NLS-1$
		IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName, monitor);
		CBuildConfiguration autotoolsConfig = new AutotoolsBuildConfiguration(config, configName);
		configManager.addBuildConfiguration(config, autotoolsConfig);
		return autotoolsConfig;
	}

}

Back to the top