Welcome to mirror list, hosted at ThFree Co, Russian Federation.

build_common.cpp « build_style « qt - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dcf1dbafffe8bae2f3871db30ebb80a28e9a5e60 (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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "build_common.h"

#include "platform/platform.hpp"

#include <QCoreApplication>
#include <QDir>
#include <QFile>
#include <QProcess>
#include <QRegExp>

#include <exception>

std::pair<int, QString> ExecProcess(QString const & cmd, QProcessEnvironment const * env)
{
  QProcess p;
  if (nullptr != env)
    p.setProcessEnvironment(*env);
  p.start(cmd);
  p.waitForFinished(-1);

  int const exitCode = p.exitCode();

  QString output = p.readAllStandardOutput();
  QString const error = p.readAllStandardError();
  if (!error.isEmpty())
  {
    if (!output.isEmpty())
      output += "\n";
    output += error;
  }

  return std::make_pair(exitCode, output);
}

bool CopyFile(QString const & oldFile, QString const & newFile)
{
  if (oldFile == newFile)
    return true;
  if (!QFile::exists(oldFile))
    return false;
  if (QFile::exists(newFile) && !QFile::remove(newFile))
    return false;
  return QFile::copy(oldFile, newFile);
}

void CopyFromResources(QString const & name, QString const & output)
{
  QString const resourceDir = GetPlatform().ResourcesDir().c_str();
  if (!CopyFile(JoinFoldersToPath({resourceDir, name}),
                JoinFoldersToPath({output, name})))
  {
    throw std::runtime_error(std::string("Cannot copy file ") +
                             name.toStdString() +
                             " to " + output.toStdString());
  }
}

void CopyToResources(QString const & name, QString const & input, QString const & newName)
{
  QString const resourceDir = GetPlatform().ResourcesDir().c_str();
  if (!CopyFile(JoinFoldersToPath({input, name}),
                JoinFoldersToPath({resourceDir, newName.isEmpty() ? name : newName})))
  {
    throw std::runtime_error(std::string("Cannot copy file ") +
                             name.toStdString() +
                             " from " + input.toStdString());
  }
}

QString JoinFoldersToPath(std::initializer_list<QString> const & folders)
{
  QString result;
  bool firstInserted = false;
  for (auto it = folders.begin(); it != folders.end(); ++it)
  {
    if (it->isEmpty() || *it == QDir::separator())
      continue;

    if (firstInserted)
      result.append(QDir::separator());

    result.append(*it);
    firstInserted = true;
  }
  return QDir::cleanPath(result);
}

QString GetExternalPath(QString const & name, QString const & primaryPath,
                        QString const & secondaryPath)
{
  QString const resourceDir = GetPlatform().ResourcesDir().c_str();
  QString path = JoinFoldersToPath({resourceDir, primaryPath, name});
  if (!QFileInfo::exists(path))
    path = JoinFoldersToPath({resourceDir, secondaryPath, name});

  // Special case for looking for in application folder.
  if (!QFileInfo::exists(path) && secondaryPath.isEmpty())
  {
    QString const appPath = QCoreApplication::applicationDirPath();
    QRegExp rx("(/[^/]*\\.app)", Qt::CaseInsensitive);
    int i = rx.indexIn(appPath);
    if (i >= 0)
      path = JoinFoldersToPath({appPath.left(i), name});
  }

  ASSERT(QFileInfo::exists(path), (path.toStdString()));
  return path;
}

QString GetProtobufEggPath()
{
  return GetExternalPath("protobuf-2.6.1-py2.7.egg", "kothic", "../protobuf");
}