meson: modify gperf test to remove sh dependency

modifies the gperf test to instead rely on a file input
rather than piping in using sh, as sh is often not reliable
on Windows due to paths.

Also changes the if else ladder into a foreach loop.

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
This commit is contained in:
Christopher Degawa 2022-10-25 14:41:05 -05:00
parent c45e09df1e
commit a07e2f1e8a
No known key found for this signature in database
GPG Key ID: 40BDA1D2A156699E
2 changed files with 19 additions and 24 deletions

1
meson-cc-tests/gperf.txt Normal file
View File

@ -0,0 +1 @@
foo,bar

View File

@ -315,39 +315,33 @@ if fc_configdir.startswith(fc_baseconfigdir + '/')
fonts_conf.set('CONFIGDIR', fc_configdir.split(fc_baseconfigdir + '/')[1]) fonts_conf.set('CONFIGDIR', fc_configdir.split(fc_baseconfigdir + '/')[1])
endif endif
# It will automatically fallback to subproject if not found on system gperf = find_program('gperf', required: false)
gperf = find_program('gperf') gperf_len_type = ''
sh = find_program('sh', required : false) if gperf.found()
if not sh.found() # host_machine.system() == 'windows' or not sh.found()
# TODO: This is not always correct
if cc.get_id() == 'msvc'
gperf_len_type = 'size_t'
else
gperf_len_type = 'unsigned'
endif
else
gperf_test_format = ''' gperf_test_format = '''
#include <string.h> #include <string.h>
const char * in_word_set(const char *, @0@); const char * in_word_set(const char *, @0@);
@1@ @1@
''' '''
gperf_snippet_format = 'echo foo,bar | @0@ -L ANSI-C' gperf_snippet = run_command(gperf, '-L', 'ANSI-C', files('meson-cc-tests/gperf.txt'),
gperf_snippet = run_command(sh, '-c', gperf_snippet_format.format(gperf.full_path()), check: true).stdout()
check: true)
gperf_test = gperf_test_format.format('size_t', gperf_snippet.stdout())
if cc.compiles(gperf_test) foreach type : ['size_t', 'unsigned']
gperf_len_type = 'size_t' if cc.compiles(gperf_test_format.format(type, gperf_snippet))
else gperf_len_type = type
gperf_test = gperf_test_format.format('unsigned', gperf_snippet.stdout()) break
if cc.compiles(gperf_test)
gperf_len_type = 'unsigned'
else
error('unable to determine gperf len type')
endif endif
endforeach
if gperf_len_type == ''
error('unable to determine gperf len type')
endif endif
else
# Fallback to subproject
gperf = find_program('gperf')
# assume if we are compiling from the wrap, the size is just size_t
gperf_len_type = 'size_t'
endif endif
message('gperf len type is @0@'.format(gperf_len_type)) message('gperf len type is @0@'.format(gperf_len_type))