📄 pbuilder_pbx.cpp
字号:
/****************************************************************************
**
** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
**
** This file is part of the qmake application of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://www.trolltech.com/products/qt/licensing.html or contact the
** sales department at sales@trolltech.com.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include "pbuilder_pbx.h"
#include "option.h"
#include "meta.h"
#include "qtmd5.h"
#include <qdir.h>
#include <qregexp.h>
#include <stdlib.h>
#include <time.h>
#ifdef Q_OS_UNIX
# include <sys/types.h>
# include <sys/stat.h>
#endif
//#define GENERATE_AGGREGRATE_SUBDIR
// Note: this is fairly hacky, but it does the job...
ProjectBuilderMakefileGenerator::ProjectBuilderMakefileGenerator() : UnixMakefileGenerator()
{
}
bool
ProjectBuilderMakefileGenerator::writeMakefile(QTextStream &t)
{
if(!project->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) {
/* for now just dump, I need to generated an empty xml or something.. */
fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
var("QMAKE_FAILED_REQUIREMENTS").toLatin1().constData());
return true;
}
project->variables()["MAKEFILE"].clear();
project->variables()["MAKEFILE"].append("Makefile");
if(project->first("TEMPLATE") == "app" || project->first("TEMPLATE") == "lib")
return writeMakeParts(t);
else if(project->first("TEMPLATE") == "subdirs")
return writeSubDirs(t);
return false;
}
bool
ProjectBuilderMakefileGenerator::writeSubDirs(QTextStream &t)
{
if(project->isActiveConfig("generate_pbxbuild_makefile")) {
QString mkwrap = fileFixify(pbx_dir + Option::dir_sep + ".." + Option::dir_sep + project->first("MAKEFILE"),
qmake_getpwd());
QFile mkwrapf(mkwrap);
if(mkwrapf.open(QIODevice::WriteOnly | QIODevice::Text)) {
debug_msg(1, "pbuilder: Creating file: %s", mkwrap.toLatin1().constData());
QTextStream mkwrapt(&mkwrapf);
UnixMakefileGenerator::writeSubDirs(mkwrapt);
}
}
//HEADER
const int pbVersion = pbuilderVersion();
t << "// !$*UTF8*$!" << "\n"
<< "{" << "\n"
<< "\t" << "archiveVersion = 1;" << "\n"
<< "\t" << "classes = {" << "\n" << "\t" << "};" << "\n"
<< "\t" << "objectVersion = " << pbVersion << ";" << "\n"
<< "\t" << "objects = {" << endl;
//SUBDIRS
QStringList subdirs = project->variables()["SUBDIRS"];
QString oldpwd = qmake_getpwd();
QMap<QString, QStringList> groups;
for(int subdir = 0; subdir < subdirs.count(); subdir++) {
QFileInfo fi(fileInfo(Option::fixPathToLocalOS(subdirs[subdir], true)));
if(fi.exists()) {
if(fi.isDir()) {
QString profile = subdirs[subdir];
if(!profile.endsWith(Option::dir_sep))
profile += Option::dir_sep;
profile += fi.baseName() + ".pro";
subdirs.append(profile);
} else {
QMakeProject tmp_proj;
QString dir = fi.path(), fn = fi.fileName();
if(!dir.isEmpty()) {
if(!qmake_setpwd(dir))
fprintf(stderr, "Cannot find directory: %s\n", dir.toLatin1().constData());
}
if(tmp_proj.read(fn)) {
if(Option::debug_level) {
QMap<QString, QStringList> &vars = tmp_proj.variables();
for(QMap<QString, QStringList>::Iterator it = vars.begin();
it != vars.end(); ++it) {
if(it.key().left(1) != "." && !it.value().isEmpty())
debug_msg(1, "%s: %s === %s", fn.toLatin1().constData(), it.key().toLatin1().constData(),
it.value().join(" :: ").toLatin1().constData());
}
}
if(tmp_proj.first("TEMPLATE") == "subdirs") {
subdirs += fileFixify(tmp_proj.variables()["SUBDIRS"]);
} else if(tmp_proj.first("TEMPLATE") == "app" || tmp_proj.first("TEMPLATE") == "lib") {
QString pbxproj = qmake_getpwd() + Option::dir_sep + tmp_proj.first("TARGET") + projectSuffix();
if(!exists(pbxproj)) {
warn_msg(WarnLogic, "Ignored (not found) '%s'", pbxproj.toLatin1().constData());
goto nextfile; // # Dirty!
}
const QString project_key = keyFor(pbxproj + "_PROJECTREF");
project->variables()["QMAKE_PBX_SUBDIRS"] += pbxproj;
//PROJECTREF
{
bool in_root = true;
QString name = qmake_getpwd();
if(project->isActiveConfig("flat")) {
QString flat_file = fileFixify(name, oldpwd, Option::output_dir, FileFixifyRelative);
if(flat_file.indexOf(Option::dir_sep) != -1) {
QStringList dirs = flat_file.split(Option::dir_sep);
name = dirs.back();
}
} else {
QString flat_file = fileFixify(name, oldpwd, Option::output_dir, FileFixifyRelative);
if(QDir::isRelativePath(flat_file) && flat_file.indexOf(Option::dir_sep) != -1) {
QString last_grp("QMAKE_SUBDIR_PBX_HEIR_GROUP");
QStringList dirs = flat_file.split(Option::dir_sep);
name = dirs.back();
for(QStringList::Iterator dir_it = dirs.begin(); dir_it != dirs.end(); ++dir_it) {
QString new_grp(last_grp + Option::dir_sep + (*dir_it)), new_grp_key(keyFor(new_grp));
if(dir_it == dirs.begin()) {
if(!groups.contains(new_grp))
project->variables()["QMAKE_SUBDIR_PBX_GROUPS"].append(new_grp_key);
} else {
if(!groups[last_grp].contains(new_grp_key))
groups[last_grp] += new_grp_key;
}
last_grp = new_grp;
}
groups[last_grp] += project_key;
in_root = false;
}
}
if(in_root)
project->variables()["QMAKE_SUBDIR_PBX_GROUPS"] += project_key;
t << "\t\t" << project_key << " = {" << "\n"
<< "\t\t\t" << "isa = PBXFileReference;" << "\n"
<< "\t\t\t" << "lastKnownFileType = \"wrapper.pb-project\";" << "\n"
<< "\t\t\t" << "name = " << tmp_proj.first("TARGET") << projectSuffix() << ";" << "\n"
<< "\t\t\t" << "path = " << pbxproj << ";" << "\n"
<< "\t\t\t" << "refType = 0;" << "\n"
<< "\t\t\t" << "sourceTree = \"<absolute>\";" << "\n"
<< "\t\t" << "};" << "\n";
//WRAPPER
t << "\t\t" << keyFor(pbxproj + "_WRAPPER") << " = {" << "\n"
<< "\t\t\t" << "isa = PBXReferenceProxy;" << "\n";
if(tmp_proj.first("TEMPLATE") == "app") {
t << "\t\t\t" << "fileType = wrapper.application;" << "\n"
<< "\t\t\t" << "path = " << tmp_proj.first("TARGET") << ".app;" << "\n";
} else {
t << "\t\t\t" << "fileType = \"compiled.mach-o.dylib\";" << "\n"
<< "\t\t\t" << "path = " << tmp_proj.first("TARGET") << ".dylib;" << "\n";
}
t << "\t\t\t" << "refType = 3;" << "\n"
<< "\t\t\t" << "remoteRef = " << keyFor(pbxproj + "_WRAPPERREF") << ";" << "\n"
<< "\t\t\t" << "sourceTree = BUILT_PRODUCTS_DIR;" << "\n"
<< "\t\t" << "};" << "\n";
t << "\t\t" << keyFor(pbxproj + "_WRAPPERREF") << " = {" << "\n"
<< "\t\t\t" << "containerPortal = " << project_key << ";" << "\n"
<< "\t\t\t" << "isa = PBXContainerItemProxy;" << "\n"
<< "\t\t\t" << "proxyType = 2;" << "\n"
// << "\t\t\t" << "remoteGlobalIDString = " << keyFor(pbxproj + "QMAKE_PBX_REFERENCE") << ";" << "\n"
<< "\t\t\t" << "remoteGlobalIDString = " << keyFor(pbxproj + "QMAKE_PBX_REFERENCE!!!") << ";" << "\n"
<< "\t\t\t" << "remoteInfo = " << tmp_proj.first("TARGET") << ";" << "\n"
<< "\t\t" << "};" << "\n";
//PRODUCTGROUP
t << "\t\t" << keyFor(pbxproj + "_PRODUCTGROUP") << " = {" << "\n"
<< "\t\t\t" << "children = (" << "\n"
<< "\t\t\t\t" << keyFor(pbxproj + "_WRAPPER") << "\n"
<< "\t\t\t" << ");" << "\n"
<< "\t\t\t" << "isa = PBXGroup;" << "\n"
<< "\t\t\t" << "name = Products;" << "\n"
<< "\t\t\t" << "refType = 4;" << "\n"
<< "\t\t\t" << "sourceTree = \"<group>\";" << "\n"
<< "\t\t" << "};" << "\n";
}
#ifdef GENERATE_AGGREGRATE_SUBDIR
//TARGET (for aggregate)
{
//container
const QString container_proxy = keyFor(pbxproj + "_CONTAINERPROXY");
t << "\t\t" << container_proxy << " = {" << "\n"
<< "\t\t\t" << "containerPortal = " << project_key << ";" << "\n"
<< "\t\t\t" << "isa = PBXContainerItemProxy;" << "\n"
<< "\t\t\t" << "proxyType = 1;" << "\n"
<< "\t\t\t" << "remoteGlobalIDString = " << keyFor(pbxproj + "QMAKE_PBX_TARGET") << ";" << "\n"
<< "\t\t\t" << "remoteInfo = " << tmp_proj.first("TARGET") << ";" << "\n"
<< "\t\t" << "};" << "\n";
//targetref
t << "\t\t" << keyFor(pbxproj + "_TARGETREF") << " = {" << "\n"
<< "\t\t\t" << "isa = PBXTargetDependency;" << "\n"
<< "\t\t\t" << "name = \"" << tmp_proj.first("TARGET")
<< " (from " << tmp_proj.first("TARGET") << projectSuffix() << ")\";" << "\n"
<< "\t\t\t" << "targetProxy = " << container_proxy << ";" << "\n"
<< "\t\t" << "};" << "\n";
}
#endif
}
}
nextfile:
qmake_setpwd(oldpwd);
}
}
}
for(QMap<QString, QStringList>::Iterator grp_it = groups.begin(); grp_it != groups.end(); ++grp_it) {
t << "\t\t" << keyFor(grp_it.key()) << " = {" << "\n"
<< "\t\t\t" << "isa = PBXGroup;" << "\n"
<< "\t\t\t" << "children = (" << "\n"
<< valGlue(grp_it.value(), "\t\t\t\t", ",\n\t\t\t\t", "\n")
<< "\t\t\t" << ");" << "\n"
<< "\t\t\t" << "name = \"" << grp_it.key().section(Option::dir_sep, -1) << "\";" << "\n"
<< "\t\t\t" << "refType = 4;" << "\n"
<< "\t\t" << "};" << "\n";
}
//DUMP EVERYTHING THAT TIES THE ABOVE TOGETHER
//BUILDSTYLE
QString active_buildstyle;
for(int as_release = 0; as_release < 2; as_release++)
{
QMap<QString, QString> settings;
settings.insert("COPY_PHASE_STRIP", (as_release ? "YES" : "NO"));
if(as_release)
settings.insert("GCC_GENERATE_DEBUGGING_SYMBOLS", "NO");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -