Skip to content

[build-script] Move call_without_sleeping into the shell module #23803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions utils/build-parser-lib
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ from swift_build_support.swift_build_support.toolchain import host_toolchain

isMac = platform.system() == 'Darwin'

def call_without_sleeping(command, env=None, dry_run=False, echo=False):
"""
Execute a command during which system sleep is disabled.

By default, this ignores the state of the `shell.dry_run` flag.
"""

# Disable system sleep, if possible.
if platform.system() == 'Darwin':
# Don't mutate the caller's copy of the arguments.
command = ["caffeinate"] + list(command)

shell.call(command, env=env, dry_run=dry_run, echo=echo)

class Builder(object):
def __init__(self, toolchain, args):
self.toolchain = toolchain
Expand All @@ -76,7 +62,7 @@ class Builder(object):

def call(self, command, env=None, without_sleeping=False):
if without_sleeping:
call_without_sleeping(command, env=env, dry_run=self.dry_run, echo=self.verbose)
shell.call_without_sleeping(command, env=env, dry_run=self.dry_run, echo=self.verbose)
else:
shell.call(command, env=env, dry_run=self.dry_run, echo=self.verbose)

Expand Down
23 changes: 4 additions & 19 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ def exit_rejecting_arguments(message, parser=None):
sys.exit(2) # 2 is the same as `argparse` error exit code.


def call_without_sleeping(command, env=None, dry_run=False, echo=False):
"""
Execute a command during which system sleep is disabled.

By default, this ignores the state of the `shell.dry_run` flag.
"""

# Disable system sleep, if possible.
if platform.system() == 'Darwin':
# Don't mutate the caller's copy of the arguments.
command = ["caffeinate"] + list(command)

shell.call(command, env=env, dry_run=dry_run, echo=echo)


class HostSpecificConfiguration(object):

"""Configuration information for an individual host."""
Expand Down Expand Up @@ -906,8 +891,8 @@ class BuildScriptInvocation(object):
# `build-script-impl`.
if self.args.legacy_impl:
# Execute the underlying build script implementation.
call_without_sleeping([build_script_impl] + impl_args,
env=impl_env, echo=True)
shell.call_without_sleeping([build_script_impl] + impl_args,
env=impl_env, echo=True)
return

# Otherwise, we compute and execute the individual actions ourselves.
Expand All @@ -924,7 +909,7 @@ class BuildScriptInvocation(object):
assert name is not None, "invalid action"
action_name = "{}-{}-{}".format(
host.name, product_class.product_name(), name)
call_without_sleeping(
shell.call_without_sleeping(
[build_script_impl] + impl_args + [
"--only-execute", action_name],
env=impl_env, echo=self.args.verbose_build)
Expand Down Expand Up @@ -1143,7 +1128,7 @@ def main_preset():
if args.expand_build_script_invocation:
return 0

call_without_sleeping(build_script_args)
shell.call_without_sleeping(build_script_args)
return 0


Expand Down
16 changes: 16 additions & 0 deletions utils/swift_build_support/swift_build_support/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import os
import pipes
import platform
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -93,6 +94,21 @@ def call(command, stderr=None, env=None, dry_run=None, echo=True):
"': " + e.strerror)


def call_without_sleeping(command, env=None, dry_run=False, echo=False):
"""
Execute a command during which system sleep is disabled.

By default, this ignores the state of the `shell.dry_run` flag.
"""

# Disable system sleep, if possible.
if platform.system() == 'Darwin':
# Don't mutate the caller's copy of the arguments.
command = ["caffeinate"] + list(command)

call(command, env=env, dry_run=dry_run, echo=echo)


def capture(command, stderr=None, env=None, dry_run=None, echo=True,
optional=False, allow_non_zero_exit=False):
"""
Expand Down