IOS: Compute MD5 identifiers instead of random

To avoid recompiling the wole project each time we use the create_project tool.
This commit is contained in:
Vincent Bénony 2015-12-09 15:32:52 +01:00
parent 66c195f55e
commit ee73bb428f
3 changed files with 39 additions and 8 deletions

View File

@ -26,6 +26,12 @@
#include <fstream>
#include <algorithm>
#ifdef MACOSX
#include <sstream>
#include <iomanip>
#include <CommonCrypto/CommonCrypto.h>
#endif
namespace CreateProjectTool {
#define DEBUG_XCODE_HASH 0
@ -1008,7 +1014,6 @@ void XcodeProvider::setupDefines(const BuildSetup &setup) {
// Object hash
//////////////////////////////////////////////////////////////////////////
// TODO use md5 to compute a file hash (and fall back to standard key generation if not passed a file)
std::string XcodeProvider::getHash(std::string key) {
#if DEBUG_XCODE_HASH
@ -1020,7 +1025,12 @@ std::string XcodeProvider::getHash(std::string key) {
return hashIterator->second;
// Generate a new key from the file hash and insert it into the dictionary
#ifdef MACOSX
std::string hash = md5(key);
#else
std::string hash = newHash();
#endif
_hashDictionnary[key] = hash;
return hash;
@ -1029,6 +1039,19 @@ std::string XcodeProvider::getHash(std::string key) {
bool isSeparator (char s) { return (s == '-'); }
#ifdef MACOSX
std::string XcodeProvider::md5(std::string key) {
unsigned char md[CC_MD5_DIGEST_LENGTH];
CC_MD5(key.c_str(), (CC_LONG) key.length(), md);
std::stringstream stream;
stream << std::hex << std::setfill('0') << std::setw(2);
for (int i=0; i<CC_MD5_DIGEST_LENGTH; i++) {
stream << (unsigned int) md[i];
}
return stream.str();
}
#endif
std::string XcodeProvider::newHash() const {
std::string hash = createUUID();

View File

@ -340,6 +340,9 @@ private:
// Hash generation
std::string getHash(std::string key);
#ifdef MACOSX
std::string md5(std::string key);
#endif
std::string newHash() const;
// Output

View File

@ -141,6 +141,7 @@
F9A66C1E1396D36100CEE494 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0720;
};
buildConfigurationList = F9A66C211396D36100CEE494 /* Build configuration list for PBXProject "create_project" */;
compatibilityVersion = "Xcode 3.2";
@ -179,12 +180,14 @@
F9A66C2E1396D36100CEE494 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
GCC_PREPROCESSOR_DEFINITIONS = (
POSIX,
MACOSX,
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@ -197,9 +200,11 @@
F9A66C2F1396D36100CEE494 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_PREPROCESSOR_DEFINITIONS = (
POSIX,
MACOSX,
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@ -216,8 +221,8 @@
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
DEBUG,
POSIX,
);
PRODUCT_NAME = "$(TARGET_NAME)";
};
@ -230,7 +235,7 @@
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_PREPROCESSOR_DEFINITIONS = POSIX;
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;