blob: e810cca254924f3694669fdca2d5225b0394aaf8 [file] [log] [blame]
# -*- coding: utf-8 -*-
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Common functions used from multiple files.
"""
from __future__ import print_function
import subprocess
def parse_shell_args(s):
"""Parses the string representing shell arguments (e.g. C++ flags) as a list.
For example, '''-DFOO=a -DBAR='"b c"' -DBAZ="d e f"''' becomes
['-DFOO=a', '-DBAR="b c"', '-DBAZ=d e f'].
For GN, strings to be passed to the shell must have been parsed, as otherwise
they are escaped by GN on emitting ninja files.
"""
# The dummy variable prevents the first value in s from interpreted as a flag
# for echo. IFS is set to separate $* with newlines.
output = subprocess.check_output(
['eval "set -- dummy $0"; IFS=$\'\\n\'; echo -n "$*"', s], shell=True)
return output.splitlines()[1:]