[Git][ghc/ghc][master] 2 commits: rts: Drop .wasm suffix from .prof file names

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Sat Mar 9 08:42:46 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
5580e1bd by Ben Gamari at 2024-03-09T03:41:30-05:00
rts: Drop .wasm suffix from .prof file names

This replicates the behavior on Windows, where `Hi.exe` will produce
profiling output named `Hi.prof` instead of `Hi.exe.prof`.

While in the area I also fixed the extension-stripping logic, which
incorrectly rewrote `Hi.exefoo` to `Hi.foo`.

Closes #24515.

- - - - -
259495ee by Cheng Shao at 2024-03-09T03:41:30-05:00
testsuite: drop exe extension from .hp & .prof filenames

See #24515 for details.

- - - - -


5 changed files:

- rts/ProfHeap.c
- rts/Profiling.c
- rts/RtsUtils.c
- rts/RtsUtils.h
- testsuite/driver/testlib.py


Changes:

=====================================
rts/ProfHeap.c
=====================================
@@ -448,18 +448,14 @@ initHeapProfiling(void)
         stem = stgMallocBytes(strlen(RtsFlags.CcFlags.outputFileNameStem) + 1, "initHeapProfiling");
         strcpy(stem, RtsFlags.CcFlags.outputFileNameStem);
     } else {
-
         stem = stgMallocBytes(strlen(prog_name) + 1, "initHeapProfiling");
         strcpy(stem, prog_name);
+
+        // Drop the platform's executable suffix if there is one
 #if defined(mingw32_HOST_OS)
-            // on Windows, drop the .exe suffix if there is one
-            {
-                char *suff;
-                suff = strrchr(stem,'.');
-                if (suff != NULL && !strcmp(suff,".exe")) {
-                    *suff = '\0';
-                }
-            }
+        dropExtension(stem, ".exe");
+#elif defined(wasm32_HOST_ARCH)
+        dropExtension(stem, ".wasm");
 #endif
     }
 


=====================================
rts/Profiling.c
=====================================
@@ -245,19 +245,14 @@ initProfilingLogFile(void)
     if (RtsFlags.CcFlags.outputFileNameStem) {
         stem = RtsFlags.CcFlags.outputFileNameStem;
     } else {
-        char *prog;
-
-        prog = arenaAlloc(prof_arena, strlen(prog_name) + 1);
+        char *prog = arenaAlloc(prof_arena, strlen(prog_name) + 1);
         strcpy(prog, prog_name);
+
+        // Drop the platform's executable suffix if there is one
 #if defined(mingw32_HOST_OS)
-        // on Windows, drop the .exe suffix if there is one
-        {
-            char *suff;
-            suff = strrchr(prog,'.');
-            if (suff != NULL && !strcmp(suff,".exe")) {
-                *suff = '\0';
-            }
-        }
+        dropExtension(prog, ".exe");
+#elif defined(wasm32_HOST_ARCH)
+        dropExtension(prog, ".wasm");
 #endif
         stem = prog;
     }


=====================================
rts/RtsUtils.c
=====================================
@@ -456,3 +456,15 @@ void checkFPUStack(void)
     }
 #endif
 }
+
+// Drop the given extension from a filepath.
+void dropExtension(char *path, const char *extension) {
+    int ext_len = strlen(extension);
+    int path_len = strlen(path);
+    if (ext_len < path_len) {
+        char *s = &path[path_len - ext_len];
+        if (strcmp(s, extension) == 0) {
+            *s = '\0';
+        }
+    }
+}


=====================================
rts/RtsUtils.h
=====================================
@@ -62,4 +62,7 @@ void checkFPUStack(void);
 #define xstr(s) str(s)
 #define str(s) #s
 
+// Drop the given extension from a filepath.
+void dropExtension(char *path, const char *extension);
+
 #include "EndPrivate.h"


=====================================
testsuite/driver/testlib.py
=====================================
@@ -2329,14 +2329,13 @@ def write_file(f: Path, s: str) -> None:
 
 async def check_hp_ok(name: TestName) -> bool:
     opts = getTestOpts()
-    actual_name = name + exe_extension() if not opts.ignore_extension else name
 
     # do not qualify for hp2ps because we should be in the right directory
-    hp2psCmd = 'cd "{opts.testdir}" && {{hp2ps}} {actual_name}'.format(**locals())
+    hp2psCmd = 'cd "{opts.testdir}" && {{hp2ps}} {name}'.format(**locals())
 
     hp2psResult = await runCmd(hp2psCmd, print_output=True)
 
-    actual_ps_path = in_testdir(actual_name, 'ps')
+    actual_ps_path = in_testdir(name, 'ps')
 
     if hp2psResult == 0:
         if actual_ps_path.exists():
@@ -2345,15 +2344,15 @@ async def check_hp_ok(name: TestName) -> bool:
                 if (gsResult == 0):
                     return True
                 else:
-                    print("hp2ps output for " + actual_name + " is not valid PostScript")
+                    print("hp2ps output for " + name + " is not valid PostScript")
                     return False
             else:
                 return True # assume postscript is valid without ghostscript
         else:
-            print("hp2ps did not generate PostScript for " + actual_name)
+            print("hp2ps did not generate PostScript for " + name)
             return  False
     else:
-        print("hp2ps error when processing heap profile for " + actual_name)
+        print("hp2ps error when processing heap profile for " + name)
         return False
 
 async def check_prof_ok(name: TestName, way: WayName) -> bool:
@@ -2365,7 +2364,7 @@ async def check_prof_ok(name: TestName, way: WayName) -> bool:
     if not expected_prof_path.exists():
         return True
 
-    actual_prof_file = add_suffix(name + exe_extension(), 'prof')
+    actual_prof_file = add_suffix(name, 'prof')
     actual_prof_path = in_testdir(actual_prof_file)
 
     if not actual_prof_path.exists():



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2341d81ec72f5ae963072957911a67a739a83db9...259495ee3de352d259a07b577f3089b34ddf283f

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2341d81ec72f5ae963072957911a67a739a83db9...259495ee3de352d259a07b577f3089b34ddf283f
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240309/3b8e0dc4/attachment-0001.html>


More information about the ghc-commits mailing list