Skip to content

Commit

Permalink
[types] core/process.py passes.
Browse files Browse the repository at this point in the history
Added a virtual JobWait() function.
  • Loading branch information
Andy Chu committed Feb 4, 2020
1 parent 1bfe1cc commit 8377616
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
22 changes: 14 additions & 8 deletions core/process.py
Expand Up @@ -18,6 +18,7 @@
from _devbuild.gen.id_kind_asdl import Id
from _devbuild.gen.runtime_asdl import (
job_state_e, job_state_t,
job_status, job_status_t,
redirect_e, redirect_t,
redirect__Path, redirect__FileDesc, redirect__HereDoc,
)
Expand Down Expand Up @@ -731,14 +732,9 @@ def Send_SIGCONT(self, waiter):
"""
pass

def Wait(self, waiter):
# type: (Waiter) -> None
"""Wait for this process/pipeline to be stopped or finished.
Returns:
An int for a process
A list of ints for a pipeline
"""
def JobWait(self, waiter):
# type: (Waiter) -> job_status_t
"""Wait for this process/pipeline to be stopped or finished."""
raise NotImplementedError()


Expand Down Expand Up @@ -842,6 +838,11 @@ def Wait(self, waiter):
break
return self.status

def JobWait(self, waiter):
# type: (Waiter) -> job_status_t
exit_code = self.Wait(waiter)
return job_status.Proc(exit_code)

def WhenStopped(self):
# type: () -> None
self.state = job_state_e.Stopped
Expand Down Expand Up @@ -981,6 +982,11 @@ def Wait(self, waiter):

return self.pipe_status

def JobWait(self, waiter):
# type: (Waiter) -> job_status_t
pipe_status = self.Wait(waiter)
return job_status.Pipeline(pipe_status)

def Run(self, waiter, fd_state):
# type: (Waiter, FdState) -> List[int]
"""Run this pipeline synchronously (foreground pipeline).
Expand Down
25 changes: 21 additions & 4 deletions osh/builtin_process.py
Expand Up @@ -8,16 +8,20 @@

import signal # for calculating numbers

from _devbuild.gen.runtime_asdl import cmd_value__Argv
from _devbuild.gen.runtime_asdl import (
cmd_value__Argv,
job_status_e, job_status__Proc, job_status__Pipeline,
)
from core import ui
from core.builtin_def import _Register
from core.util import log
from frontend import args
from osh.builtin import _Builtin
from mycpp.mylib import tagswitch

import posix_ as posix

from typing import List, Dict, Any, TYPE_CHECKING
from typing import List, Dict, Any, cast, TYPE_CHECKING
if TYPE_CHECKING:
from _devbuild.gen.syntax_asdl import command_t
from core.ui import ErrorFormatter
Expand Down Expand Up @@ -130,8 +134,21 @@ def Run(self, cmd_val):
span_id=span_id)
return 127

# TODO: Wait for pipelines, and handle PIPESTATUS from Pipeline.Wait().
status = job.Wait(self.waiter)
# TODO: Does this wait for pipelines?
job_status = job.JobWait(self.waiter)

UP_job_status = job_status
with tagswitch(job_status) as case:
if case(job_status_e.Proc):
job_status = cast(job_status__Proc, UP_job_status)
status = job_status.code
elif case(job_status_e.Pipeline):
# TODO: handle PIPESTATUS?
job_status = cast(job_status__Pipeline, UP_job_status)
# Is this right?
status = job_status.codes[-1]
else:
raise AssertionError

return status

Expand Down
2 changes: 1 addition & 1 deletion types/oil-slice.sh
Expand Up @@ -83,7 +83,7 @@ typecheck-all() {
# _devbuild/cpython-full on Travis to crawl dependencies.
travis-setup() {
# TODO: add stat.py back. Why does it cause errors?
local exclude='vendor|__future__|mylib.py|/stat.py|/process.py'
local exclude='vendor|__future__|mylib.py|/stat.py'

osh-parse-deps
egrep -v "$exclude" $OSH_PARSE_DEPS | tee $OSH_PARSE_MANIFEST
Expand Down
1 change: 1 addition & 0 deletions types/osh-eval-manifest.txt
Expand Up @@ -7,6 +7,7 @@
./core/builtin_def.py
./core/error.py
./core/meta.py
./core/process.py
./core/pyutil.py
./core/ui.py
./core/util.py
Expand Down

0 comments on commit 8377616

Please sign in to comment.