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 "autoreconfstep.h"
29 
30 #include "autotoolsprojectconstants.h"
31 
32 #include <projectexplorer/abstractprocessstep.h>
33 #include <projectexplorer/buildconfiguration.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 using namespace ProjectExplorer;
42 using namespace Utils;
43 
44 namespace AutotoolsProjectManager {
45 namespace Internal {
46 
47 // AutoreconfStep class
48 
49 /**
50  * @brief Implementation of the ProjectExplorer::AbstractProcessStep interface.
51  *
52  * A autoreconf step can be configured by selecting the "Projects" button
53  * of Qt Creator (in the left hand side menu) and under "Build Settings".
54  *
55  * It is possible for the user to specify custom arguments.
56  */
57 
58 class AutoreconfStep final : public AbstractProcessStep
59 {
60     Q_DECLARE_TR_FUNCTIONS(AutotoolsProjectManager::Internal::AutoreconfStep)
61 
62 public:
63     AutoreconfStep(BuildStepList *bsl, Id id);
64 
65     void doRun() override;
66 
67 private:
68     bool m_runAutoreconf = false;
69 };
70 
AutoreconfStep(BuildStepList * bsl,Id id)71 AutoreconfStep::AutoreconfStep(BuildStepList *bsl, Id id)
72     : AbstractProcessStep(bsl, id)
73 {
74     auto arguments = addAspect<StringAspect>();
75     arguments->setSettingsKey("AutotoolsProjectManager.AutoreconfStep.AdditionalArguments");
76     arguments->setLabelText(tr("Arguments:"));
77     arguments->setValue("--force --install");
78     arguments->setDisplayStyle(StringAspect::LineEditDisplay);
79     arguments->setHistoryCompleter("AutotoolsPM.History.AutoreconfStepArgs");
80 
81     connect(arguments, &BaseAspect::changed, this, [this] {
82         m_runAutoreconf = true;
83     });
84 
85     setCommandLineProvider([arguments] {
86         return CommandLine(FilePath::fromString("autoreconf"),
87                            arguments->value(),
88                            CommandLine::Raw);
89     });
90 
91     setWorkingDirectoryProvider([this] { return project()->projectDirectory(); });
92 
93     setSummaryUpdater([this] {
94         ProcessParameters param;
95         setupProcessParameters(&param);
96         return param.summary(displayName());
97     });
98 }
99 
doRun()100 void AutoreconfStep::doRun()
101 {
102     // Check whether we need to run autoreconf
103     const QString projectDir(project()->projectDirectory().toString());
104 
105     if (!QFileInfo::exists(projectDir + "/configure"))
106         m_runAutoreconf = true;
107 
108     if (!m_runAutoreconf) {
109         emit addOutput(tr("Configuration unchanged, skipping autoreconf step."), OutputFormat::NormalMessage);
110         emit finished(true);
111         return;
112     }
113 
114     m_runAutoreconf = false;
115     AbstractProcessStep::doRun();
116 }
117 
118 // AutoreconfStepFactory class
119 
120 /**
121  * @brief Implementation of the ProjectExplorer::IBuildStepFactory interface.
122  *
123  * The factory is used to create instances of AutoreconfStep.
124  */
125 
AutoreconfStepFactory()126 AutoreconfStepFactory::AutoreconfStepFactory()
127 {
128     registerStep<AutoreconfStep>(Constants::AUTORECONF_STEP_ID);
129     setDisplayName(AutoreconfStep::tr("Autoreconf", "Display name for AutotoolsProjectManager::AutoreconfStep id."));
130     setSupportedProjectType(Constants::AUTOTOOLS_PROJECT_ID);
131     setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
132 }
133 
134 } // Internal
135 } // AutotoolsProjectManager
136