1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Openismus GmbH.
4 ** Author: Peter Penz (ppenz@openismus.com)
5 ** Author: Patricia Santana Cruz (patriciasantanacruz@gmail.com)
6 ** Contact: https://www.qt.io/licensing/
7 **
8 ** This file is part of Qt Creator.
9 **
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU
20 ** General Public License version 3 as published by the Free Software
21 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
22 ** included in the packaging of this file. Please review the following
23 ** information to ensure the GNU General Public License requirements will
24 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25 **
26 ****************************************************************************/
27 
28 #include "configurestep.h"
29 
30 #include "autotoolsbuildconfiguration.h"
31 #include "autotoolsprojectconstants.h"
32 
33 #include <projectexplorer/abstractprocessstep.h>
34 #include <projectexplorer/processparameters.h>
35 #include <projectexplorer/project.h>
36 #include <projectexplorer/projectexplorerconstants.h>
37 #include <projectexplorer/target.h>
38 
39 #include <utils/aspects.h>
40 
41 #include <QDateTime>
42 #include <QDir>
43 
44 using namespace ProjectExplorer;
45 using namespace Utils;
46 
47 namespace AutotoolsProjectManager {
48 namespace Internal {
49 
50 // Helper Function
51 
projectDirRelativeToBuildDir(BuildConfiguration * bc)52 static QString projectDirRelativeToBuildDir(BuildConfiguration *bc)
53 {
54     const QDir buildDir(bc->buildDirectory().toString());
55     QString projDirToBuildDir = buildDir.relativeFilePath(
56         bc->project()->projectDirectory().toString());
57     if (projDirToBuildDir.isEmpty())
58         return QString("./");
59     if (!projDirToBuildDir.endsWith('/'))
60         projDirToBuildDir.append('/');
61     return projDirToBuildDir;
62 }
63 
64 // ConfigureStep
65 
66 ///**
67 // * @brief Implementation of the ProjectExplorer::AbstractProcessStep interface.
68 // *
69 // * A configure step can be configured by selecting the "Projects" button of Qt
70 // * Creator (in the left hand side menu) and under "Build Settings".
71 // *
72 // * It is possible for the user to specify custom arguments. The corresponding
73 // * configuration widget is created by MakeStep::createConfigWidget and is
74 // * represented by an instance of the class MakeStepConfigWidget.
75 // */
76 
77 class ConfigureStep final : public AbstractProcessStep
78 {
79     Q_DECLARE_TR_FUNCTIONS(AutotoolsProjectManager::Internal::ConfigureStep)
80 
81 public:
82     ConfigureStep(BuildStepList *bsl, Id id);
83 
84     void setAdditionalArguments(const QString &list);
85 
86 private:
87     void doRun() final;
88 
89     bool m_runConfigure = false;
90 };
91 
ConfigureStep(BuildStepList * bsl,Id id)92 ConfigureStep::ConfigureStep(BuildStepList *bsl, Id id)
93     : AbstractProcessStep(bsl, id)
94 {
95     auto arguments = addAspect<StringAspect>();
96     arguments->setDisplayStyle(StringAspect::LineEditDisplay);
97     arguments->setSettingsKey("AutotoolsProjectManager.ConfigureStep.AdditionalArguments");
98     arguments->setLabelText(tr("Arguments:"));
99     arguments->setHistoryCompleter("AutotoolsPM.History.ConfigureArgs");
100 
101     connect(arguments, &BaseAspect::changed, this, [this] {
102         m_runConfigure = true;
103     });
104 
105     setWorkingDirectoryProvider([this] { return project()->projectDirectory(); });
106 
107     setCommandLineProvider([this, arguments] {
108         BuildConfiguration *bc = buildConfiguration();
109 
110         return CommandLine({FilePath::fromString(projectDirRelativeToBuildDir(bc) + "configure"),
111                             arguments->value(),
112                             CommandLine::Raw});
113     });
114 
115     setSummaryUpdater([this] {
116         ProcessParameters param;
117         setupProcessParameters(&param);
118 
119         return param.summaryInWorkdir(displayName());
120     });
121 }
122 
doRun()123 void ConfigureStep::doRun()
124 {
125     //Check whether we need to run configure
126     const QString projectDir(project()->projectDirectory().toString());
127     const QFileInfo configureInfo(projectDir + "/configure");
128     const QFileInfo configStatusInfo(buildDirectory().toString() + "/config.status");
129 
130     if (!configStatusInfo.exists()
131         || configStatusInfo.lastModified() < configureInfo.lastModified()) {
132         m_runConfigure = true;
133     }
134 
135     if (!m_runConfigure) {
136         emit addOutput(tr("Configuration unchanged, skipping configure step."), OutputFormat::NormalMessage);
137         emit finished(true);
138         return;
139     }
140 
141     m_runConfigure = false;
142     AbstractProcessStep::doRun();
143 }
144 
145 // ConfigureStepFactory
146 
147 /**
148  * @brief Implementation of the ProjectExplorer::IBuildStepFactory interface.
149  *
150  * The factory is used to create instances of ConfigureStep.
151  */
152 
ConfigureStepFactory()153 ConfigureStepFactory::ConfigureStepFactory()
154 {
155     registerStep<ConfigureStep>(Constants::CONFIGURE_STEP_ID);
156     setDisplayName(ConfigureStep::tr("Configure", "Display name for AutotoolsProjectManager::ConfigureStep id."));
157     setSupportedProjectType(Constants::AUTOTOOLS_PROJECT_ID);
158     setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
159 }
160 
161 } // namespace Internal
162 } // namespace AutotoolsProjectManager
163