From 6e29e1abeefb998c97df14c6971c69822ead7959 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 7 Nov 2013 12:58:34 +0100 Subject: DEVTOOLS: Adapt create_project for new configure.engine files. I could not try any generated project files since I do not have access to the IDEs. --- devtools/create_project/create_project.cpp | 165 ++++++++++++++++++++--------- 1 file changed, 112 insertions(+), 53 deletions(-) (limited to 'devtools/create_project/create_project.cpp') diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp index e013377241..ad3160d778 100644 --- a/devtools/create_project/create_project.cpp +++ b/devtools/create_project/create_project.cpp @@ -81,22 +81,6 @@ std::string unifyPath(const std::string &path); * @param exe Name of the executable. */ void displayHelp(const char *exe); - -/** - * Structure for describing an FSNode. This is a very minimalistic - * description, which includes everything we need. - * It only contains the name of the node and whether it is a directory - * or not. - */ -struct FSNode { - FSNode() : name(), isDirectory(false) {} - FSNode(const std::string &n, bool iD) : name(n), isDirectory(iD) {} - - std::string name; ///< Name of the file system node - bool isDirectory; ///< Whether it is a directory or not -}; - -typedef std::list FileList; } // End of anonymous namespace enum ProjectType { @@ -128,7 +112,7 @@ int main(int argc, char *argv[]) { setup.filePrefix = setup.srcDir; setup.outputDir = '.'; - setup.engines = parseConfigure(setup.srcDir); + setup.engines = parseEngines(setup.srcDir); if (setup.engines.empty()) { std::cout << "WARNING: No engines found in configure file or configure file missing in \"" << setup.srcDir << "\"\n"; @@ -672,47 +656,51 @@ void displayHelp(const char *exe) { } /** - * Try to parse a given line and create an engine definition - * out of the result. - * - * This may take *any* input line, when the line is not used - * to define an engine the result of the function will be "false". + * Parse the configure.engine file of a given engine directory and return a + * list of all defined engines. * - * Note that the contents of "engine" are undefined, when this - * function returns "false". + * @param engineDir The directory of the engine. + * @return The list of all defined engines. + */ +EngineDescList parseEngineConfigure(const std::string &engineDir); + +/** + * Compares two FSNode entries in a strict-weak fashion based on the name. * - * @param line Text input line. - * @param engine Reference to an object, where the engine information - * is to be stored in. - * @return "true", when parsing succeeded, "false" otherwise. + * @param left The first operand. + * @param right The second operand. + * @return "true" when the name of the left operand is strictly smaller than + * the name of the second operand. "false" otherwise. */ -bool parseEngine(const std::string &line, EngineDesc &engine); +bool compareFSNode(const CreateProjectTool::FSNode &left, const CreateProjectTool::FSNode &right); } // End of anonymous namespace -EngineDescList parseConfigure(const std::string &srcDir) { - std::string configureFile = srcDir + "/engines/configure.engines"; +EngineDescList parseEngines(const std::string &srcDir) { + using CreateProjectTool::FileList; + using CreateProjectTool::listDirectory; - std::ifstream configure(configureFile.c_str()); - if (!configure) - return EngineDescList(); + EngineDescList engineList; - std::string line; - EngineDescList engines; + FileList engineFiles = listDirectory(srcDir + "/engines/"); - for (;;) { - std::getline(configure, line); - if (configure.eof()) - break; + // Sort file list alphabetically this allows for a nicer order in + // --list-engines output, for example. + engineFiles.sort(&compareFSNode); - if (configure.fail()) - error("Failed while reading from " + configureFile); + for (FileList::const_iterator i = engineFiles.begin(), end = engineFiles.end(); i != end; ++i) { + // Each engine requires its own sub directory thus we will skip all + // non directory file nodes here. + if (!i->isDirectory) { + continue; + } - EngineDesc desc; - if (parseEngine(line, desc)) - engines.push_back(desc); + // Retrieve all engines defined in this sub directory and add them to + // the list of all engines. + EngineDescList list = parseEngineConfigure(srcDir + "/engines/" + i->name); + engineList.splice(engineList.end(), list); } - return engines; + return engineList; } bool isSubEngine(const std::string &name, const EngineDescList &engines) { @@ -777,6 +765,21 @@ StringList getEngineDefines(const EngineDescList &engines) { } namespace { +/** + * Try to parse a given line and create an engine definition + * out of the result. + * + * This may take *any* input line, when the line is not used + * to define an engine the result of the function will be "false". + * + * Note that the contents of "engine" are undefined, when this + * function returns "false". + * + * @param line Text input line. + * @param engine Reference to an object, where the engine information + * is to be stored in. + * @return "true", when parsing succeeded, "false" otherwise. + */ bool parseEngine(const std::string &line, EngineDesc &engine) { // Format: // add_engine engine_name "Readable Description" enable_default ["SubEngineList"] @@ -799,6 +802,36 @@ bool parseEngine(const std::string &line, EngineDesc &engine) { return true; } + +EngineDescList parseEngineConfigure(const std::string &engineDir) { + std::string configureFile = engineDir + "/configure.engine"; + + std::ifstream configure(configureFile.c_str()); + if (!configure) + return EngineDescList(); + + std::string line; + EngineDescList engines; + + for (;;) { + std::getline(configure, line); + if (configure.eof()) + break; + + if (configure.fail()) + error("Failed while reading from " + configureFile); + + EngineDesc desc; + if (parseEngine(line, desc)) + engines.push_back(desc); + } + + return engines; +} + +bool compareFSNode(const CreateProjectTool::FSNode &left, const CreateProjectTool::FSNode &right) { + return left.name < right.name; +} } // End of anonymous namespace TokenList tokenize(const std::string &input, char separator) { @@ -1048,13 +1081,6 @@ bool compareNodes(const FileNode *l, const FileNode *r) { } } -/** - * Returns a list of all files and directories in the specified - * path. - * - * @param dir Directory which should be listed. - * @return List of all children. - */ FileList listDirectory(const std::string &dir) { FileList result; #ifdef USE_WIN32_API @@ -1242,6 +1268,12 @@ void ProjectProvider::createProject(BuildSetup &setup) { // Create other misc. build files createOtherBuildFiles(setup); + + // In case we create the main ScummVM project files we will need to + // generate engines/plugins_table.h too. + if (!setup.tests && !setup.devTools) { + createEnginePluginsTable(setup); + } } ProjectProvider::UUIDMap ProjectProvider::createUUIDMap(const BuildSetup &setup) const { @@ -1569,6 +1601,33 @@ void ProjectProvider::createModuleList(const std::string &moduleDir, const Strin error("Malformed file " + moduleMkFile); } +void ProjectProvider::createEnginePluginsTable(const BuildSetup &setup) { + const std::string enginePluginsTableFile = setup.outputDir + "/engines/plugins_table.h"; + std::ofstream enginePluginsTable(enginePluginsTableFile.c_str()); + if (!enginePluginsTable) { + error("Could not open \"" + enginePluginsTableFile + "\" for writing"); + } + + enginePluginsTable << "/* This file is automatically generated by create_project */\n" + << "/* DO NOT EDIT MANUALLY */\n" + << "// This file is being included by \"base/plugins.cpp\"\n"; + + for (EngineDescList::const_iterator i = setup.engines.begin(), end = setup.engines.end(); i != end; ++i) { + // We ignore all sub engines here because they require no special + // handling. + if (isSubEngine(i->name, setup.engines)) { + continue; + } + + // Make the engine name all uppercase. + std::string engineName; + std::transform(i->name.begin(), i->name.end(), std::back_inserter(engineName), toupper); + + enginePluginsTable << "#if PLUGIN_ENABLED_STATIC(" << engineName << ")\n" + << "LINK_PLUGIN(" << engineName << ")\n" + << "#endif\n"; + } +} } // End of anonymous namespace void error(const std::string &message) { -- cgit v1.2.3 From c00ab00f250205dc76890965562f5b661055826a Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 7 Nov 2013 12:58:35 +0100 Subject: DEVTOOLS: Factor out function to create directories in create_project. --- devtools/create_project/create_project.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'devtools/create_project/create_project.cpp') diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp index ad3160d778..026cbe07a4 100644 --- a/devtools/create_project/create_project.cpp +++ b/devtools/create_project/create_project.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #endif namespace { @@ -1121,6 +1122,32 @@ FileList listDirectory(const std::string &dir) { return result; } +void createDirectory(const std::string &dir) { +#if defined(_WIN32) || defined(WIN32) + if (!CreateDirectory(dir.c_str(), NULL)) { + if (GetLastError() != ERROR_ALREADY_EXISTS) { + error("Could not create folder \"" + dir + "\""); + } + } +#else + if (mkdir(dir.c_str(), 0777) == -1) { + if (errno == EEXIST) { + // Try to open as a folder (might be a file / symbolic link) + DIR *dirp = opendir(dir.c_str()); + if (dirp == NULL) { + error("Could not create folder \"" + dir + "\""); + } else { + // The folder exists, just close the stream and return + closedir(dirp); + } + } else { + error("Could not create folder \"" + dir + "\""); + } + } +#endif + +} + /** * Scans the specified directory against files, which should be included * in the project files. It will not include files present in the exclude list. -- cgit v1.2.3 From 8b3fc996a16dccccb2de01c75d8eff65c89a969f Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 7 Nov 2013 12:58:35 +0100 Subject: DEVTOOLS: Adapt create_project to create engines/ dir if necessary --- devtools/create_project/create_project.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'devtools/create_project/create_project.cpp') diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp index 026cbe07a4..3eba36e235 100644 --- a/devtools/create_project/create_project.cpp +++ b/devtools/create_project/create_project.cpp @@ -1629,6 +1629,10 @@ void ProjectProvider::createModuleList(const std::string &moduleDir, const Strin } void ProjectProvider::createEnginePluginsTable(const BuildSetup &setup) { + // First we need to create the "engines" directory. + createDirectory(setup.outputDir + "/engines"); + + // Then, we can generate the actual "plugins_table.h" file. const std::string enginePluginsTableFile = setup.outputDir + "/engines/plugins_table.h"; std::ofstream enginePluginsTable(enginePluginsTableFile.c_str()); if (!enginePluginsTable) { -- cgit v1.2.3 From 80136c1e51902d4c63264730e26a7b4aff35e829 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 7 Nov 2013 12:58:35 +0100 Subject: DEVTOOLS: Make create_project sort SCUMM as first engine. This makes create_project output consistent with configure output again. --- devtools/create_project/create_project.cpp | 35 ++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'devtools/create_project/create_project.cpp') diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp index 3eba36e235..16b8e1d166 100644 --- a/devtools/create_project/create_project.cpp +++ b/devtools/create_project/create_project.cpp @@ -674,6 +674,19 @@ EngineDescList parseEngineConfigure(const std::string &engineDir); * the name of the second operand. "false" otherwise. */ bool compareFSNode(const CreateProjectTool::FSNode &left, const CreateProjectTool::FSNode &right); + +#ifdef FIRST_ENGINE +/** + * Compares two FSNode entries in a strict-weak fashion based on engine name + * order. + * + * @param left The first operand. + * @param right The second operand. + * @return "true" when the name of the left operand is strictly smaller than + * the name of the second operand. "false" otherwise. + */ +bool compareEngineNames(const CreateProjectTool::FSNode &left, const CreateProjectTool::FSNode &right); +#endif } // End of anonymous namespace EngineDescList parseEngines(const std::string &srcDir) { @@ -684,9 +697,15 @@ EngineDescList parseEngines(const std::string &srcDir) { FileList engineFiles = listDirectory(srcDir + "/engines/"); - // Sort file list alphabetically this allows for a nicer order in - // --list-engines output, for example. +#ifdef FIRST_ENGINE + // In case we want to sort an engine to the front of the list we will + // use some manual sorting predicate which assures that. + engineFiles.sort(&compareEngineNames); +#else + // Otherwise, we simply sort the file list alphabetically this allows + // for a nicer order in --list-engines output, for example. engineFiles.sort(&compareFSNode); +#endif for (FileList::const_iterator i = engineFiles.begin(), end = engineFiles.end(); i != end; ++i) { // Each engine requires its own sub directory thus we will skip all @@ -833,6 +852,18 @@ EngineDescList parseEngineConfigure(const std::string &engineDir) { bool compareFSNode(const CreateProjectTool::FSNode &left, const CreateProjectTool::FSNode &right) { return left.name < right.name; } + +#ifdef FIRST_ENGINE +bool compareEngineNames(const CreateProjectTool::FSNode &left, const CreateProjectTool::FSNode &right) { + if (left.name == FIRST_ENGINE) { + return right.name != FIRST_ENGINE; + } else if (right.name == FIRST_ENGINE) { + return false; + } else { + return compareFSNode(left, right); + } +} +#endif } // End of anonymous namespace TokenList tokenize(const std::string &input, char separator) { -- cgit v1.2.3 From 441ebc04b0afd2ba768c454c9a20b6320b4cf6a2 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 27 Nov 2013 23:07:57 +0100 Subject: DEVTOOLS: Include 'iterator' for std::back_inserter. --- devtools/create_project/create_project.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'devtools/create_project/create_project.cpp') diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp index 16b8e1d166..9d7ed532cb 100644 --- a/devtools/create_project/create_project.cpp +++ b/devtools/create_project/create_project.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include -- cgit v1.2.3