Skip to content

Commit 46a626c

Browse files
ramsay-jonesgitster
authored andcommitted
meson: correct path to system config/attribute files
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bdb3843 commit 46a626c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

meson.build

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,6 @@ endif
757757
libgit_c_args = [
758758
'-DBINDIR="' + get_option('bindir') + '"',
759759
'-DDEFAULT_GIT_TEMPLATE_DIR="' + get_option('datadir') / 'git-core/templates' + '"',
760-
'-DETC_GITATTRIBUTES="' + get_option('gitattributes') + '"',
761-
'-DETC_GITCONFIG="' + get_option('gitconfig') + '"',
762760
'-DFALLBACK_RUNTIME_PREFIX="' + get_option('prefix') + '"',
763761
'-DGIT_HOST_CPU="' + host_machine.cpu_family() + '"',
764762
'-DGIT_HTML_PATH="' + get_option('datadir') / 'doc/git-doc"',
@@ -769,6 +767,20 @@ libgit_c_args = [
769767
'-DSHELL_PATH="' + fs.as_posix(target_shell.full_path()) + '"',
770768
]
771769

770+
system_attributes = get_option('gitattributes')
771+
if system_attributes != ''
772+
libgit_c_args += '-DETC_GITATTRIBUTES="' + system_attributes + '"'
773+
else
774+
libgit_c_args += '-DETC_GITATTRIBUTES="' + get_option('sysconfdir') / 'gitattributes"'
775+
endif
776+
777+
system_config = get_option('gitconfig')
778+
if system_config != ''
779+
libgit_c_args += '-DETC_GITCONFIG="' + system_config + '"'
780+
else
781+
libgit_c_args += '-DETC_GITCONFIG="' + get_option('sysconfdir') / 'gitconfig"'
782+
endif
783+
772784
editor_opt = get_option('default_editor')
773785
if editor_opt != '' and editor_opt != 'vi'
774786
libgit_c_args += '-DDEFAULT_EDITOR="' + editor_opt + '"'

meson_options.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ option('default_pager', type: 'string', value: 'less',
33
description: 'Fall-back pager.')
44
option('default_editor', type: 'string', value: 'vi',
55
description: 'Fall-back editor.')
6-
option('gitconfig', type: 'string', value: '/etc/gitconfig',
7-
description: 'Path to the global git configuration file.')
8-
option('gitattributes', type: 'string', value: '/etc/gitattributes',
9-
description: 'Path to the global git attributes file.')
6+
option('gitconfig', type: 'string',
7+
description: 'Path to the global git configuration file. (default: etc/gitconfig)')
8+
option('gitattributes', type: 'string',
9+
description: 'Path to the global git attributes file. (default: etc/gitattributes)')
1010
option('pager_environment', type: 'string', value: 'LESS=FRX LV=-c',
1111
description: 'Environment used when spawning the pager')
1212
option('perl_cpan_fallback', type: 'boolean', value: true,

0 commit comments

Comments
 (0)