aboutsummaryrefslogtreecommitdiff
path: root/contrib/devtools/utils.py
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2021-01-21 13:52:40 -0500
committerfanquake <fanquake@gmail.com>2021-07-07 19:31:37 +0800
commit9fdc8afe117b7b1ea845f8acae9e831922b8f92b (patch)
treea8add8f24a05ac933e831d16e1b798259eabfd8f /contrib/devtools/utils.py
parentbda62eab38c5dd74e222eddedbca19ace9df6daa (diff)
downloadbitcoin-9fdc8afe117b7b1ea845f8acae9e831922b8f92b.tar.xz
devtools: Improve *-check.py tool detection
This is important to make sure that we're not testing tools different from the one we're building with. Introduce determine_wellknown_cmd, which encapsulates how we should handle well-known tools specification (IFS splitting, env override, etc.).
Diffstat (limited to 'contrib/devtools/utils.py')
-rwxr-xr-xcontrib/devtools/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/contrib/devtools/utils.py b/contrib/devtools/utils.py
new file mode 100755
index 0000000000..68ad1c3aba
--- /dev/null
+++ b/contrib/devtools/utils.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+# Copyright (c) 2021 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+Common utility functions
+'''
+import shutil
+import sys
+import os
+from typing import List
+
+
+def determine_wellknown_cmd(envvar, progname) -> List[str]:
+ maybe_env = os.getenv(envvar)
+ maybe_which = shutil.which(progname)
+ if maybe_env:
+ return maybe_env.split(' ') # Well-known vars are often meant to be word-split
+ elif maybe_which:
+ return [ maybe_which ]
+ else:
+ sys.exit(f"{progname} not found")