mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-26 08:01:14 +02:00
dev-build/meson-format-array: Sync with Gentoo
It's from Gentoo commit d5e08b1999d751bcb76f4989cfb5eb8f8124a4ea.
This commit is contained in:
parent
896454de68
commit
b1d83707bd
@ -6,10 +6,22 @@ import itertools
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
|
||||
def quote(s):
|
||||
""" Surround a value with quotes, escape embedded quotes.
|
||||
>>> quote("foo'bar")
|
||||
"'foo\\\\'bar'"
|
||||
"""
|
||||
|
||||
return "'" + s.replace("\\", "\\\\").replace("'", "\\'") + "'"
|
||||
|
||||
def main(args):
|
||||
|
||||
def format_array(args):
|
||||
""" Format shell-compatible expressions as a meson array.
|
||||
>>> format_array(['-O2 -pipe -DFOO="bar baz"'])
|
||||
"['-O2', '-pipe', '-DFOO=bar baz']"
|
||||
"""
|
||||
|
||||
# Split each argument according to shell rules
|
||||
args = (shlex.split(x) for x in args)
|
||||
|
||||
@ -20,7 +32,12 @@ def main(args):
|
||||
args = (quote(x) for x in args)
|
||||
|
||||
# Format the result
|
||||
print("[" + ", ".join(args) + "]")
|
||||
return "[" + ", ".join(args) + "]"
|
||||
|
||||
|
||||
def main(args):
|
||||
print(format_array(args))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
@ -4,10 +4,11 @@
|
||||
EAPI=8
|
||||
PYTHON_COMPAT=( python3_{10..13} )
|
||||
|
||||
inherit python-r1
|
||||
inherit edo python-r1
|
||||
|
||||
DESCRIPTION="Format shell expressions into a meson array"
|
||||
HOMEPAGE="https://wiki.gentoo.org/wiki/No_homepage"
|
||||
S="${WORKDIR}"
|
||||
|
||||
LICENSE="GPL-2"
|
||||
SLOT="0"
|
||||
@ -15,8 +16,14 @@ KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~loong ~m68k ~mips ppc ppc64 ~riscv
|
||||
|
||||
REQUIRED_USE="${PYTHON_REQUIRED_USE}"
|
||||
RDEPEND="${PYTHON_DEPS}"
|
||||
S="${WORKDIR}"
|
||||
|
||||
src_test() {
|
||||
run_doctest() {
|
||||
edo ${EPYTHON} -B -m doctest "${FILESDIR}/meson-format-array.py"
|
||||
}
|
||||
python_foreach_impl run_doctest
|
||||
}
|
||||
|
||||
src_install() {
|
||||
python_foreach_impl python_doscript "${FILESDIR}"/meson-format-array
|
||||
python_foreach_impl python_newscript "${FILESDIR}"/meson-format-array.py meson-format-array
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user