Merge branch 'ps/meson-contrib-bits'

Update meson-based build procedure to cover contrib/ and other
places as well.

* ps/meson-contrib-bits:
  ci: exercise credential helpers
  ci: fix propagating UTF-8 test locale in musl-based Meson job
  meson: wire up static analysis via Coccinelle
  meson: wire up git-contacts(1)
  meson: wire up credential helpers
  contrib/credential: fix compilation of "osxkeychain" helper
  contrib/credential: fix compiling "libsecret" helper
  contrib/credential: fix compilation of wincred helper with MSVC
  contrib/credential: fix "netrc" tests with out-of-tree builds
  GIT-BUILD-OPTIONS: propagate project's source directory
This commit is contained in:
Junio C Hamano
2025-03-03 08:53:02 -08:00
24 changed files with 229 additions and 27 deletions

View File

@ -1169,14 +1169,13 @@ string(REPLACE "@GIT_PERF_MAKE_COMMAND@" "" git_build_options "${git_build_optio
string(REPLACE "@GIT_PERF_MAKE_OPTS@" "" git_build_options "${git_build_options}")
string(REPLACE "@GIT_PERF_REPEAT_COUNT@" "" git_build_options "${git_build_options}")
string(REPLACE "@GIT_PERF_REPO@" "" git_build_options "${git_build_options}")
string(REPLACE "@GIT_SOURCE_DIR@" "${CMAKE_SOURCE_DIR}" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_CMP@" "" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_CMP_USE_COPIED_CONTEXT@" "" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_GITPERLLIB@" "'${CMAKE_BINARY_DIR}/perl/build/lib'" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_INDEX_VERSION@" "" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_MERGE_TOOLS_DIR@" "'${CMAKE_BINARY_DIR}/mergetools'" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_OPTS@" "" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_PERL_FATAL_WARNINGS@" "" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_POPATH@" "'${CMAKE_BINARY_DIR}/po'" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_TEMPLATE_DIR@" "'${CMAKE_BINARY_DIR}/templates/blt'" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_TEXTDOMAINDIR@" "'${CMAKE_BINARY_DIR}/po/build/locale'" git_build_options "${git_build_options}")
string(REPLACE "@GIT_TEST_UTF8_LOCALE@" "" git_build_options "${git_build_options}")

View File

@ -0,0 +1,89 @@
spatch = find_program('spatch', required: get_option('coccinelle'))
if not spatch.found()
subdir_done()
endif
third_party_sources = [
':!contrib',
':!compat/inet_ntop.c',
':!compat/inet_pton.c',
':!compat/nedmalloc',
':!compat/obstack.*',
':!compat/poll',
':!compat/regex',
':!sha1collisiondetection',
':!sha1dc',
':!t/unit-tests/clar',
':!t/unit-tests/clar',
':!t/t[0-9][0-9][0-9][0-9]*',
]
rules = [
'array.cocci',
'commit.cocci',
'config_fn_ctx.pending.cocci',
'equals-null.cocci',
'flex_alloc.cocci',
'free.cocci',
'git_config_number.cocci',
'hashmap.cocci',
'index-compatibility.cocci',
'object_id.cocci',
'preincr.cocci',
'qsort.cocci',
'refs.cocci',
'strbuf.cocci',
'swap.cocci',
'the_repository.cocci',
'xcalloc.cocci',
'xopen.cocci',
'xstrdup_or_null.cocci',
'xstrncmpz.cocci',
]
concatenated_rules = custom_target(
command: [
'cat', '@INPUT@',
],
input: rules,
output: 'rules.cocci',
capture: true,
)
sources = [ ]
foreach source : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.c', third_party_sources, check: true).stdout().split()
sources += source
endforeach
headers = [ ]
foreach header : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.h', third_party_sources, check: true).stdout().split()
headers += meson.project_source_root() / header
endforeach
patches = [ ]
foreach source : sources
patches += custom_target(
command: [
spatch,
'--all-includes',
'--sp-file', concatenated_rules,
'--patch', meson.project_source_root(),
'@INPUT@',
],
input: meson.project_source_root() / source,
output: source.underscorify() + '.patch',
capture: true,
depend_files: headers,
)
endforeach
concatenated_patch = custom_target(
command: [
'cat', '@INPUT@',
],
input: patches,
output: 'cocci.patch',
capture: true,
)
alias_target('coccicheck', concatenated_patch)

View File

@ -0,0 +1,55 @@
custom_target(
input: 'git-contacts',
output: 'git-contacts',
command: generate_perl_command,
depends: [git_version_file],
install: true,
install_dir: get_option('libexecdir') / 'git-core',
)
if get_option('docs').contains('man')
contacts_xml = custom_target(
command: asciidoc_common_options + [
'--backend=' + asciidoc_docbook,
'--doctype=manpage',
'--out-file=@OUTPUT@',
'@INPUT@',
],
depends: documentation_deps,
input: 'git-contacts.txt',
output: 'git-contacts.xml',
)
custom_target(
command: [
xmlto,
'-m', '@INPUT@',
'man',
contacts_xml,
'-o',
meson.current_build_dir(),
] + xmlto_extra,
input: [
'../../Documentation/manpage-normal.xsl',
],
output: 'git-contacts.1',
install: true,
install_dir: get_option('mandir') / 'man1',
)
endif
if get_option('docs').contains('html')
custom_target(
command: asciidoc_common_options + [
'--backend=' + asciidoc_html,
'--doctype=manpage',
'--out-file=@OUTPUT@',
'@INPUT@',
],
depends: documentation_deps,
input: 'git-contacts.txt',
output: 'git-contacts.html',
install: true,
install_dir: get_option('datadir') / 'doc/git-doc',
)
endif

View File

@ -59,10 +59,10 @@ static void credential_clear(struct credential *c);
/* ----------------- Secret Service functions ----------------- */
static const SecretSchema schema = {
"org.git.Password",
.name = "org.git.Password",
/* Ignore schema name during search for backwards compatibility */
SECRET_SCHEMA_DONT_MATCH_NAME,
{
.flags = SECRET_SCHEMA_DONT_MATCH_NAME,
.attributes = {
/*
* libsecret assumes attribute values are non-confidential and
* unchanging, so we can't include oauth_refresh_token or
@ -168,7 +168,7 @@ static int keyring_get(struct credential *c)
g_free(c->password);
c->password = g_strdup("");
}
for (int i = 1; i < g_strv_length(parts); i++) {
for (guint i = 1; i < g_strv_length(parts); i++) {
if (g_str_has_prefix(parts[i], "password_expiry_utc=")) {
g_free(c->password_expiry_utc);
c->password_expiry_utc = g_strdup(&parts[i][20]);
@ -424,7 +424,7 @@ int main(int argc, char *argv[])
struct credential_operation const *try_op = credential_helper_ops;
struct credential cred = CREDENTIAL_INIT;
if (!argv[1]) {
if (argc < 2 || !*argv[1]) {
usage(argv[0]);
exit(EXIT_FAILURE);
}

View File

@ -0,0 +1,9 @@
executable('git-credential-libsecret',
sources: 'git-credential-libsecret.c',
dependencies: [
dependency('glib-2.0'),
dependency('libsecret-1'),
],
install: true,
install_dir: get_option('libexecdir') / 'git-core',
)

View File

@ -0,0 +1,3 @@
foreach helper : get_option('credential_helpers')
subdir(helper)
endforeach

View File

@ -0,0 +1,20 @@
credential_netrc = custom_target(
input: 'git-credential-netrc.perl',
output: 'git-credential-netrc',
command: generate_perl_command,
depends: [git_version_file],
install: true,
install_dir: get_option('libexecdir') / 'git-core',
)
credential_netrc_testenv = test_environment
credential_netrc_testenv.set('CREDENTIAL_NETRC_PATH', credential_netrc.full_path())
test('t-git-credential-netrc',
shell,
args: [ meson.current_source_dir() / 't-git-credential-netrc.sh' ],
workdir: meson.current_source_dir(),
env: credential_netrc_testenv,
depends: test_dependencies + bin_wrappers + [credential_netrc],
timeout: 0,
)

View File

@ -15,7 +15,7 @@
export PERL5LIB="$GITPERLLIB"
test_expect_success 'git-credential-netrc' '
perl "$GIT_BUILD_DIR"/contrib/credential/netrc/test.pl
perl "$GIT_SOURCE_DIR"/contrib/credential/netrc/test.pl
'
test_done

View File

@ -15,10 +15,11 @@ BEGIN {
my @global_credential_args = @ARGV;
my $scriptDir = dirname rel2abs $0;
my ($netrc, $netrcGpg, $gcNetrc) = map { catfile $scriptDir, $_; }
my ($netrc, $netrcGpg) = map { catfile $scriptDir, $_; }
qw(test.netrc
test.netrc.gpg
git-credential-netrc);
test.netrc.gpg);
my $gcNetrc = $ENV{CREDENTIAL_NETRC_PATH} || catfile $scriptDir, qw(git-credential-netrc);
local $ENV{PATH} = join ':'
, $scriptDir
, $ENV{PATH}

View File

@ -422,7 +422,7 @@ int main(int argc, const char **argv)
const char *usage =
"usage: git credential-osxkeychain <get|store|erase>";
if (!argv[1])
if (argc < 2 || !*argv[1])
die("%s", usage);
if (open(argv[0], O_RDONLY | O_EXLOCK) == -1)

View File

@ -0,0 +1,9 @@
executable('git-credential-osxkeychain',
sources: 'git-credential-osxkeychain.c',
dependencies: [
dependency('CoreFoundation'),
dependency('Security'),
],
install: true,
install_dir: get_option('libexecdir') / 'git-core',
)

View File

@ -12,7 +12,9 @@
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#ifndef _MSC_VER
__attribute__((format (printf, 1, 2)))
#endif
static void die(const char *err, ...)
{
char msg[4096];

View File

@ -0,0 +1,5 @@
executable('git-credential-wincred',
sources: 'git-credential-wincred.c',
install: true,
install_dir: get_option('libexecdir') / 'git-core',
)

View File

@ -1,3 +1,6 @@
foreach feature : get_option('contrib')
subdir(feature)
endforeach
subdir('coccinelle')
subdir('credential')