[cfe-commits] r89517 - /cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
John Thompson
john.thompson.jtsoftware at gmail.com
Mon Nov 23 15:15:27 PST 2009
Daniel,
It worked find on a clean machine.
Is there any chance you could step through getSystemRegistryString on that
machine (with some test or source file that includes something like stdio.h,
and see where it fails? I can't imagine why it wouldn't be working. The
registry stuff is pretty consistent.
-John
On Mon, Nov 23, 2009 at 9:52 AM, John Thompson <
john.thompson.jtsoftware at gmail.com> wrote:
> Sorry about that. I don't know what's wrong yet, so I put back the
> hard-coded paths.
>
> Meanwhile, I'm setting up my spare machine, which is pretty clean, with VC9
> and the needed tools and will see if it happens there.
> -John
> On Sat, Nov 21, 2009 at 8:39 PM, Daniel Dunbar <daniel at zuster.org>wrote:
>
>> Hi John,
>>
>> It looks like this broke the windows buildbot, can you take a look, or
>> tell me what I should check (in the registry) to see what it is
>> failing.
>>
>> I recently upgraded the Windows box to be a very straightforward
>> out-of-the-box XP + VS 2009 install (+ gnuwin32), so this is
>> definitely a platform I would hope keeps working OOTB.
>>
>> - Daniel
>>
>> On Fri, Nov 20, 2009 at 4:15 PM, John Thompson
>> <John.Thompson.JTSoftware at gmail.com> wrote:
>> > Author: jtsoftware
>> > Date: Fri Nov 20 18:15:52 2009
>> > New Revision: 89517
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=89517&view=rev
>> > Log:
>> > Revised Win32 include path to search highest version in registry, plus
>> platform SDK path
>> >
>> > Modified:
>> > cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
>> >
>> > Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
>> > URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=89517&r1=89516&r2=89517&view=diff
>> >
>> >
>> ==============================================================================
>> > --- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
>> > +++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Fri Nov 20 18:15:52 2009
>> > @@ -194,7 +194,15 @@
>> >
>> > // FIXME: This probably should goto to some platform utils place.
>> > #ifdef _MSC_VER
>> > +
>> > // Read registry string.
>> > + // This also supports a means to look for high-versioned keys by use
>> > + // of a $VERSION placeholder in the key path.
>> > + // $VERSION in the key path is a placeholder for the version number,
>> > + // causing the highest value path to be searched for and used.
>> > + // I.e.
>> "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION".
>> > + // There can be additional characters in the component. Only the
>> numberic
>> > + // characters are compared.
>> > bool getSystemRegistryString(const char *keyPath, const char
>> *valueName,
>> > char *value, size_t maxLength) {
>> > HKEY hRootKey = NULL;
>> > @@ -202,6 +210,7 @@
>> > const char* subKey = NULL;
>> > DWORD valueType;
>> > DWORD valueSize = maxLength - 1;
>> > + long lResult;
>> > bool returnValue = false;
>> > if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) {
>> > hRootKey = HKEY_CLASSES_ROOT;
>> > @@ -221,13 +230,80 @@
>> > }
>> > else
>> > return(false);
>> > - long lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey);
>> > - if (lResult == ERROR_SUCCESS) {
>> > - lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
>> > - (LPBYTE)value, &valueSize);
>> > - if (lResult == ERROR_SUCCESS)
>> > - returnValue = true;
>> > - RegCloseKey(hKey);
>> > + const char *placeHolder = strstr(subKey, "$VERSION");
>> > + char bestName[256];
>> > + bestName[0] = '\0';
>> > + // If we have a $VERSION placeholder, do the highest-version search.
>> > + if (placeHolder) {
>> > + const char *keyEnd = placeHolder - 1;
>> > + const char *nextKey = placeHolder;
>> > + // Find end of previous key.
>> > + while ((keyEnd > subKey) && (*keyEnd != '\\'))
>> > + keyEnd--;
>> > + // Find end of key containing $VERSION.
>> > + while (*nextKey && (*nextKey != '\\'))
>> > + nextKey++;
>> > + size_t partialKeyLength = keyEnd - subKey;
>> > + char partialKey[256];
>> > + if (partialKeyLength > sizeof(partialKey))
>> > + partialKeyLength = sizeof(partialKey);
>> > + strncpy(partialKey, subKey, partialKeyLength);
>> > + partialKey[partialKeyLength] = '\0';
>> > + HKEY hTopKey = NULL;
>> > + lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ,
>> &hTopKey);
>> > + if (lResult == ERROR_SUCCESS) {
>> > + char keyName[256];
>> > + int bestIndex = -1;
>> > + double bestValue = 0.0;
>> > + DWORD index, size = sizeof(keyName) - 1;
>> > + for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size,
>> NULL,
>> > + NULL, NULL, NULL) == ERROR_SUCCESS; index++) {
>> > + const char *sp = keyName;
>> > + while (*sp && !isdigit(*sp))
>> > + sp++;
>> > + if (!*sp)
>> > + continue;
>> > + const char *ep = sp + 1;
>> > + while (*ep && (isdigit(*ep) || (*ep == '.')))
>> > + ep++;
>> > + char numBuf[32];
>> > + strncpy(numBuf, sp, sizeof(numBuf) - 1);
>> > + numBuf[sizeof(numBuf) - 1] = '\0';
>> > + double value = strtod(numBuf, NULL);
>> > + if (value > bestValue) {
>> > + bestIndex = (int)index;
>> > + bestValue = value;
>> > + strcpy(bestName, keyName);
>> > + }
>> > + size = sizeof(keyName) - 1;
>> > + }
>> > + // If we found the highest versioned key, open the key and get
>> the value.
>> > + if (bestIndex != -1) {
>> > + // Append rest of key.
>> > + strncat(bestName, nextKey, sizeof(bestName) - 1);
>> > + bestName[sizeof(bestName) - 1] = '\0';
>> > + // Open the chosen key path remainder.
>> > + lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey);
>> > + if (lResult == ERROR_SUCCESS) {
>> > + lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
>> > + (LPBYTE)value, &valueSize);
>> > + if (lResult == ERROR_SUCCESS)
>> > + returnValue = true;
>> > + RegCloseKey(hKey);
>> > + }
>> > + }
>> > + RegCloseKey(hTopKey);
>> > + }
>> > + }
>> > + else {
>> > + lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey);
>> > + if (lResult == ERROR_SUCCESS) {
>> > + lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
>> > + (LPBYTE)value, &valueSize);
>> > + if (lResult == ERROR_SUCCESS)
>> > + returnValue = true;
>> > + RegCloseKey(hKey);
>> > + }
>> > }
>> > return(returnValue);
>> > }
>> > @@ -240,35 +316,13 @@
>> >
>> > // Get Visual Studio installation directory.
>> > bool getVisualStudioDir(std::string &path) {
>> > + char vsIDEInstallDir[256];
>> > // Try the Windows registry first.
>> > - char vs80IDEInstallDir[256];
>> > - char vs90IDEInstallDir[256];
>> > - const char* vsIDEInstallDir = NULL;
>> > - bool has80 = getSystemRegistryString(
>> > - "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0",
>> > - "InstallDir", vs80IDEInstallDir, sizeof(vs80IDEInstallDir) - 1);
>> > - bool has90 = getSystemRegistryString(
>> > - "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0",
>> > - "InstallDir", vs90IDEInstallDir, sizeof(vs90IDEInstallDir) - 1);
>> > + bool hasVCDir = getSystemRegistryString(
>> > + "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION",
>> > + "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1);
>> > // If we have both vc80 and vc90, pick version we were compiled
>> with.
>> > - if (has80 && has90) {
>> > - #ifdef _MSC_VER
>> > - #if (_MSC_VER >= 1500) // VC90
>> > - vsIDEInstallDir = vs90IDEInstallDir;
>> > - #elif (_MSC_VER == 1400) // VC80
>> > - vsIDEInstallDir = vs80IDEInstallDir;
>> > - #else
>> > - vsIDEInstallDir = vs90IDEInstallDir;
>> > - #endif
>> > - #else
>> > - vsIDEInstallDir = vs90IDEInstallDir;
>> > - #endif
>> > - }
>> > - else if (has90)
>> > - vsIDEInstallDir = vs90IDEInstallDir;
>> > - else if (has80)
>> > - vsIDEInstallDir = vs80IDEInstallDir;
>> > - if (vsIDEInstallDir && *vsIDEInstallDir) {
>> > + if (hasVCDir && vsIDEInstallDir[0]) {
>> > char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE");
>> > if (p)
>> > *p = '\0';
>> > @@ -307,6 +361,21 @@
>> > return(false);
>> > }
>> >
>> > + // Get Windows SDK installation directory.
>> > +bool getWindowsSDKDir(std::string &path) {
>> > + char windowsSDKInstallDir[256];
>> > + // Try the Windows registry.
>> > + bool hasSDKDir = getSystemRegistryString(
>> > + "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft
>> SDKs\\Windows\\$VERSION",
>> > + "InstallationFolder", windowsSDKInstallDir,
>> sizeof(windowsSDKInstallDir) - 1);
>> > + // If we have both vc80 and vc90, pick version we were compiled
>> with.
>> > + if (hasSDKDir && windowsSDKInstallDir[0]) {
>> > + path = windowsSDKInstallDir;
>> > + return(true);
>> > + }
>> > + return(false);
>> > +}
>> > +
>> > void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple
>> &triple) {
>> > // FIXME: temporary hack: hard-coded paths.
>> > llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS);
>> > @@ -324,29 +393,14 @@
>> > case llvm::Triple::Win32:
>> > {
>> > std::string VSDir;
>> > + std::string WindowsSDKDir;
>> > if (getVisualStudioDir(VSDir)) {
>> > AddPath(VSDir + "\\VC\\include", System, false, false, false);
>> > - AddPath(VSDir + "\\VC\\PlatformSDK\\Include",
>> > - System, false, false, false);
>> > - }
>> > - else {
>> > - // Default install paths.
>> > - AddPath("C:/Program Files/Microsoft Visual Studio
>> 9.0/VC/include",
>> > - System, false, false, false);
>> > - AddPath(
>> > - "C:/Program Files/Microsoft Visual Studio
>> 9.0/VC/PlatformSDK/Include",
>> > - System, false, false, false);
>> > - AddPath("C:/Program Files/Microsoft Visual Studio
>> 8/VC/include",
>> > - System, false, false, false);
>> > - AddPath(
>> > - "C:/Program Files/Microsoft Visual Studio
>> 8/VC/PlatformSDK/Include",
>> > - System, false, false, false);
>> > - // For some clang developers.
>> > - AddPath("G:/Program Files/Microsoft Visual Studio
>> 9.0/VC/include",
>> > - System, false, false, false);
>> > - AddPath(
>> > - "G:/Program Files/Microsoft Visual Studio
>> 9.0/VC/PlatformSDK/Include",
>> > - System, false, false, false);
>> > + if (getWindowsSDKDir(WindowsSDKDir))
>> > + AddPath(WindowsSDKDir, System, false, false, false);
>> > + else
>> > + AddPath(VSDir + "\\VC\\PlatformSDK\\Include",
>> > + System, false, false, false);
>> > }
>> > }
>> > break;
>> >
>> >
>> > _______________________________________________
>> > cfe-commits mailing list
>> > cfe-commits at cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>> >
>>
>
>
>
> --
> John Thompson
> John.Thompson.JTSoftware at gmail.com
>
>
--
John Thompson
John.Thompson.JTSoftware at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20091123/93e29680/attachment.html>
More information about the cfe-commits
mailing list