Make it easy to run Safari in the debugger on Windows
[WebKit-https.git] / WebKitTools / FindSafari / FindSafari.cpp
index f2ec2a8d8a8a6faa0bc01daf3f157da0ac6bfff6..46e10a9fd841d0694f0035dc2b4aed39bd2021cb 100644 (file)
@@ -128,19 +128,46 @@ int _tmain(int argc, TCHAR* argv[])
         return 1;
     }
 
-    if (argc < 2 || _tcscmp(argv[1], TEXT("/printSafariLauncher"))) {
-        _tprintf(TEXT("%s"), path);
+    bool printLauncher = false;
+    bool debugger = false;
+
+    for (int i = 1; i < argc; ++i) {
+        if (!_tcscmp(argv[i], TEXT("/printSafariLauncher"))) {
+            printLauncher = true;
+            continue;
+        }
+        if (!_tcscmp(argv[i], TEXT("/debugger"))) {
+            debugger = true;
+            continue;
+        }
+    }
+
+    if (!printLauncher) {
+        _tprintf(TEXT("%s\n"), path);
         free(path);
         return 0;
     }
 
-    TCHAR* lines[] = {
+    LPCTSTR lines[] = {
         TEXT("@echo off"),
         TEXT("mkdir 2>NUL \"%%TMP%%\\WebKitNightly\\Safari.resources\""),
         TEXT("xcopy /y /i /d \"%sSafari.exe\" \"%%TMP%%\\WebKitNightly\""),
         TEXT("xcopy /y /i /d /e \"%sSafari.resources\" \"%%TMP%%\\WebKitNightly\\Safari.resources\""),
         TEXT("set PATH=\"%%CD%%;%s;%%PATH%%\""),
-        TEXT("\"%%TMP%%\\WebKitNightly\\Safari.exe\" /customWebKit"),
+    };
+
+    LPCTSTR command = TEXT("\"%TMP%\\WebKitNightly\\Safari.exe\" /customWebKit");
+
+    LPCTSTR launchLines[] = {
+        TEXT("%s"),
+    };
+
+    LPCTSTR debuggerLines[] = {
+        TEXT("if exist \"%%DevEnvDir%%\\VCExpress.exe\" ("),
+        TEXT("\"%%DevEnvDir%%\\VCExpress.exe\" /debugExe %s"),
+        TEXT(") else ("),
+        TEXT("\"%%DevEnvDir%%\\devenv.exe\" /debugExe %s"),
+        TEXT(")"),
     };
 
     for (int i = 0; i < ARRAYSIZE(lines); ++i) {
@@ -148,6 +175,12 @@ int _tmain(int argc, TCHAR* argv[])
         _tprintf(TEXT("\n"));
     }
 
+    LPCTSTR* endLines = debugger ? debuggerLines : launchLines;
+    for (unsigned i = 0; i < (debugger ? ARRAYSIZE(debuggerLines) : ARRAYSIZE(launchLines)); ++i) {
+        _tprintf(endLines[i], command);
+        _tprintf(TEXT("\n"));
+    }
+
     free(path);
     return 0;
 }