[Scummvm-git-logs] scummvm master -> b0bc79599920c42d341c6ae1ed76897a93c15aee

SupSuper supsuper at gmail.com
Wed Nov 11 10:26:15 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b0bc795999 CREATE_PROJECT: Don't include files with the same name but different paths


Commit: b0bc79599920c42d341c6ae1ed76897a93c15aee
    https://github.com/scummvm/scummvm/commit/b0bc79599920c42d341c6ae1ed76897a93c15aee
Author: SupSuper (supsuper at gmail.com)
Date: 2020-11-11T10:24:59Z

Commit Message:
CREATE_PROJECT: Don't include files with the same name but different paths

Changed paths:
    devtools/create_project/cmake.cpp
    devtools/create_project/codeblocks.cpp
    devtools/create_project/create_project.cpp
    devtools/create_project/create_project.h
    devtools/create_project/msbuild.cpp
    devtools/create_project/visualstudio.cpp
    devtools/create_project/xcode.cpp


diff --git a/devtools/create_project/cmake.cpp b/devtools/create_project/cmake.cpp
index 2f5af0c5d7..dfec5d3614 100644
--- a/devtools/create_project/cmake.cpp
+++ b/devtools/create_project/cmake.cpp
@@ -264,7 +264,7 @@ void CMakeProvider::createProjectFile(const std::string &name, const std::string
 			modulePath.erase(0, 1);
 	}
 
-	if (modulePath.size())
+	if (!modulePath.empty())
 		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix + '/' + modulePath);
 	else
 		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix);
diff --git a/devtools/create_project/codeblocks.cpp b/devtools/create_project/codeblocks.cpp
index ff6ce90f3a..06f16f5da8 100644
--- a/devtools/create_project/codeblocks.cpp
+++ b/devtools/create_project/codeblocks.cpp
@@ -202,7 +202,7 @@ void CodeBlocksProvider::createProjectFile(const std::string &name, const std::s
 			modulePath.erase(0, 1);
 	}
 
-	if (modulePath.size())
+	if (!modulePath.empty())
 		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix + '/' + modulePath);
 	else
 		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix);
diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp
index 6741e173b6..bdc21ed964 100644
--- a/devtools/create_project/create_project.cpp
+++ b/devtools/create_project/create_project.cpp
@@ -1266,6 +1266,12 @@ void splitFilename(const std::string &fileName, std::string &name, std::string &
 	ext = (dot == std::string::npos) ? std::string() : fileName.substr(dot + 1);
 }
 
+void splitPath(const std::string &path, std::string &dir, std::string &file) {
+	const std::string::size_type sep = path.find_last_of('/');
+	dir = (sep == std::string::npos) ? path : path.substr(0, sep);
+	file = (sep == std::string::npos) ? std::string() : path.substr(sep + 1);
+}
+
 std::string basename(const std::string &fileName) {
 	const std::string::size_type slash = fileName.find_last_of('/');
 	if (slash == std::string::npos)
@@ -1273,14 +1279,14 @@ std::string basename(const std::string &fileName) {
 	return fileName.substr(slash + 1);
 }
 
+bool producesObjectExtension(const std::string &ext) {
+	return (ext == "cpp" || ext == "c" || ext == "asm" || ext == "m" || ext == "mm");
+}
+
 bool producesObjectFile(const std::string &fileName) {
 	std::string n, ext;
 	splitFilename(fileName, n, ext);
-
-	if (ext == "cpp" || ext == "c" || ext == "asm" || ext == "m" || ext == "mm")
-		return true;
-	else
-		return false;
+	return producesObjectExtension(ext);
 }
 
 std::string toString(int num) {
@@ -1293,10 +1299,10 @@ std::string toString(int num) {
  * Checks whether the give file in the specified directory is present in the given
  * file list.
  *
- * This function does as special match against the file list. Object files (.o) are
- * excluded by default and it will not take file extensions into consideration,
- * when the extension of a file in the specified directory is one of "h", "cpp",
- * "c" or "asm".
+ * This function does as special match against the file list.
+ * By default object files (.o) are excluded, header files (.h) are included,
+ * and it will not take file extensions into consideration, when the extension
+ * of a file in the specified directory is one of "m", "cpp", "c" or "asm".
  *
  * @param dir Parent directory of the file.
  * @param fileName File name to match.
@@ -1304,6 +1310,9 @@ std::string toString(int num) {
  * @return "true" when the file is in the list, "false" otherwise.
  */
 bool isInList(const std::string &dir, const std::string &fileName, const StringList &fileList) {
+	if (fileList.empty())
+		return false;
+
 	std::string compareName, extensionName;
 	splitFilename(fileName, compareName, extensionName);
 
@@ -1311,28 +1320,34 @@ bool isInList(const std::string &dir, const std::string &fileName, const StringL
 		compareName += '.';
 
 	for (StringList::const_iterator i = fileList.begin(); i != fileList.end(); ++i) {
-		if (i->compare(0, dir.size(), dir))
-			continue;
 
 		// When no comparison name is given, we try to match whether a subset of
 		// the given directory should be included. To do that we must assure that
 		// the first character after the substring, having the same size as dir, must
 		// be a path delimiter.
 		if (compareName.empty()) {
+			if (i->compare(0, dir.size(), dir))
+				continue;
 			if (i->size() >= dir.size() + 1 && i->at(dir.size()) == '/')
 				return true;
 			else
 				continue;
 		}
 
-		const std::string lastPathComponent = ProjectProvider::getLastPathComponent(*i);
+		std::string listDir, listFile;
+		splitPath(*i, listDir, listFile);
+		if (dir.compare(0, listDir.size(), listDir))
+			continue;
+
 		if (extensionName == "o") {
 			return false;
-		} else if (!producesObjectFile(fileName) && extensionName != "h") {
-			if (fileName == lastPathComponent)
+		} else if (extensionName == "h") {
+			return true;
+		} else if (!producesObjectExtension(extensionName)) {
+			if (fileName == listFile)
 				return true;
 		} else {
-			if (!lastPathComponent.compare(0, compareName.size(), compareName))
+			if (!listFile.compare(0, compareName.size(), compareName))
 				return true;
 		}
 	}
@@ -1470,10 +1485,8 @@ FileNode *scanFiles(const std::string &dir, const StringList &includeList, const
 		std::string name, ext;
 		splitFilename(i->name, name, ext);
 
-		if (ext != "h") {
-			if (!isInList(dir, i->name, includeList))
-				continue;
-		}
+		if (!isInList(dir, i->name, includeList))
+			continue;
 
 		FileNode *child = new FileNode(i->name);
 		assert(child);
@@ -1555,7 +1568,7 @@ void ProjectProvider::createProject(BuildSetup &setup) {
 			createModuleList(*i, setup.defines, setup.testDirs, in, ex, true);
 		}
 
-		createProjectFile(detProject, detUUID, setup, setup.srcDir, in, ex);
+		createProjectFile(detProject, detUUID, setup, setup.srcDir + "/engines", in, ex);
 	}
 
 	if (setup.tests) {
diff --git a/devtools/create_project/create_project.h b/devtools/create_project/create_project.h
index cfd8146d1d..4961fe4581 100644
--- a/devtools/create_project/create_project.h
+++ b/devtools/create_project/create_project.h
@@ -384,6 +384,17 @@ std::string convertPathToWin(const std::string &path);
  */
 void splitFilename(const std::string &fileName, std::string &name, std::string &ext);
 
+/**
+ * Splits a full path into directory and filename.
+ * This assumes the last part is the filename, even if it
+ * has no extension.
+ *
+ * @param path Path to split
+ * @param name Reference to a string, where to store the directory part.
+ * @param ext Reference to a string, where to store the filename part.
+ */
+void splitPath(const std::string &path, std::string &dir, std::string &file);
+
 /**
  * Returns the basename of a path.
  * examples:
diff --git a/devtools/create_project/msbuild.cpp b/devtools/create_project/msbuild.cpp
index 73b344f9f2..f628bdbf44 100644
--- a/devtools/create_project/msbuild.cpp
+++ b/devtools/create_project/msbuild.cpp
@@ -153,7 +153,7 @@ void MSBuildProvider::createProjectFile(const std::string &name, const std::stri
 			modulePath.erase(0, 1);
 	}
 
-	if (modulePath.size())
+	if (!modulePath.empty())
 		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix + '/' + modulePath);
 	else
 		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix);
diff --git a/devtools/create_project/visualstudio.cpp b/devtools/create_project/visualstudio.cpp
index fc12ebe2ec..e436ae8084 100644
--- a/devtools/create_project/visualstudio.cpp
+++ b/devtools/create_project/visualstudio.cpp
@@ -118,7 +118,7 @@ void VisualStudioProvider::createProjectFile(const std::string &name, const std:
 			modulePath.erase(0, 1);
 	}
 
-	if (modulePath.size())
+	if (!modulePath.empty())
 		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix + '/' + modulePath);
 	else
 		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix);
diff --git a/devtools/create_project/xcode.cpp b/devtools/create_project/xcode.cpp
index 9f63b00bf1..e34d637ff8 100644
--- a/devtools/create_project/xcode.cpp
+++ b/devtools/create_project/xcode.cpp
@@ -329,7 +329,7 @@ void XcodeProvider::createProjectFile(const std::string &, const std::string &,
 	}
 
 	std::ofstream project;
-	if (modulePath.size())
+	if (!modulePath.empty())
 		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix + '/' + modulePath);
 	else
 		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix);




More information about the Scummvm-git-logs mailing list