aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qtapplicationmanager/appmanagerutilities.cpp
blob: 8d37282df7769a3d8d799d5621305efa580111b0 (plain)
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
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "appmanagerutilities.h"

#include "appmanagerconstants.h"

#include <projectexplorer/projectexplorerconstants.h>

#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitaspect.h>

#include <utils/hostosinfo.h>

using namespace ProjectExplorer;
using namespace QtSupport;
using namespace Utils;

namespace AppManager::Internal {

static FilePath getToolPathByQtVersion(const QtVersion *qtVersion,
                                       const QString &toolname = QString(Constants::APPMAN_PACKAGER))
{
    if (qtVersion) {
        const auto toolExistsInDir = [&toolname](const FilePath &dir) {
            return dir.pathAppended(getToolNameByDevice(toolname)).isFile();
        };

        const FilePath qtHostBinsDir = qtVersion->hostBinPath();
        if (toolExistsInDir(qtHostBinsDir))
            return qtHostBinsDir;

        const FilePath qtBinDir = qtVersion->binPath();
        if (toolExistsInDir(qtBinDir))
            return qtBinDir;
    }
    return {};
}

FilePath getToolFilePath(const QString &toolname, const Kit *kit, const IDevice::ConstPtr &device)
{
    const bool local = !device || device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
    const FilePath path = local ? getToolPathByQtVersion(QtKitAspect::qtVersion(kit))
                                : FilePath(Constants::REMOTE_DEFAULT_BIN_PATH);
    const QString name = getToolNameByDevice(toolname, device);
    const QString filePath = !path.isEmpty() ? path.pathAppended(name).toUrlishString() : name;
    return !device ? FilePath::fromString(filePath) : device->filePath(filePath);
}

QString getToolNameByDevice(const QString &baseName, const std::shared_ptr<const IDevice> &device)
{
    return OsSpecificAspects::withExecutableSuffix(device ? device->osType() : HostOsInfo::hostOs(), baseName);
}

} // AppManager::Internal