Skip to content

Commit

Permalink
use workunit output for cpp command running
Browse files Browse the repository at this point in the history
While working on moving reporting to a separate thread, I found that the cpp plugin wasn't using workunit output files, so it's output wasn't being managed by the run_tracker.

This changes the cpp run_command to use a workunit for the stdout / stderr files, and also adds the RUN label to the cpp run task.

Testing Done:
Ran contrib tests after changes, ci baking in PR.

Bugs closed: 1549

Reviewed at https://rbcommons.com/s/twitter/r/2223/
  • Loading branch information
baroquebobcat committed May 14, 2015
1 parent 9bd9f7f commit 5f74e66
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def add_library(tgt):
if self.get_options().ld_options != None:
cmd.extend(('-Wl,{0}'.format(o) for o in self.get_options().ld_options.split(' ')))

with self.context.new_workunit(name='cpp-link', labels=[WorkUnit.COMPILER]):
self.run_command(cmd)
with self.context.new_workunit(name='cpp-link', labels=[WorkUnit.COMPILER]) as workunit:
self.run_command(cmd, workunit)

return output
4 changes: 2 additions & 2 deletions contrib/cpp/src/python/pants/contrib/cpp/tasks/cpp_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _compile(self, target, source):
cmd.extend([self.get_options().cc_options])

# TODO: submit_async_work with self.run_command, [(cmd)] as a Work object.
with self.context.new_workunit(name='cpp-compile', labels=[WorkUnit.COMPILER]):
self.run_command(cmd)
with self.context.new_workunit(name='cpp-compile', labels=[WorkUnit.COMPILER]) as workunit:
self.run_command(cmd, workunit)

self.context.log.info('Built c++ object: {0}'.format(obj))
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _link_library(self, target, objects):
cmd.extend([output])
cmd.extend(objects)

with self.context.new_workunit(name='cpp-link', labels=[WorkUnit.COMPILER]):
self.run_command(cmd)
with self.context.new_workunit(name='cpp-link', labels=[WorkUnit.COMPILER]) as workunit:
self.run_command(cmd, workunit)

return output
4 changes: 2 additions & 2 deletions contrib/cpp/src/python/pants/contrib/cpp/tasks/cpp_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def prepare(cls, options, round_manager):
def execute(self):
binary = self.require_single_root_target()
if isinstance(binary, CppBinary):
with self.context.new_workunit(name='cpp-run', labels=[WorkUnit.TASK]):
with self.context.new_workunit(name='cpp-run', labels=[WorkUnit.RUN]) as workunit:
cmd = [os.path.join(binary.workdir, binary.id, binary.name)]
args = self.get_options().args + self.get_passthru_args()
if args != None:
cmd.extend(args)

self.run_command(cmd)
self.run_command(cmd, workunit)
4 changes: 2 additions & 2 deletions contrib/cpp/src/python/pants/contrib/cpp/tasks/cpp_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def register_options(cls, register):
def execute(self):
raise NotImplementedError('execute must be implemented by subclasses of CppTask')

def run_command(self, cmd):
def run_command(self, cmd, workunit):
try:
self.context.log.debug('Executing: {0}'.format(cmd))
# TODO: capture stdout/stderr and redirect to log
subprocess.check_call(cmd)
subprocess.check_call(cmd, stdout=workunit.output('stdout'), stderr=workunit.output('stderr'))
except subprocess.CalledProcessError as e:
raise TaskError('Execution failed: {0}'.format(e))
except:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_cpp_binary_with_library_compile(self):
def test_cpp_run(self):
pants_run = self.run_pants(['run', self.TEST_RUN_TARGET])
self.assert_success(pants_run)
self.assertIn('[cpp-run]Hello, pants!\nGoodbye, pants!\n',
self.assertIn('[cpp-run]\nHello, pants!\nGoodbye, pants!\n',
pants_run.stdout_data)

def _binary_test(self, target):
Expand Down

0 comments on commit 5f74e66

Please sign in to comment.