Skip to content

[5.6][swift-stdlib-tool] Fix finding sibling directories #41262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions tools/swift-stdlib-tool/swift-stdlib-tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,21 @@ std::vector<uint8_t> query_code_signature(std::string file) {
}

template <typename F>
void enumerateDirectory(std::string directory, F &&func) {
void listDirectoryContents(std::string directory, F &&func) {
DIR *dir = opendir(directory.c_str());
if (dir == NULL) {
return;
}

struct dirent *entry;
while ((entry = readdir(dir))) {
func(directory + "/" + entry->d_name);
}
closedir(dir);
}

template <typename F>
void recursivelyListFiles(std::string directory, F &&func) {
DIR *dir = opendir(directory.c_str());
if (dir == NULL) {
return;
Expand All @@ -975,7 +989,7 @@ void enumerateDirectory(std::string directory, F &&func) {
}
closedir(dir);
for (const auto &path : subpaths) {
enumerateDirectory(path, func);
recursivelyListFiles(path, func);
}
}

Expand Down Expand Up @@ -1085,7 +1099,7 @@ int main(int argc, const char *argv[]) {
std::string root_path =
parentPath(parentPath(self_executable)) + "/" + "lib";

enumerateDirectory(root_path, [&](std::string entry) {
listDirectoryContents(root_path, [&](std::string entry) {
if (filename(entry).compare(0, strlen("swift-"), "swift-") == 0) {
src_dirs.push_back(entry + "/" + platform);
}
Expand Down Expand Up @@ -1119,7 +1133,7 @@ int main(int argc, const char *argv[]) {

// Collect executables from the --scan-folder locations.
for (const auto &embedDir : embedDirs) {
enumerateDirectory(embedDir, [&](std::string entry) {
recursivelyListFiles(embedDir, [&](std::string entry) {
if (0 == access(entry.c_str(), X_OK)) {
executables.push_back(entry);
} else {
Expand Down