{"thread":{"id":"59638","subject":"[PATCH] Handle compiler versions containing a dash","startedAt":"2023-04-23T09:13:08Z","lastAt":"2023-04-26T00:49:37Z","messageCount":3,"participants":["Mike Hommey","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"475895","messageId":"20230423091249.2591136-1-mh@glandium.org","threadId":"59638","inReplyTo":null,"subject":"[PATCH] Handle compiler versions containing a dash","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2023-04-23T09:12:49Z","receivedAt":"2023-04-23T09:13:08Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"The version reported by e.g. x86_64-w64-mingw32-gcc on Debian bullseye\nlooks like:\n  gcc version 10-win32 20210110 (GCC)\n\nThis ends up with detect-compiler failing with:\n  ./detect-compiler: 30: test: Illegal number: 10-win32\n\nThis change removes the -win32 part by excluding the dash and everything\nthat follows from the version.\n---\n detect-compiler | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/detect-compiler b/detect-compiler\nindex 50087f5670..d961df5fb5 100755\n--- a/detect-compiler\n+++ b/detect-compiler\n@@ -17,7 +17,7 @@ get_family() {\n }\n \n get_version() {\n-\tget_version_line | sed 's/^.* version \\([0-9][^ ]*\\).*/\\1/'\n+\tget_version_line | sed 's/^.* version \\([0-9][^ -]*\\).*/\\1/'\n }\n \n print_flags() {\n-- \n2.40.0.1.gc689dad23e\n\n"},{"id":"475976","messageId":"xmqqo7nd9cy7.fsf@gitster.g","threadId":"59638","inReplyTo":"20230423091249.2591136-1-mh@glandium.org","subject":"Re: [PATCH] Handle compiler versions containing a dash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-04-24T21:40:00Z","receivedAt":"2023-04-24T21:40:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mike Hommey <mh@glandium.org> writes:\n\n> The version reported by e.g. x86_64-w64-mingw32-gcc on Debian bullseye\n> looks like:\n>   gcc version 10-win32 20210110 (GCC)\n>\n> This ends up with detect-compiler failing with:\n>   ./detect-compiler: 30: test: Illegal number: 10-win32\n>\n> This change removes the -win32 part by excluding the dash and everything\n> that follows from the version.\n\nThis may help the \"test \"$version\" -gt 0\" check and $((version - 1))\nto pass.  It is not quite clear if/why it gives sensible results,\nthough.\n\n> ---\n>  detect-compiler | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n\nMissing sign-off?\n\n> diff --git a/detect-compiler b/detect-compiler\n> index 50087f5670..d961df5fb5 100755\n> --- a/detect-compiler\n> +++ b/detect-compiler\n> @@ -17,7 +17,7 @@ get_family() {\n>  }\n>  \n>  get_version() {\n> -\tget_version_line | sed 's/^.* version \\([0-9][^ ]*\\).*/\\1/'\n> +\tget_version_line | sed 's/^.* version \\([0-9][^ -]*\\).*/\\1/'\n\nThe original is bad enough in that it says \"We take anything that\nbegins with a digit up to (but not including) the first SP, and then\nit assumes that it is getting an integer.  This one is not all that\nbetter in that it can still accept a garbage like \"version 01xx-foo\"\nand \"test \"$version\" -gt 0\" would fail the same way, no?\n\nIf we are sure that \"version N-win32\" is always equivalent to\n\"version N\" for the purpose of print_flags() helper function, it may\nbe more prudent to allow the known-good ones, with something like\n\n\t# A string that begins with a digit up to the next SP\n\tver=$(get_version_line | sed 's/^.* version \\([0-9][^ ]*\\).*/\\1/')\n\n\t# There are known -variant suffixes that do not affect the\n\t# meaning of the main version number.  Strip them.\n\tver=${ver%-win32}\n\tver=${ver%-win64}\n\t...\n\techo \"$ver\"\n\nwhile keeping the ones that are not \"known-to-be-good\" as-is.\n\nThat way, non-numeric numbers that we do not know about how to\ninterpret will continue to stop detect-compiler from giving a bogus\nanswer, which would be better than silently accepting anything with\ndash and treat as if the string after the number does not make any\ndifference.\n\nOne thing I am worried about is \"10-prerelease\" that is not quite\n\"10\" yet to be treated just like \"10\" and causing problems.\n\nThanks.\n\n\n"},{"id":"476081","messageId":"20230426004843.3391826-1-mh@glandium.org","threadId":"59638","inReplyTo":"xmqqo7nd9cy7.fsf@gitster.g","subject":"[PATCH] Handle some compiler versions containing a dash","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2023-04-26T00:48:43Z","receivedAt":"2023-04-26T00:49:37Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"The version reported by e.g. x86_64-w64-mingw32-gcc on Debian bullseye\nlooks like:\n  gcc version 10-win32 20210110 (GCC)\n\nThis ends up with detect-compiler failing with:\n  ./detect-compiler: 30: test: Illegal number: 10-win32\n\nThis change removes the two known suffixes known to exist in GCC versions\nin Debian: -win32 and -posix.\n\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n detect-compiler | 10 +++++++++-\n 1 file changed, 9 insertions(+), 1 deletion(-)\n\ndiff --git a/detect-compiler b/detect-compiler\nindex 50087f5670..a87650b71b 100755\n--- a/detect-compiler\n+++ b/detect-compiler\n@@ -17,7 +17,15 @@ get_family() {\n }\n \n get_version() {\n-\tget_version_line | sed 's/^.* version \\([0-9][^ ]*\\).*/\\1/'\n+\t# A string that begins with a digit up to the next SP\n+\tver=$(get_version_line | sed 's/^.* version \\([0-9][^ ]*\\).*/\\1/')\n+\n+\t# There are known -variant suffixes that do not affect the\n+\t# meaning of the main version number.  Strip them.\n+\tver=${ver%-win32}\n+\tver=${ver%-posix}\n+\n+\techo \"$ver\"\n }\n \n print_flags() {\n-- \n2.40.0.1.gc689dad23e\n\n"}]}