public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsayjones•plus.com>
To: GIT Mailing-list <git@vger•kernel.org>
Cc: "Ramsay Jones" <ramsay@ramsayjones•plus.com>,
	"Junio C Hamano" <gitster@pobox•com>,
	"Patrick Steinhardt" <ps@pks•im>,
	"Eli Schwartz" <eschwartz@gentoo•org>,
	"Đoàn Trần Công Danh" <congdanhqx@gmail•com>
Subject: [PATCH v3 3/5] meson: correct path to system config/attribute files
Date: Fri, 16 May 2025 19:48:41 +0100	[thread overview]
Message-ID: <20250516184843.1524925-4-ramsay@ramsayjones.plus.com> (raw)
In-Reply-To: <20250516184843.1524925-1-ramsay@ramsayjones.plus.com>

The path to the system-wide config and attributes files are not being
set correctly in the meson build. Unless explicitly overridden on the
command line during setup, the 'gitconfig' and 'gitattributes' options
are defaulting to absolute paths in the '/etc' system directory. This
is only appropriate if the <prefix> is set specifically to '/usr'.

The directory in which these files are placed is generally referred to
as the 'system configuration directory' or 'sysconfdir' for short. When
the prefix is '/usr' then the sysconfdir is usually set to '/etc', but
any other value for prefix results in the relative directory value 'etc'
instead. (eg if prefix is '/usr/local', then the 'etc' relative value
results in a system configuration directory of '/usr/local/etc'). When
setting the 'sysconfdir' builtin option value, the meson system uses
exactly this algorithm, so we can use get_option('sysconfdir') directly
when setting the (non-overridden) build variables.

In order to allow for overriding from the command line, remove the
default values specified for the 'gitconfig' and 'gitattributes' options
in the 'meson_options.txt' file. This allows the user to specify any
pathname for those options, while being able to test for the unset
(empty) value. An absolute pathname will be used unchanged and a relative
pathname will be appended to '<prefix>/'. These values are then used to
set the 'ETC_GITCONFIG' and 'ETC_GITATTRIBUTES' build variables which are,
in turn, passed to the compiler as '-D' arguments.

When the 'gitconfig' or 'gitattributes' options are not used, then use
the built-in 'sysconfdir' and set the ETC_GITCONFIG build variable to
the string "<sysconfdir>/gitconfig". Similarly, set ETC_ATTRIBUTES to
"<sysconfdir>/gitattributes".

Signed-off-by: Ramsay Jones <ramsay@ramsayjones•plus.com>
---
 meson.build       | 16 ++++++++++++++--
 meson_options.txt |  8 ++++----
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/meson.build b/meson.build
index 48f31157a0..8e8f228a37 100644
--- a/meson.build
+++ b/meson.build
@@ -757,8 +757,6 @@ endif
 libgit_c_args = [
   '-DBINDIR="' + get_option('bindir') + '"',
   '-DDEFAULT_GIT_TEMPLATE_DIR="' + get_option('datadir') / 'git-core/templates' + '"',
-  '-DETC_GITATTRIBUTES="' + get_option('gitattributes') + '"',
-  '-DETC_GITCONFIG="' + get_option('gitconfig') + '"',
   '-DFALLBACK_RUNTIME_PREFIX="' + get_option('prefix') + '"',
   '-DGIT_HOST_CPU="' + host_machine.cpu_family() + '"',
   '-DGIT_HTML_PATH="' + get_option('datadir') / 'doc/git-doc"',
@@ -769,6 +767,20 @@ libgit_c_args = [
   '-DSHELL_PATH="' + fs.as_posix(target_shell.full_path()) + '"',
 ]
 
+system_attributes = get_option('gitattributes')
+if system_attributes != ''
+  libgit_c_args += '-DETC_GITATTRIBUTES="' + system_attributes + '"'
+else
+  libgit_c_args += '-DETC_GITATTRIBUTES="' + get_option('sysconfdir') / 'gitattributes"'
+endif
+
+system_config = get_option('gitconfig')
+if system_config != ''
+  libgit_c_args += '-DETC_GITCONFIG="' + system_config + '"'
+else
+  libgit_c_args += '-DETC_GITCONFIG="' + get_option('sysconfdir') / 'gitconfig"'
+endif
+
 editor_opt = get_option('default_editor')
 if editor_opt != '' and editor_opt != 'vi'
   libgit_c_args += '-DDEFAULT_EDITOR="' + editor_opt + '"'
diff --git a/meson_options.txt b/meson_options.txt
index 8547c0eb47..7a4b896f7e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -3,10 +3,10 @@ option('default_pager', type: 'string', value: 'less',
   description: 'Fall-back pager.')
 option('default_editor', type: 'string', value: 'vi',
   description: 'Fall-back editor.')
-option('gitconfig', type: 'string', value: '/etc/gitconfig',
-  description: 'Path to the global git configuration file.')
-option('gitattributes', type: 'string', value: '/etc/gitattributes',
-  description: 'Path to the global git attributes file.')
+option('gitconfig', type: 'string', # default 'etc/gitconfig'
+  description: 'Path to the global git configuration file. (default: etc/gitconfig)')
+option('gitattributes', type: 'string', # default 'etc/gitattributes'
+  description: 'Path to the global git attributes file. (default: etc/gitattributes)')
 option('pager_environment', type: 'string', value: 'LESS=FRX LV=-c',
   description: 'Environment used when spawning the pager')
 option('perl_cpan_fallback', type: 'boolean', value: true,
-- 
2.49.0


  parent reply	other threads:[~2025-05-16 18:49 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-08 16:44 [PATCH 0/5] miscellaneous build mods (part 2) Ramsay Jones
2025-05-08 16:44 ` [PATCH 1/5] meson.build: quote the GITWEBDIR build configuration Ramsay Jones
2025-05-08 16:44   ` [PATCH 2/5] meson: correct install location of YAML.pm Ramsay Jones
2025-05-08 16:44     ` [PATCH 3/5] meson: correct path to system config/attribute files Ramsay Jones
2025-05-08 16:44       ` [PATCH 4/5] meson.build: correct setting of GIT_EXEC_PATH Ramsay Jones
2025-05-08 16:44         ` [PATCH 5/5] configure.ac: upgrade to a compilation check for sysinfo Ramsay Jones
2025-05-08 21:07           ` Eli Schwartz
2025-05-08 23:01             ` Ramsay Jones
2025-05-15 20:17               ` Eli Schwartz
2025-05-08 21:55         ` [PATCH 4/5] meson.build: correct setting of GIT_EXEC_PATH Junio C Hamano
2025-05-08 21:48       ` [PATCH 3/5] meson: correct path to system config/attribute files Junio C Hamano
2025-05-08 22:50         ` Eli Schwartz
2025-05-09  1:03           ` Junio C Hamano
2025-05-08 23:16         ` Ramsay Jones
2025-05-09  8:51       ` Patrick Steinhardt
2025-05-09 15:23         ` Ramsay Jones
2025-05-08 17:36 ` [PATCH 0/5] miscellaneous build mods (part 2) Ramsay Jones
2025-05-13 19:17 ` [PATCH v2 " Ramsay Jones
2025-05-13 19:17   ` [PATCH v2 1/5] meson.build: quote the GITWEBDIR build configuration Ramsay Jones
2025-05-13 19:17   ` [PATCH v2 2/5] meson: correct install location of YAML.pm Ramsay Jones
2025-05-13 19:17   ` [PATCH v2 3/5] meson: correct path to system config/attribute files Ramsay Jones
2025-05-14  4:36     ` Patrick Steinhardt
2025-05-15 16:42       ` Ramsay Jones
2025-05-15 17:51         ` Eli Schwartz
2025-05-15 19:53           ` Ramsay Jones
2025-05-16  5:45         ` Patrick Steinhardt
2025-05-13 19:17   ` [PATCH v2 4/5] meson.build: correct setting of GIT_EXEC_PATH Ramsay Jones
2025-06-16 22:08     ` irecca.kun
2025-05-13 19:17   ` [PATCH v2 5/5] configure.ac: upgrade to a compilation check for sysinfo Ramsay Jones
2025-05-13 20:13   ` [PATCH v2 0/5] miscellaneous build mods (part 2) Junio C Hamano
2025-05-13 20:55     ` Ramsay Jones
2025-05-16 18:48   ` [PATCH v3 " Ramsay Jones
2025-05-16 18:48     ` [PATCH v3 1/5] meson.build: quote the GITWEBDIR build configuration Ramsay Jones
2025-05-16 18:48     ` [PATCH v3 2/5] meson: correct install location of YAML.pm Ramsay Jones
2025-05-16 18:48     ` Ramsay Jones [this message]
2025-05-19  7:32       ` [PATCH v3 3/5] meson: correct path to system config/attribute files Patrick Steinhardt
2025-05-16 18:48     ` [PATCH v3 4/5] meson.build: correct setting of GIT_EXEC_PATH Ramsay Jones
2025-05-16 18:48     ` [PATCH v3 5/5] configure.ac: upgrade to a compilation check for sysinfo Ramsay Jones
2025-05-19 16:25     ` [PATCH v4 0/5] miscellaneous build mods (part 2) Ramsay Jones
2025-05-19 16:25       ` [PATCH v4 1/5] meson.build: quote the GITWEBDIR build configuration Ramsay Jones
2025-05-19 16:25       ` [PATCH v4 2/5] meson: correct install location of YAML.pm Ramsay Jones
2025-05-19 16:25       ` [PATCH v4 3/5] meson: correct path to system config/attribute files Ramsay Jones
2025-05-19 16:25       ` [PATCH v4 4/5] meson.build: correct setting of GIT_EXEC_PATH Ramsay Jones
2025-05-19 16:25       ` [PATCH v4 5/5] configure.ac: upgrade to a compilation check for sysinfo Ramsay Jones
2025-05-19 18:48       ` [PATCH v4 0/5] miscellaneous build mods (part 2) Junio C Hamano
2025-05-19 19:08         ` Patrick Steinhardt
2025-05-19 22:42           ` Ramsay Jones
2025-05-19 23:01             ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250516184843.1524925-4-ramsay@ramsayjones.plus.com \
    --to=ramsay@ramsayjones$(echo .)plus.com \
    --cc=congdanhqx@gmail$(echo .)com \
    --cc=eschwartz@gentoo$(echo .)org \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    --cc=ps@pks$(echo .)im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox