Skip to content

[build-script] Shell Module #14430

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

Closed
wants to merge 4 commits into from
Closed

Conversation

Rostepher
Copy link
Contributor

@Rostepher Rostepher commented Feb 6, 2018

Purpose

This PR introduces two new modules. First is the shell module which implements a CommandExecutor that wraps portions of the standard subprocess module in a context object that tracks common state and command history. The executor is extensible with a trivial action system that allows for users to add any callable to the queue of actions performed prior to executing a command. The intended use-case here is to have a centralized shell-object that is passed around through the program to build up a history and maintain state.

For example:

import os

from build_swift import shell

ENV = {
    'PATH': '/usr/bin',
}

sh = shell.CommandExecutor(env=ENV, stdout=open(os.devnull, 'w'))
sh.cp('/Applications/Xcode.app')
sh.mkdir('test')

sh.check_call(['./utils/build-script', '--reconfigure', '-t'])

sh.history()

It's possible to hook-in custom actions like so:

def callable(command):
    # Do something with the command
    log_command(command)

sh.add_action(callable)

Every action is performed before executing the command.

The second module is pretty small, wrapping the xcrun utility using the shell module. Both have testing, albeit not much in the way of xcrun.

This furthers the efforts for completing SR-237
rdar://25281853

@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher Rostepher requested a review from zisko February 6, 2018 04:42
@Rostepher Rostepher self-assigned this Feb 6, 2018
@Rostepher Rostepher requested a review from rintaro February 6, 2018 04:43
@rintaro
Copy link
Member

rintaro commented Feb 6, 2018

I think NullExecutor should override cd andpushd as well.
Consider:

sh.mkdir("foo")
with sh.pushd("foo"):
    # something
    pass

Since foo isn't created, it fails with OSError: [Errno 2] No such file or directory: 'foo'

@Rostepher
Copy link
Contributor Author

@rintaro I'll override cd and pushd in the NullExecutor.

@Rostepher
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 7, 2018

Build failed
Swift Test Linux Platform
Git Sha - ef793b4cf4ead4ede918ec4dd46cba4b91e32229

@swift-ci
Copy link
Contributor

swift-ci commented Feb 7, 2018

Build failed
Swift Test OS X Platform
Git Sha - ef793b4cf4ead4ede918ec4dd46cba4b91e32229

@Rostepher Rostepher requested a review from shahmishal February 7, 2018 23:01
@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher
Copy link
Contributor Author

@swift-ci please build toolchain

@swift-ci
Copy link
Contributor

swift-ci commented Feb 8, 2018

Build failed
Swift Test OS X Platform
Git Sha - 720788e28d7aadd742218e1ae8abcb4671b3671e

@swift-ci
Copy link
Contributor

swift-ci commented Feb 8, 2018

Build failed
Swift Test Linux Platform
Git Sha - 720788e28d7aadd742218e1ae8abcb4671b3671e

@Rostepher
Copy link
Contributor Author

@swift-ci please test Linux

Rostepher and others added 4 commits March 2, 2018 20:52
…ndard subprocess library. Also implemented a small wrapper module around Xcrun using the new shell module.
…e unexpected failures if they still perform work.
…dded missing **kwargs to the _fake_popen method on the CommandExecutor.
@Rostepher
Copy link
Contributor Author

I'm going to close this PR, it's no longer the direction I want to take this sort of module.

@Rostepher Rostepher closed this Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants