DEVTOOLS: Factor out function to create directories in create_project.
This commit is contained in:
parent
19a20ad71f
commit
c00ab00f25
3 changed files with 35 additions and 30 deletions
|
@ -59,6 +59,7 @@
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -1121,6 +1122,32 @@ FileList listDirectory(const std::string &dir) {
|
||||||
return result;
|
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
|
* Scans the specified directory against files, which should be included
|
||||||
* in the project files. It will not include files present in the exclude list.
|
* in the project files. It will not include files present in the exclude list.
|
||||||
|
|
|
@ -340,6 +340,13 @@ std::string toString(int num);
|
||||||
*/
|
*/
|
||||||
FileList listDirectory(const std::string &dir);
|
FileList listDirectory(const std::string &dir);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a directory at the given path.
|
||||||
|
*
|
||||||
|
* @param dir The path to create.
|
||||||
|
*/
|
||||||
|
void createDirectory(const std::string &dir);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structure representing a file tree. This contains two
|
* Structure representing a file tree. This contains two
|
||||||
* members: name and children. "name" holds the name of
|
* members: name and children. "name" holds the name of
|
||||||
|
|
|
@ -26,15 +26,6 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(WIN32)
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace CreateProjectTool {
|
namespace CreateProjectTool {
|
||||||
|
|
||||||
#define DEBUG_XCODE_HASH 0
|
#define DEBUG_XCODE_HASH 0
|
||||||
|
@ -88,27 +79,7 @@ XCodeProvider::XCodeProvider(StringList &global_warnings, std::map<std::string,
|
||||||
void XCodeProvider::createWorkspace(const BuildSetup &setup) {
|
void XCodeProvider::createWorkspace(const BuildSetup &setup) {
|
||||||
// Create project folder
|
// Create project folder
|
||||||
std::string workspace = setup.outputDir + '/' + PROJECT_NAME ".xcodeproj";
|
std::string workspace = setup.outputDir + '/' + PROJECT_NAME ".xcodeproj";
|
||||||
|
createDirectory(workspace);
|
||||||
#if defined(_WIN32) || defined(WIN32)
|
|
||||||
if (!CreateDirectory(workspace.c_str(), NULL))
|
|
||||||
if (GetLastError() != ERROR_ALREADY_EXISTS)
|
|
||||||
error("Could not create folder \"" + setup.outputDir + '/' + PROJECT_NAME ".xcodeproj\"");
|
|
||||||
#else
|
|
||||||
if (mkdir(workspace.c_str(), 0777) == -1) {
|
|
||||||
if (errno == EEXIST) {
|
|
||||||
// Try to open as a folder (might be a file / symbolic link)
|
|
||||||
DIR *dirp = opendir(workspace.c_str());
|
|
||||||
if (dirp == NULL) {
|
|
||||||
error("Could not create folder \"" + setup.outputDir + '/' + PROJECT_NAME ".xcodeproj\"");
|
|
||||||
} else {
|
|
||||||
// The folder exists, just close the stream and return
|
|
||||||
closedir(dirp);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error("Could not create folder \"" + setup.outputDir + '/' + PROJECT_NAME ".xcodeproj\"");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Setup global objects
|
// Setup global objects
|
||||||
setupDefines(setup);
|
setupDefines(setup);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue