Skip to main content
summaryrefslogtreecommitdiffstats
blob: ab843b5b50132ad8c29aa3a211156968330c6112 (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
/*******************************************************************************
 * Copyright (c) 2015 QNX Software Systems and others.
 * 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
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.cdt.internal.qt.core.build;

import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.cdt.build.core.IConsoleService;
import org.eclipse.cdt.internal.qt.core.Activator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;

public class QtBuilder extends IncrementalProjectBuilder {

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

	@Override
	protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
		IProject project = getProject();
		try {
			IConsoleService console = Activator.getService(IConsoleService.class);
			QtBuildConfiguration qtConfig = getBuildConfig().getAdapter(QtBuildConfiguration.class);

			Path buildDir = qtConfig.getBuildDirectory();
			if (!buildDir.resolve("Makefile").toFile().exists()) { //$NON-NLS-1$
				// Need to run qmake
				List<String> command = new ArrayList<>();
				command.add(qtConfig.getQmakeCommand());

				String config = qtConfig.getQmakeConfig();
				if (config != null) {
					command.add(config);
				}

				IFile projectFile = qtConfig.getProject().getFile("main.pro");
				command.add(projectFile.getLocation().toOSString());

				Process process = new ProcessBuilder(command).directory(buildDir.toFile()).start();
				StringBuffer msg = new StringBuffer();
				for (String arg : command) {
					msg.append(arg).append(' ');
				}
				msg.append('\n');
				console.writeOutput(msg.toString());
				console.monitor(process, null, buildDir);
			}

			// run make
			// TODO obviously hardcoding here
			boolean isWin = Platform.getOS().equals(Platform.OS_WIN32);
			String make = isWin ? "C:/Qt/Tools/mingw492_32/bin/mingw32-make" : "make";
			ProcessBuilder procBuilder = new ProcessBuilder(make).directory(buildDir.toFile());
			if (isWin) {
				// Need to put the toolchain into env
				Map<String, String> env = procBuilder.environment();
				String path = env.get("PATH");
				path = "C:/Qt/Tools/mingw492_32/bin;" + path;
				env.put("PATH", path);
			}
			Process process = procBuilder.start();
			console.writeOutput("make\n"); //$NON-NLS-1$
			console.monitor(process, null, buildDir);

			project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
			return new IProject[] { project };
		} catch (IOException e) {
			throw new CoreException(new Status(IStatus.ERROR, Activator.ID, "Building " + project.getName(), e));
		}
	}

}

Back to the top