diff --git a/uppsrc/ide/Android/Android.cpp b/uppsrc/ide/Android/Android.cpp index 89e8eb846..da9231938 100644 --- a/uppsrc/ide/Android/Android.cpp +++ b/uppsrc/ide/Android/Android.cpp @@ -20,4 +20,75 @@ String Android::GetCmdExt() #endif } +void Android::NormalizeVersions(Vector& versions) +{ + String prefix = FindVersionsPrefix(versions); + String longestVersion = FindLongestVersion(versions); + + int longestVersionCount = longestVersion.GetCount(); + for(int i = 0; i < versions.GetCount(); i++) { + int diff = longestVersionCount - versions[i].GetCount(); + if(diff <= 0) + continue; + + String version = versions[i]; + if(!prefix.IsEmpty()) + version.Replace(prefix, ""); + for(int j = 0; j < diff; j++) + version = "0" + version; + versions[i] = prefix + version; + } +} + +void Android::RemoveVersionsNormalization(Vector& versions) +{ + String prefix = FindVersionsPrefix(versions); + for(int i = 0; i < versions.GetCount(); i++) { + String version = versions[i]; + if(!prefix.IsEmpty()) + version.Replace(prefix, ""); + for(;;) { + if(!version.StartsWith("0")) + break; + version.Remove(0); + } + versions[i] = prefix + version; + } +} + +String Android::FindVersionsPrefix(const Vector& versions) +{ + String prefix; + for(int i = 0; i < versions.GetCount(); i++) { + String currentPrefix; + String version = versions[i]; + for(int j = 0; j < 10; j++) { + int idx = version.Find(IntStr(j)); + if(idx < 0) + continue; + String left = version.Left(idx); + if(currentPrefix.IsEmpty() || left.GetCount() < currentPrefix.GetCount()) + currentPrefix = left; + } + if(i == 0) + prefix = currentPrefix; + else + if(i > 0 && currentPrefix != prefix) + return ""; + } + + return prefix; +} + +String Android::FindLongestVersion(const Vector& versions) +{ + String longest; + for(int i = 0; i < versions.GetCount(); i++) { + String current = versions[i]; + if(current.GetCount() > longest.GetCount()) + longest = current; + } + return longest; +} + END_UPP_NAMESPACE diff --git a/uppsrc/ide/Android/Android.h b/uppsrc/ide/Android/Android.h index c5de5c3fd..e88a195c7 100644 --- a/uppsrc/ide/Android/Android.h +++ b/uppsrc/ide/Android/Android.h @@ -14,6 +14,13 @@ public: static String GetScriptExt(); static String GetCmdExt(); + static void NormalizeVersions(Vector& versions); + static void RemoveVersionsNormalization(Vector& versions); + +private: + static String FindVersionsPrefix(const Vector& versions); + static String FindLongestVersion(const Vector& versions); + private: Android(); Android(const Android&); @@ -95,16 +102,22 @@ public: bool Validate() const; + String FindDefaultPlatform() const; String FindDefaultToolchain() const; String FindDefaultCppRuntime() const; + Vector FindPlatforms() const; Vector FindToolchains() const; Vector FindCppRuntimes() const; public: + String GetIncludeDir() const; + + String GetPlatformsDir() const { return path + DIR_SEPS + "platforms"; } + String GetToolchainsDir() const { return path + DIR_SEPS + "toolchains"; } + String GetNdkBuildPath() const { return path + DIR_SEPS + "ndk-build" + Android::GetCmdExt(); } String GetGdbPath() const { return path + DIR_SEPS + "ndk-gdb"; } - String GetToolchainsDir() const { return path + DIR_SEPS + "toolchains"; } public: String GetPath() const { return this->path; } diff --git a/uppsrc/ide/Android/AndroidNDK.cpp b/uppsrc/ide/Android/AndroidNDK.cpp index 2d900074f..88cd58c68 100644 --- a/uppsrc/ide/Android/AndroidNDK.cpp +++ b/uppsrc/ide/Android/AndroidNDK.cpp @@ -30,12 +30,24 @@ bool AndroidNDK::Validate() const return true; } +String AndroidNDK::FindDefaultPlatform() const +{ + Vector platforms = FindPlatforms(); + + Android::NormalizeVersions(platforms); + Sort(platforms, StdGreater()); + Android::RemoveVersionsNormalization(platforms); + + return !platforms.IsEmpty() ? platforms[0] : ""; +} + String AndroidNDK::FindDefaultToolchain() const { Vector toolchains = FindToolchains(); Sort(toolchains, StdGreater()); - return toolchains.GetCount() ? toolchains[toolchains.GetCount() - 1] : ""; + int count = toolchains.GetCount(); + return count ? toolchains[count - 1] : ""; } String AndroidNDK::FindDefaultCppRuntime() const @@ -43,6 +55,18 @@ String AndroidNDK::FindDefaultCppRuntime() const return "gnustl_shared"; } +Vector AndroidNDK::FindPlatforms() const +{ + Vector platforms; + + for(FindFile ff(AppendFileName(GetPlatformsDir(), "*")); ff; ff.Next()) { + if(!ff.IsHidden() && ff.IsFolder()) + platforms.Add(ff.GetName()); + } + + return platforms; +} + Vector AndroidNDK::FindToolchains() const { Vector toolchains; @@ -83,4 +107,15 @@ Vector AndroidNDK::FindCppRuntimes() const return runtimes; } +String AndroidNDK::GetIncludeDir() const +{ + String dir; + dir << GetPlatformsDir() << DIR_SEPS << FindDefaultPlatform() << DIR_SEPS; + // TODO: decide how to implement architecture selection. + dir << "arch-arm" << DIR_SEPS; + dir << "usr" << DIR_SEPS << "include"; + + return DirectoryExists(dir) ? dir : ""; +} + END_UPP_NAMESPACE diff --git a/uppsrc/ide/Android/AndroidSDK.cpp b/uppsrc/ide/Android/AndroidSDK.cpp index a2d899820..cbfbf0040 100644 --- a/uppsrc/ide/Android/AndroidSDK.cpp +++ b/uppsrc/ide/Android/AndroidSDK.cpp @@ -173,7 +173,10 @@ String AndroidSDK::FindDefaultPlatform() const { Vector platforms = FindPlatforms(); if(platforms.GetCount()) { + Android::NormalizeVersions(platforms); Sort(platforms, StdGreater()); + Android::RemoveVersionsNormalization(platforms); + int idx = 0; for(int i = 0; i < platforms.GetCount(); i++) { if(RegExp("^android-[0-9]*$").Match(platforms[i])) { diff --git a/uppsrc/ide/Java/Java.h b/uppsrc/ide/Java/Java.h index 13101a80e..237f5f049 100644 --- a/uppsrc/ide/Java/Java.h +++ b/uppsrc/ide/Java/Java.h @@ -31,6 +31,7 @@ public: public: String GetBinDir() const { return path + DIR_SEPS + "bin"; } + String GetIncludeDir() const { return path + DIR_SEPS + "include"; } String GetJarPath() const { return GetBinDir() + DIR_SEPS + "jar" + GetExeExt(); } String GetJavacPath() const { return GetBinDir() + DIR_SEPS + "javac" + GetExeExt(); } diff --git a/uppsrc/ide/Methods.cpp b/uppsrc/ide/Methods.cpp index ce15806f2..84e6cd4da 100644 --- a/uppsrc/ide/Methods.cpp +++ b/uppsrc/ide/Methods.cpp @@ -832,7 +832,12 @@ String Ide::GetIncludePath() } MergeWith(include, ";", mingw_include[q]); #endif - + if(findarg(bm.Get("BUILDER"), "ANDROID") >= 0) { + AndroidNDK ndk(bm.Get("NDK_PATH")); + if(ndk.Validate()) + MergeWith(include, ";", ndk.GetIncludeDir()); + } + const Workspace& wspc = GetIdeWorkspace(); for(int i = 0; i < wspc.GetCount(); i++) { const Package& pkg = wspc.GetPackage(i);