mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
--print-cmd-oneline
This commit is contained in:
@@ -573,6 +573,14 @@ when building examples that rely on it or running tests for those examples.
|
|||||||
Indicate that all packages used by our userland/ examples with --package
|
Indicate that all packages used by our userland/ examples with --package
|
||||||
are available.
|
are available.
|
||||||
''',
|
''',
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
'--print-cmd-oneline',
|
||||||
|
action='store_true',
|
||||||
|
help='''\
|
||||||
|
Print generated commands in a single line:
|
||||||
|
https://cirosantilli.com/linux-kernel-module-cheat#dry-run
|
||||||
|
'''
|
||||||
)
|
)
|
||||||
self.add_argument(
|
self.add_argument(
|
||||||
'--static',
|
'--static',
|
||||||
@@ -1482,6 +1490,7 @@ lunch aosp_{}-eng
|
|||||||
self.env = env.copy()
|
self.env = env.copy()
|
||||||
self.sh = shell_helpers.ShellHelpers(
|
self.sh = shell_helpers.ShellHelpers(
|
||||||
dry_run=self.env['dry_run'],
|
dry_run=self.env['dry_run'],
|
||||||
|
force_oneline=self.env['print_cmd_oneline'],
|
||||||
quiet=(not show_cmds),
|
quiet=(not show_cmds),
|
||||||
)
|
)
|
||||||
self._init_env(self.env)
|
self._init_env(self.env)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class ShellHelpers:
|
|||||||
|
|
||||||
_print_lock = threading.Lock()
|
_print_lock = threading.Lock()
|
||||||
|
|
||||||
def __init__(self, dry_run=False, quiet=False):
|
def __init__(self, dry_run=False, quiet=False, force_oneline=False):
|
||||||
'''
|
'''
|
||||||
:param dry_run: don't run the commands, just potentially print them. Debug aid.
|
:param dry_run: don't run the commands, just potentially print them. Debug aid.
|
||||||
:type dry_run: Bool
|
:type dry_run: Bool
|
||||||
@@ -44,6 +44,7 @@ class ShellHelpers:
|
|||||||
:type dry_run: Bool
|
:type dry_run: Bool
|
||||||
'''
|
'''
|
||||||
self.dry_run = dry_run
|
self.dry_run = dry_run
|
||||||
|
self.force_oneline_default = force_oneline
|
||||||
self.quiet = quiet
|
self.quiet = quiet
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -108,13 +109,19 @@ class ShellHelpers:
|
|||||||
new_mode = old_mode & ~mode_delta
|
new_mode = old_mode & ~mode_delta
|
||||||
os.chmod(path, new_mode)
|
os.chmod(path, new_mode)
|
||||||
|
|
||||||
@staticmethod
|
def force_oneline(self, force_oneline):
|
||||||
|
if force_oneline is not None:
|
||||||
|
return force_oneline
|
||||||
|
else:
|
||||||
|
return self.force_oneline_default
|
||||||
|
|
||||||
def cmd_to_string(
|
def cmd_to_string(
|
||||||
|
self,
|
||||||
cmd: List[Union[str, LF]],
|
cmd: List[Union[str, LF]],
|
||||||
cwd=None,
|
cwd=None,
|
||||||
extra_env=None,
|
extra_env=None,
|
||||||
extra_paths=None,
|
extra_paths=None,
|
||||||
force_oneline: bool =False,
|
force_oneline: Union[bool,None] =None,
|
||||||
*,
|
*,
|
||||||
stdin_path: Union[str,None] =None
|
stdin_path: Union[str,None] =None
|
||||||
):
|
):
|
||||||
@@ -143,12 +150,12 @@ class ShellHelpers:
|
|||||||
newline_count = 0
|
newline_count = 0
|
||||||
for arg in cmd:
|
for arg in cmd:
|
||||||
if arg == LF:
|
if arg == LF:
|
||||||
if not force_oneline:
|
if not self.force_oneline(force_oneline):
|
||||||
cmd_quote.append(arg)
|
cmd_quote.append(arg)
|
||||||
newline_count += 1
|
newline_count += 1
|
||||||
else:
|
else:
|
||||||
cmd_quote.append(shlex.quote(arg))
|
cmd_quote.append(shlex.quote(arg))
|
||||||
if force_oneline or newline_count > 0:
|
if self.force_oneline(force_oneline) or newline_count > 0:
|
||||||
cmd_quote = [
|
cmd_quote = [
|
||||||
' '.join(list(y))
|
' '.join(list(y))
|
||||||
for x, y in itertools.groupby(
|
for x, y in itertools.groupby(
|
||||||
@@ -160,7 +167,7 @@ class ShellHelpers:
|
|||||||
out.extend(cmd_quote)
|
out.extend(cmd_quote)
|
||||||
if stdin_path is not None:
|
if stdin_path is not None:
|
||||||
out.append('< {}'.format(shlex.quote(stdin_path)))
|
out.append('< {}'.format(shlex.quote(stdin_path)))
|
||||||
if force_oneline or newline_count == 1 and cmd[-1] == LF:
|
if self.force_oneline(force_oneline) or newline_count == 1 and cmd[-1] == LF:
|
||||||
ending = ''
|
ending = ''
|
||||||
else:
|
else:
|
||||||
ending = last_newline + ';'
|
ending = last_newline + ';'
|
||||||
@@ -246,7 +253,7 @@ class ShellHelpers:
|
|||||||
cmd_files=None,
|
cmd_files=None,
|
||||||
extra_env=None,
|
extra_env=None,
|
||||||
extra_paths=None,
|
extra_paths=None,
|
||||||
force_oneline=False,
|
force_oneline: Union[bool,None] =None,
|
||||||
*,
|
*,
|
||||||
stdin_path: Union[str,None] =None
|
stdin_path: Union[str,None] =None
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user