{"thread":{"id":"65262","subject":"[PATCH] clar: update to fix compilation on platforms without PATH_MAX","startedAt":"2026-03-16T07:50:55Z","lastAt":"2026-03-16T07:50:55Z","messageCount":1,"participants":["Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"539075","messageId":"20260316-b4-pks-clar-without-path-max-v1-1-40b4bc91fdc0@pks.im","threadId":"65262","inReplyTo":null,"subject":"[PATCH] clar: update to fix compilation on platforms without PATH_MAX","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-03-16T07:50:43Z","receivedAt":"2026-03-16T07:50:55Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Update clar to e4172e3 (Merge pull request #134 from\nclar-test/ethomson/const, 2026-01-10). Besides some changes to\n\"generate.py\" which don't have any impact on us, this commit also fixes\ncompilation on platforms that don't have PATH_MAX, like for example\nGNU/Hurd.\n\nReported-by: Samuel Thibault <samuel.thibault@ens-lyon.org>\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\nHi,\n\nas discussed in the thread at [1]. Thanks!\n\nPatrick\n\n[1]: <20260312191901.174808-1-samuel.thibault@ens-lyon.org>\n---\n t/unit-tests/clar/clar.h      |  4 ++-\n t/unit-tests/clar/generate.py | 79 +++++++++++++++++++++++++++++++++++--------\n 2 files changed, 68 insertions(+), 15 deletions(-)\n\ndiff --git a/t/unit-tests/clar/clar.h b/t/unit-tests/clar/clar.h\nindex f7e4363022..9ea91d3d0e 100644\n--- a/t/unit-tests/clar/clar.h\n+++ b/t/unit-tests/clar/clar.h\n@@ -15,8 +15,10 @@\n # define CLAR_MAX_PATH 4096\n #elif defined(_WIN32)\n # define CLAR_MAX_PATH MAX_PATH\n-#else\n+#elif defined(PATH_MAX)\n # define CLAR_MAX_PATH PATH_MAX\n+#else\n+# define CLAR_MAX_PATH 4096\n #endif\n \n #ifndef CLAR_SELFTEST\ndiff --git a/t/unit-tests/clar/generate.py b/t/unit-tests/clar/generate.py\nindex fd2f0ee83b..2357b2d6d2 100755\n--- a/t/unit-tests/clar/generate.py\n+++ b/t/unit-tests/clar/generate.py\n@@ -8,7 +8,7 @@\n \n from __future__ import with_statement\n from string import Template\n-import re, fnmatch, os, sys, codecs, pickle\n+import re, fnmatch, os, sys, codecs, pickle, io\n \n class Module(object):\n     class Template(object):\n@@ -147,7 +147,7 @@ def __init__(self, path, output):\n         self.path = path\n         self.output = output\n \n-    def should_generate(self, path):\n+    def maybe_generate(self, path):\n         if not os.path.isfile(path):\n             return True\n \n@@ -223,34 +223,85 @@ def callback_count(self):\n         return sum(len(module.callbacks) for module in self.modules.values())\n \n     def write(self):\n-        output = os.path.join(self.output, 'clar.suite')\n-        os.makedirs(self.output, exist_ok=True)\n+        if not os.path.exists(self.output):\n+            os.makedirs(self.output)\n \n-        if not self.should_generate(output):\n+        wrote_suite = self.write_suite()\n+        wrote_header = self.write_header()\n+\n+        if wrote_suite or wrote_header:\n+            self.save_cache()\n+            return True\n+\n+        return False\n+\n+    def write_output(self, fn, data):\n+        if not self.maybe_generate(fn):\n+            return False\n+\n+        current = None\n+\n+        try:\n+            with open(fn, 'r') as input:\n+                current = input.read()\n+        except OSError:\n+            pass\n+        except IOError:\n+            pass\n+\n+        if current == data:\n             return False\n \n-        with open(output, 'w') as data:\n+        with open(fn, 'w') as output:\n+            output.write(data)\n+\n+        return True\n+\n+    def write_suite(self):\n+        suite_fn = os.path.join(self.output, 'clar.suite')\n+\n+        with io.StringIO() as suite_file:\n             modules = sorted(self.modules.values(), key=lambda module: module.name)\n \n             for module in modules:\n                 t = Module.DeclarationTemplate(module)\n-                data.write(t.render())\n+                suite_file.write(t.render())\n \n             for module in modules:\n                 t = Module.CallbacksTemplate(module)\n-                data.write(t.render())\n+                suite_file.write(t.render())\n \n             suites = \"static struct clar_suite _clar_suites[] = {\" + ','.join(\n                 Module.InfoTemplate(module).render() for module in modules\n             ) + \"\\n};\\n\"\n \n-            data.write(suites)\n+            suite_file.write(suites)\n \n-            data.write(\"static const size_t _clar_suite_count = %d;\\n\" % self.suite_count())\n-            data.write(\"static const size_t _clar_callback_count = %d;\\n\" % self.callback_count())\n+            suite_file.write(u\"static const size_t _clar_suite_count = %d;\\n\" % self.suite_count())\n+            suite_file.write(u\"static const size_t _clar_callback_count = %d;\\n\" % self.callback_count())\n \n-        self.save_cache()\n-        return True\n+            return self.write_output(suite_fn, suite_file.getvalue())\n+\n+        return False\n+\n+    def write_header(self):\n+        header_fn = os.path.join(self.output, 'clar_suite.h')\n+\n+        with io.StringIO() as header_file:\n+            header_file.write(u\"#ifndef _____clar_suite_h_____\\n\")\n+            header_file.write(u\"#define _____clar_suite_h_____\\n\")\n+\n+            modules = sorted(self.modules.values(), key=lambda module: module.name)\n+\n+            for module in modules:\n+                t = Module.DeclarationTemplate(module)\n+                header_file.write(t.render())\n+\n+            header_file.write(u\"#endif\\n\")\n+\n+            return self.write_output(header_fn, header_file.getvalue())\n+\n+        return False\n \n if __name__ == '__main__':\n     from optparse import OptionParser\n@@ -275,4 +326,4 @@ def write(self):\n     suite.load(options.force)\n     suite.disable(options.excluded)\n     if suite.write():\n-        print(\"Written `clar.suite` (%d tests in %d suites)\" % (suite.callback_count(), suite.suite_count()))\n+        print(\"Written `clar.suite`, `clar_suite.h` (%d tests in %d suites)\" % (suite.callback_count(), suite.suite_count()))\n\n---\nbase-commit: 67006b9db8b772423ad0706029286096307d2567\nchange-id: 20260316-b4-pks-clar-without-path-max-a2068515d9e2\n\n"}]}