{"thread":{"id":"63133","subject":"[PATCH 03/12] meson.build: only set build variables for non-default values","startedAt":"2025-03-15T02:50:02Z","lastAt":"2025-03-20T09:26:10Z","messageCount":4,"participants":["Ramsay Jones","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":12},"messages":[{"id":"514346","messageId":"5d0112ae-98b5-46f2-91ad-35ed11358c3e@ramsayjones.plus.com","threadId":"63133","inReplyTo":null,"subject":"[PATCH 03/12] meson.build: only set build variables for non-default values","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2025-03-15T02:46:59Z","receivedAt":"2025-03-15T02:50:02Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nSome preprocessor -Defines have defaults sets in the source code when\nthey have not been provided to the C compiler. In this case, there is\nno need to pass them on the command-line, unless the build requires a\nnon-standard value.\n\nThe build variables for DEFAULT_EDITOR, DEFAULT_HELP_FORMAT along with\nDEFAULT_PAGER have appropriate defaults ('vi', 'man' and 'less') set in\nthe code. Add the preprocessor -Defines to the 'libgit_c_args' only if\nthe values set with the corresponding 'options' are different to these\nstandard values.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n---\n meson.build | 13 ++++++++++---\n 1 file changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/meson.build b/meson.build\nindex 88a29fd043..24a4c2e3c2 100644\n--- a/meson.build\n+++ b/meson.build\n@@ -693,10 +693,7 @@ endif\n # These variables are used for building libgit.a.\n libgit_c_args = [\n   '-DBINDIR=\"' + get_option('bindir') + '\"',\n-  '-DDEFAULT_EDITOR=\"' + get_option('default_editor') + '\"',\n   '-DDEFAULT_GIT_TEMPLATE_DIR=\"' + get_option('datadir') / 'git-core/templates' + '\"',\n-  '-DDEFAULT_HELP_FORMAT=\"' + get_option('default_help_format') + '\"',\n-  '-DDEFAULT_PAGER=\"' + get_option('default_pager') + '\"',\n   '-DETC_GITATTRIBUTES=\"' + get_option('gitattributes') + '\"',\n   '-DETC_GITCONFIG=\"' + get_option('gitconfig') + '\"',\n   '-DFALLBACK_RUNTIME_PREFIX=\"' + get_option('prefix') + '\"',\n@@ -708,6 +705,16 @@ libgit_c_args = [\n   '-DPAGER_ENV=\"' + get_option('pager_environment') + '\"',\n   '-DSHELL_PATH=\"' + fs.as_posix(shell.full_path()) + '\"',\n ]\n+if get_option('default_editor') != 'vi'\n+  libgit_c_args += '-DDEFAULT_EDITOR=\"' + get_option('default_editor') + '\"'\n+endif\n+if get_option('default_pager') != 'less'\n+  libgit_c_args += '-DDEFAULT_PAGER=\"' + get_option('default_pager') + '\"'\n+endif\n+if get_option('default_help_format') != 'man'\n+  libgit_c_args += '-DDEFAULT_HELP_FORMAT=\"' + get_option('default_help_format') + '\"'\n+endif\n+\n libgit_include_directories = [ '.' ]\n libgit_dependencies = [ ]\n \n-- \n2.49.0\n"},{"id":"514638","messageId":"Z9rIQlUtutWPiPgD@pks.im","threadId":"63133","inReplyTo":"5d0112ae-98b5-46f2-91ad-35ed11358c3e@ramsayjones.plus.com","subject":"Re: [PATCH 03/12] meson.build: only set build variables for non-default values","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-03-19T13:36:02Z","receivedAt":"2025-03-19T13:36:06Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sat, Mar 15, 2025 at 02:46:59AM +0000, Ramsay Jones wrote:\n> \n> Some preprocessor -Defines have defaults sets in the source code when\n> they have not been provided to the C compiler. In this case, there is\n> no need to pass them on the command-line, unless the build requires a\n> non-standard value.\n> \n> The build variables for DEFAULT_EDITOR, DEFAULT_HELP_FORMAT along with\n> DEFAULT_PAGER have appropriate defaults ('vi', 'man' and 'less') set in\n> the code. Add the preprocessor -Defines to the 'libgit_c_args' only if\n> the values set with the corresponding 'options' are different to these\n> standard values.\n\nHm. Does this really change anything though? The behaviour before and\nafter this patch are exactly the same as far as I understand, and by\nexplicitly handling the defaults we basically have to hard-code more\nassumptions. So in the current form I don't see that this patch adds\nmuch.\n\nWhat we _could_ be doing is to completely drop the default values in\n\"meson_options.txt\". In that case we could instead compare whether we\nsaw the empty string, which allows us to stop encoding the default vaule\nboth in \"meson_options.txt\" and in \"editor.c\".\n\nPatrick\n"},{"id":"514709","messageId":"77f8930d-dcfe-4612-b10d-1904e7530f38@ramsayjones.plus.com","threadId":"63133","inReplyTo":"Z9rIQlUtutWPiPgD@pks.im","subject":"Re: [PATCH 03/12] meson.build: only set build variables for non-default values","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2025-03-20T02:22:22Z","receivedAt":"2025-03-20T02:22:29Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 19/03/2025 13:36, Patrick Steinhardt wrote:\n> On Sat, Mar 15, 2025 at 02:46:59AM +0000, Ramsay Jones wrote:\n>>\n>> Some preprocessor -Defines have defaults sets in the source code when\n>> they have not been provided to the C compiler. In this case, there is\n>> no need to pass them on the command-line, unless the build requires a\n>> non-standard value.\n>>\n>> The build variables for DEFAULT_EDITOR, DEFAULT_HELP_FORMAT along with\n>> DEFAULT_PAGER have appropriate defaults ('vi', 'man' and 'less') set in\n>> the code. Add the preprocessor -Defines to the 'libgit_c_args' only if\n>> the values set with the corresponding 'options' are different to these\n>> standard values.\n> \n> Hm. Does this really change anything though? The behaviour before and\n> after this patch are exactly the same as far as I understand, and by\n> explicitly handling the defaults we basically have to hard-code more\n> assumptions. So in the current form I don't see that this patch adds\n> much.\n\nHmm, I suppose it kinda depends on how you view it! :)\n\nI have been looking at how the three build systems (well, mainly make\nand meson) differ in various ways, in order to try and determine if\nthere are any significant differences and (most important) bugs.\nReducing the differences allows me to more clearly identify the bugs. ;)\n\nIn this case, the original author(s) had clearly intended that the\ndefault values were included in the code, with the ability to override\nthe values from the command-line/environment only for 'non-standard' or\nplatform-specific uses. For example, on Windows and MINGW the\nDEFAULT_HELP_FORMAT is html, which is specified in the 'config.mak.uname'\nfile. (I don't see this override in the meson build).\n\nAlso, the documentation (see git-var.adoc) has a statement of the compiled\nin choice for the default pager and default editor, *only* if they are *not*\nthe standard values. I have a note, from several months ago, that says the\nmeson build does not pass the 'git-default-pager' and 'git-default-editor'\nattributes to asciidoc. The make build only sets those attributes if the\nDEFAULT_PAGER and DEFAULT_EDITOR variables are *defined* (and they should\n*not* be defined to the 'standard' values or the docs would not read well).\n(see git-var.adoc lines 49-51 and 67-69, Documentation/Makefile lines 239-242\nand 244-247).\n\nAlso, I believe (ie I need to check) that the make build relies on the main\nMakefile export-ing DEFAULT_EDITOR and DEFAULT_PAGER (see line #2923) to\nmake that work.\n\nI haven't looked into all of that yet (it's one of the part #2 un-written\npatches), and I don't yet know how those values get 'transmitted' to the\ndocs meson.build file.\n\nAlso, although I have found some meson documentation (https://mesonbuild.com/),\nI haven't had the time to actually study it, so I have just used search to\ntry and get some answers (it seems my search-fu leaves a lot to be desired).\nI was half expecting you to say something like 'hey, you don't do it like\nthat ... do this instead ...'. ;)\n\n[I tried searching for a option 'is_defined()' or 'is_default()' method or\nsimilar, but didn't find anything].\n\nSo, yes I think this patch has value. :)\n\nATB,\nRamsay Jones\n\n\n\n"},{"id":"514730","messageId":"Z9vfLjnfhqKBE9X4@pks.im","threadId":"63133","inReplyTo":"77f8930d-dcfe-4612-b10d-1904e7530f38@ramsayjones.plus.com","subject":"Re: [PATCH 03/12] meson.build: only set build variables for non-default values","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-03-20T09:26:06Z","receivedAt":"2025-03-20T09:26:10Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Mar 20, 2025 at 02:22:22AM +0000, Ramsay Jones wrote:\n> \n> \n> On 19/03/2025 13:36, Patrick Steinhardt wrote:\n> > On Sat, Mar 15, 2025 at 02:46:59AM +0000, Ramsay Jones wrote:\n> >>\n> >> Some preprocessor -Defines have defaults sets in the source code when\n> >> they have not been provided to the C compiler. In this case, there is\n> >> no need to pass them on the command-line, unless the build requires a\n> >> non-standard value.\n> >>\n> >> The build variables for DEFAULT_EDITOR, DEFAULT_HELP_FORMAT along with\n> >> DEFAULT_PAGER have appropriate defaults ('vi', 'man' and 'less') set in\n> >> the code. Add the preprocessor -Defines to the 'libgit_c_args' only if\n> >> the values set with the corresponding 'options' are different to these\n> >> standard values.\n> > \n> > Hm. Does this really change anything though? The behaviour before and\n> > after this patch are exactly the same as far as I understand, and by\n> > explicitly handling the defaults we basically have to hard-code more\n> > assumptions. So in the current form I don't see that this patch adds\n> > much.\n> \n> Hmm, I suppose it kinda depends on how you view it! :)\n> \n> I have been looking at how the three build systems (well, mainly make\n> and meson) differ in various ways, in order to try and determine if\n> there are any significant differences and (most important) bugs.\n> Reducing the differences allows me to more clearly identify the bugs. ;)\n\nFair.\n\n> In this case, the original author(s) had clearly intended that the\n> default values were included in the code, with the ability to override\n> the values from the command-line/environment only for 'non-standard' or\n> platform-specific uses. For example, on Windows and MINGW the\n> DEFAULT_HELP_FORMAT is html, which is specified in the 'config.mak.uname'\n> file. (I don't see this override in the meson build).\n> \n> Also, the documentation (see git-var.adoc) has a statement of the compiled\n> in choice for the default pager and default editor, *only* if they are *not*\n> the standard values. I have a note, from several months ago, that says the\n> meson build does not pass the 'git-default-pager' and 'git-default-editor'\n> attributes to asciidoc. The make build only sets those attributes if the\n> DEFAULT_PAGER and DEFAULT_EDITOR variables are *defined* (and they should\n> *not* be defined to the 'standard' values or the docs would not read well).\n> (see git-var.adoc lines 49-51 and 67-69, Documentation/Makefile lines 239-242\n> and 244-247).\n> \n> Also, I believe (ie I need to check) that the make build relies on the main\n> Makefile export-ing DEFAULT_EDITOR and DEFAULT_PAGER (see line #2923) to\n> make that work.\n> \n> I haven't looked into all of that yet (it's one of the part #2 un-written\n> patches), and I don't yet know how those values get 'transmitted' to the\n> docs meson.build file.\n\nOkay. I very much appreciate the work that you're investing into this\narea!\n\n> Also, although I have found some meson documentation (https://mesonbuild.com/),\n> I haven't had the time to actually study it, so I have just used search to\n> try and get some answers (it seems my search-fu leaves a lot to be desired).\n> I was half expecting you to say something like 'hey, you don't do it like\n> that ... do this instead ...'. ;)\n> \n> [I tried searching for a option 'is_defined()' or 'is_default()' method or\n> similar, but didn't find anything].\n\nNo, there isn't anything like that. What I'd do is to set the default\nvalues to the empty string, which makes it easy enough to see whether\nthe user has overridden the value to something sensible. And instead of\nhaving the default values defined in Meson, as well, we'd be able to use\nthe default as specified in code.\n\nFor the `default_help_format` variable it's a bit different as it's a\ncombo option. But what you can do is to e.g. add a third choice\n'platform' and make that the default value. We could then check for it\nand either set it to the empty string on non-Windows systems so that the\ndefault defined in our code gets used. And on Windows you'd override it\nto 'html'.\n\nAlternatively we could also refactor this option so that the default\nvalue gets defined entirely in code and then add an empty choice.\n\nPatrick\n"}]}