summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunghyun Kim <jh0822.kim@samsung.com>2016-08-04 22:28:18 (GMT)
committerSoonKyu Park <sk7.park@samsung.com>2018-04-03 02:28:16 (GMT)
commit814fe929db909dafdd28e81d4fade1bd4005e3fc (patch)
tree21aac3450f9f77faafa225ae83d2f049bffd8d59
parentea9b66c926d0c3654d9fec12b009414a7108e80a (diff)
downloadcmake-814fe929db909dafdd28e81d4fade1bd4005e3fc.zip
cmake-814fe929db909dafdd28e81d4fade1bd4005e3fc.tar.gz
cmake-814fe929db909dafdd28e81d4fade1bd4005e3fc.tar.bz2
List of files are sorted when using aux_source_directory() and file(glob).
If aux_source_directory(. SRCS) or file(glob SRCS "*.c") is used, files in SRCS are not sorted. This can cause different orders of files across machines. Even though it does not have any correctness issue, there is a problem. If we have a build infrastructure (e.g., OBS), the result binaries can be different on each machine. In this case, build results can be different on two different machines even if we have the same source files. For example, 1. ld -o liba.a a.o b.o SRCS=a.c b.c 2. ld -o libb.a b.o a.o SRCS=b.c a.c Then, liba.a and libb.a are different. REASON This is because of the system call readdir(). The system call readdir() returns a file in the directory in any order. SOLUTION Intead of readdir(), scandir() is used with alphasort(). This makes the list of files are sorted alphabetically. AMENDED 1. another free() is added to free malloc()ed objects (Reviewed by Chan Lee). 2. remove "#include <errno.h>" (Reviewed by Chan Lee). Change-Id: Id8aff23b2761ea04c1c49c91fcc511b9bc2b1228 Signed-off-by: Junghyun Kim <jh0822.kim@samsung.com>
-rw-r--r--Source/kwsys/Directory.cxx25
1 files changed, 16 insertions, 9 deletions
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx
index 5141d45..8049909 100644
--- a/Source/kwsys/Directory.cxx
+++ b/Source/kwsys/Directory.cxx
@@ -180,6 +180,8 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
#include <sys/types.h>
#include <dirent.h>
+#include <stdio.h>
+#include <malloc.h>
// PGI with glibc has trouble with dirent and large file support:
// http://www.pgroup.com/userforum/viewtopic.php?
@@ -201,17 +203,22 @@ bool Directory::Load(const std::string& name)
{
this->Clear();
- DIR* dir = opendir(name.c_str());
-
- if (!dir) {
+ struct dirent** namelist;
+ int num_entries = scandir(name, &namelist, NULL, alphasort);
+ if(num_entries == -1)
+ {
+ printf("name=%s\n", name);
+ perror("scandir");
return 0;
- }
-
- for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir)) {
- this->Internal->Files.push_back(d->d_name);
- }
+ }
+
+ for( int i = 0; i < num_entries; ++i )
+ {
+ this->Internal->Files.push_back(namelist[i]->d_name);
+ free(namelist[i]);
+ }
+ free(namelist);
this->Internal->Path = name;
- closedir(dir);
return 1;
}