2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 Openismus GmbH.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-11-29 14:19:28 +01:00
|
|
|
|
2019-08-13 12:47:11 +02:00
|
|
|
#include "autotoolsbuildsystem.h"
|
|
|
|
|
2024-07-15 10:53:13 +02:00
|
|
|
#include "makefileparser.h"
|
2011-11-29 14:19:28 +01:00
|
|
|
|
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2023-10-19 10:42:45 +02:00
|
|
|
#include <projectexplorer/projectupdater.h>
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2023-10-19 10:42:45 +02:00
|
|
|
|
2019-01-04 12:35:28 +01:00
|
|
|
#include <qtsupport/qtcppkitinfo.h>
|
2019-08-13 12:47:11 +02:00
|
|
|
|
2024-07-19 14:35:13 +02:00
|
|
|
#include <solutions/tasking/tasktreerunner.h>
|
|
|
|
|
2024-07-15 10:53:13 +02:00
|
|
|
#include <utils/async.h>
|
2022-09-29 17:11:01 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2011-11-29 14:19:28 +01:00
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
2024-07-15 10:53:13 +02:00
|
|
|
using namespace Tasking;
|
2022-11-25 14:06:47 +01:00
|
|
|
using namespace Utils;
|
2011-11-29 14:19:28 +01:00
|
|
|
|
2022-09-29 17:11:01 +02:00
|
|
|
namespace AutotoolsProjectManager::Internal {
|
2019-08-13 12:47:11 +02:00
|
|
|
|
2024-07-19 14:35:13 +02:00
|
|
|
class AutotoolsBuildSystem final : public BuildSystem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutotoolsBuildSystem(Target *target);
|
|
|
|
~AutotoolsBuildSystem() final;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void triggerParsing() final;
|
|
|
|
QString name() const final { return QLatin1String("autotools"); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is invoked when the makefile parsing by m_makefileParserThread has
|
|
|
|
* been finished. Adds all sources and files into the project tree and
|
|
|
|
* takes care listen to file changes for Makefile.am and configure.ac
|
|
|
|
* files.
|
|
|
|
*/
|
|
|
|
void makefileParsingFinished(const MakefileParserOutputData &outputData);
|
|
|
|
|
|
|
|
/// Return value for AutotoolsProject::files()
|
|
|
|
QStringList m_files;
|
|
|
|
|
|
|
|
/// Responsible for parsing the makefiles asynchronously in a thread
|
|
|
|
Tasking::TaskTreeRunner m_parserRunner;
|
|
|
|
|
|
|
|
std::unique_ptr<ProjectUpdater> m_cppCodeModelUpdater;
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
AutotoolsBuildSystem::AutotoolsBuildSystem(Target *target)
|
|
|
|
: BuildSystem(target)
|
2023-10-19 10:42:45 +02:00
|
|
|
, m_cppCodeModelUpdater(ProjectUpdaterFactory::createCppProjectUpdater())
|
2011-11-29 14:19:28 +01:00
|
|
|
{
|
2022-09-29 17:11:01 +02:00
|
|
|
connect(target, &Target::activeBuildConfigurationChanged, this, [this] { requestParse(); });
|
|
|
|
connect(target->project(), &Project::projectFileIsDirty, this, [this] { requestParse(); });
|
2011-11-29 14:19:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-15 10:53:13 +02:00
|
|
|
AutotoolsBuildSystem::~AutotoolsBuildSystem() = default;
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2024-07-15 15:40:55 +02:00
|
|
|
static void parseMakefileImpl(QPromise<MakefileParserOutputData> &promise, const QString &makefile)
|
2024-07-15 10:53:13 +02:00
|
|
|
{
|
2024-07-15 15:40:55 +02:00
|
|
|
const auto result = parseMakefile(makefile, QFuture<void>(promise.future()));
|
|
|
|
if (result)
|
|
|
|
promise.addResult(*result);
|
2024-07-15 10:53:13 +02:00
|
|
|
else
|
|
|
|
promise.future().cancel();
|
2011-11-29 14:19:28 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void AutotoolsBuildSystem::triggerParsing()
|
2011-11-29 14:19:28 +01:00
|
|
|
{
|
2024-07-15 10:53:13 +02:00
|
|
|
const Storage<std::optional<ParseGuard>> storage;
|
|
|
|
|
|
|
|
const auto onSetup = [this, storage](Async<MakefileParserOutputData> &async) {
|
|
|
|
*storage = guardParsingRun();
|
2024-07-15 15:40:55 +02:00
|
|
|
async.setConcurrentCallData(parseMakefileImpl, projectFilePath().toString());
|
2024-07-15 10:53:13 +02:00
|
|
|
};
|
|
|
|
const auto onDone = [this, storage](const Async<MakefileParserOutputData> &async) {
|
|
|
|
(*storage)->markAsSuccess();
|
|
|
|
makefileParsingFinished(async.result());
|
|
|
|
};
|
|
|
|
|
|
|
|
const Group recipe {
|
|
|
|
storage,
|
|
|
|
AsyncTask<MakefileParserOutputData>(onSetup, onDone, CallDoneIf::Success)
|
|
|
|
};
|
|
|
|
m_parserRunner.start(recipe);
|
2011-11-29 14:19:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-15 11:40:01 +02:00
|
|
|
static QStringList filterIncludes(const QString &absSrc, const QString &absBuild,
|
|
|
|
const QStringList &in)
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
for (const QString &i : in) {
|
|
|
|
QString out = i;
|
|
|
|
out.replace(QLatin1String("$(top_srcdir)"), absSrc);
|
|
|
|
out.replace(QLatin1String("$(abs_top_srcdir)"), absSrc);
|
|
|
|
|
|
|
|
out.replace(QLatin1String("$(top_builddir)"), absBuild);
|
|
|
|
out.replace(QLatin1String("$(abs_top_builddir)"), absBuild);
|
|
|
|
|
|
|
|
result << out;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-07-15 10:53:13 +02:00
|
|
|
void AutotoolsBuildSystem::makefileParsingFinished(const MakefileParserOutputData &outputData)
|
2011-11-29 14:19:28 +01:00
|
|
|
{
|
2019-01-16 16:07:00 +01:00
|
|
|
m_files.clear();
|
2019-08-15 12:20:49 +02:00
|
|
|
|
2024-07-15 10:53:13 +02:00
|
|
|
QSet<FilePath> filesToWatch;
|
2011-11-29 14:19:28 +01:00
|
|
|
|
2019-08-13 12:47:11 +02:00
|
|
|
// Apply sources to m_files, which are returned at AutotoolsBuildSystem::files()
|
2019-10-25 09:55:32 +02:00
|
|
|
const QFileInfo fileInfo = projectFilePath().toFileInfo();
|
2011-11-29 14:19:28 +01:00
|
|
|
const QDir dir = fileInfo.absoluteDir();
|
2024-07-15 10:53:13 +02:00
|
|
|
const QStringList files = outputData.m_sources;
|
2022-06-02 14:23:03 +02:00
|
|
|
for (const QString& file : files)
|
2011-11-29 14:19:28 +01:00
|
|
|
m_files.append(dir.absoluteFilePath(file));
|
|
|
|
|
|
|
|
// Watch for changes of Makefile.am files. If a Makefile.am file
|
|
|
|
// has been changed, the project tree must be reparsed.
|
2024-07-15 10:53:13 +02:00
|
|
|
const QStringList makefiles = outputData.m_makefiles;
|
2022-06-02 14:23:03 +02:00
|
|
|
for (const QString &makefile : makefiles) {
|
2017-06-13 14:41:14 +02:00
|
|
|
const QString absMakefile = dir.absoluteFilePath(makefile);
|
2011-11-29 14:19:28 +01:00
|
|
|
|
2017-06-13 14:41:14 +02:00
|
|
|
m_files.append(absMakefile);
|
|
|
|
|
2024-07-15 10:53:13 +02:00
|
|
|
filesToWatch.insert(FilePath::fromString(absMakefile));
|
2011-11-29 14:19:28 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 15:08:34 +01:00
|
|
|
// Add configure.ac file to project and watch for changes.
|
2011-11-29 14:19:28 +01:00
|
|
|
const QLatin1String configureAc(QLatin1String("configure.ac"));
|
2012-04-03 11:53:55 +02:00
|
|
|
const QFile configureAcFile(fileInfo.absolutePath() + QLatin1Char('/') + configureAc);
|
2011-11-29 14:19:28 +01:00
|
|
|
if (configureAcFile.exists()) {
|
2017-06-13 14:41:14 +02:00
|
|
|
const QString absConfigureAc = dir.absoluteFilePath(configureAc);
|
|
|
|
m_files.append(absConfigureAc);
|
|
|
|
|
2024-07-15 10:53:13 +02:00
|
|
|
filesToWatch.insert(FilePath::fromString(absConfigureAc));
|
2011-11-29 14:19:28 +01:00
|
|
|
}
|
|
|
|
|
2019-08-13 12:47:11 +02:00
|
|
|
auto newRoot = std::make_unique<ProjectNode>(project()->projectDirectory());
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const QString &f : std::as_const(m_files)) {
|
2024-07-15 10:53:13 +02:00
|
|
|
const FilePath path = FilePath::fromString(f);
|
2019-02-25 12:08:58 +01:00
|
|
|
newRoot->addNestedNode(std::make_unique<FileNode>(path,
|
|
|
|
FileNode::fileTypeForFileName(path)));
|
2017-03-10 17:30:40 +01:00
|
|
|
}
|
2019-11-20 15:21:54 +01:00
|
|
|
setRootProjectNode(std::move(newRoot));
|
2019-08-13 12:47:11 +02:00
|
|
|
project()->setExtraProjectFiles(filesToWatch);
|
2016-09-30 21:10:32 +02:00
|
|
|
|
2019-11-20 12:12:53 +01:00
|
|
|
QtSupport::CppKitInfo kitInfo(kit());
|
2019-08-13 12:47:11 +02:00
|
|
|
QTC_ASSERT(kitInfo.isValid(), return );
|
|
|
|
|
2019-08-28 18:22:45 +02:00
|
|
|
RawProjectPart rpp;
|
2019-08-13 12:47:11 +02:00
|
|
|
rpp.setDisplayName(project()->displayName());
|
2024-09-12 11:42:24 +02:00
|
|
|
rpp.setProjectFileLocation(projectFilePath());
|
2019-01-04 12:35:28 +01:00
|
|
|
rpp.setQtVersion(kitInfo.projectPartQtVersion);
|
2024-07-15 10:53:13 +02:00
|
|
|
const QStringList cflags = outputData.m_cflags;
|
|
|
|
QStringList cxxflags = outputData.m_cxxflags;
|
2013-04-29 02:31:43 +04:00
|
|
|
if (cxxflags.isEmpty())
|
|
|
|
cxxflags = cflags;
|
2018-06-11 12:52:04 +02:00
|
|
|
|
2022-11-25 14:06:47 +01:00
|
|
|
const FilePath includeFileBaseDir = projectDirectory();
|
2023-12-11 11:42:00 +01:00
|
|
|
rpp.setFlagsForC({kitInfo.cToolchain, cflags, includeFileBaseDir});
|
|
|
|
rpp.setFlagsForCxx({kitInfo.cxxToolchain, cxxflags, includeFileBaseDir});
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2019-08-13 12:47:11 +02:00
|
|
|
const QString absSrc = project()->projectDirectory().toString();
|
2019-11-21 13:21:11 +01:00
|
|
|
BuildConfiguration *bc = target()->activeBuildConfiguration();
|
2019-08-13 12:47:11 +02:00
|
|
|
|
|
|
|
const QString absBuild = bc ? bc->buildDirectory().toString() : QString();
|
2015-07-09 01:28:04 +02:00
|
|
|
|
2024-07-15 10:53:13 +02:00
|
|
|
rpp.setIncludePaths(filterIncludes(absSrc, absBuild, outputData.m_includePaths));
|
|
|
|
rpp.setMacros(outputData.m_macros);
|
2017-02-06 16:59:53 +01:00
|
|
|
rpp.setFiles(m_files);
|
2013-04-28 19:24:49 +04:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
m_cppCodeModelUpdater->update({project(), kitInfo, activeParseEnvironment(), {rpp}});
|
2024-07-15 11:40:01 +02:00
|
|
|
|
2024-07-19 14:35:13 +02:00
|
|
|
emitBuildSystemUpdated();
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildSystem *createAutotoolsBuildSystem(Target *target)
|
|
|
|
{
|
|
|
|
return new AutotoolsBuildSystem(target);
|
|
|
|
}
|
2019-08-13 12:47:11 +02:00
|
|
|
|
2022-09-29 17:11:01 +02:00
|
|
|
} // AutotoolsProjectManager::Internal
|