Skip to content

Commit dc86515

Browse files
committed
make: Adding clang's -Wfortify-source warning
Adding Clang's -Wfortify-source to get more diagnostics when it can detect other issues in our source code through this warning. Signed-off-by: Tyler Erickson <tyler.erickson@seagate.com>
1 parent a64568e commit dc86515

5 files changed

Lines changed: 35 additions & 8 deletions

File tree

meson.build

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ if c.get_id().contains('gcc') or c.get_id().contains('clang')
104104
'-Wcalloc-transposed-args',
105105
'-Werror=alloca', # Do not allow use of the alloca function
106106
'-Wstring-compare', # Helps detect when strcmp is used when the programmer likely meant to use strncmp
107+
'-Wfortify-source' # needed for diagnose_as_builtin attributes to work.
107108
]
108109

109110
if get_option('cc-suggest-attribute')
@@ -270,12 +271,38 @@ endif
270271

271272
source_epoch = ''
272273

274+
posixshell = find_program('sh', required: false)
275+
bashshell = find_program('bash', required: false)
273276
# 1. Check for SOURCE_DATE_EPOCH environment variable using shell
274-
env_cmd = run_command('sh', '-c', 'echo $SOURCE_DATE_EPOCH', check: false)
275-
if env_cmd.returncode() == 0 and env_cmd.stdout().strip() != ''
276-
source_epoch = env_cmd.stdout().strip()
277+
if posixshell.found()
278+
env_cmd = run_command(posixshell, '-c', 'echo $SOURCE_DATE_EPOCH', check: false)
279+
if env_cmd.returncode() == 0 and env_cmd.stdout().strip() != ''
280+
source_epoch = env_cmd.stdout().strip()
281+
endif
282+
elif bashshell.found()
283+
env_cmd = run_command(bashshell, '-c', 'echo $SOURCE_DATE_EPOCH', check: false)
284+
if env_cmd.returncode() == 0 and env_cmd.stdout().strip() != ''
285+
source_epoch = env_cmd.stdout().strip()
286+
endif
287+
else
288+
# Probably in Windows, so check for powershell and try to get the environment variable from there
289+
powershell = find_program('pwsh', 'powershell', required: false)
290+
if powershell.found()
291+
env_cmd = run_command(powershell, '-NoProfile', '-NonInteractive', '-Command', '[Environment]::GetEnvironmentVariable("SOURCE_DATE_EPOCH")', check: false)
292+
if env_cmd.returncode() == 0 and env_cmd.stdout().strip() != ''
293+
source_epoch = env_cmd.stdout().strip()
294+
endif
295+
else
296+
cmdexe = find_program('cmd.exe', required: false)
297+
if cmdexe.found()
298+
# cmd.exe is the last resort
299+
env_cmd = run_command(cmdexe, '/c', 'echo %SOURCE_DATE_EPOCH%', check: false)
300+
if env_cmd.returncode() == 0 and env_cmd.stdout().strip() != '' and env_cmd.stdout().strip() != '%SOURCE_DATE_EPOCH%'
301+
source_epoch = env_cmd.stdout().strip()
302+
endif
303+
endif
304+
endif
277305
endif
278-
279306
# 2. If Env Var is empty, try to fetch from Git
280307
if source_epoch == ''
281308
git = find_program('git', required: false)

0 commit comments

Comments
 (0)