Skip to content

Commit

Permalink
Fix problem parsing stuff like options: --compile-java-args='-target …
Browse files Browse the repository at this point in the history
…7 -source 7' in pants.rc files

Testing Done:
Ran new tests

Reviewed at https://rbcommons.com/s/twitter/r/1192/
  • Loading branch information
dturner-tw authored and ity committed Oct 22, 2014
1 parent 633bd56 commit 77ccbb6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/python/pants/base/rcfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from twitter.common.log import logger

from pants.base.config import Config
from pants.util.strutil import safe_shlex_split


log = logger(name='rcfile')
Expand Down Expand Up @@ -75,7 +76,7 @@ def apply_defaults(self, commands, args):
log.debug('using rcfiles: %s to modify args' % ','.join(read_from))

def get_rcopts(command, key):
return config.get(command, key).split() if config.has_option(command, key) else []
return safe_shlex_split(config.get(command, key)) if config.has_option(command, key) else []

commands = list(commands)
if self.process_default:
Expand Down
3 changes: 1 addition & 2 deletions src/python/pants/commands/goal_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ def setup_parser(self, parser, args):
if augmented_args != args:
# TODO(John Sirois): Cleanup this currently important mutation of the passed in args
# once the 2-layer of command -> goal is squashed into one.
del args[:]
args.extend(augmented_args)
args[:] = augmented_args
sys.stderr.write("(using pantsrc expansion: pants goal %s)\n" % ' '.join(augmented_args))

Goal.setup_parser(parser, args, self.goals)
Expand Down
10 changes: 10 additions & 0 deletions tests/python/pants_test/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ python_test_suite(
':hash_utils',
':payload',
':payload_field',
':rcfile',
':revision',
':run_info',
':source_root',
Expand Down Expand Up @@ -257,6 +258,15 @@ python_tests(
]
)

python_tests(
name = 'rcfile',
sources = ['test_rcfile.py'],
dependencies = [
'src/python/pants/base:rcfile',
'tests/python/pants_test:base_test',
]
)

python_tests(
name = 'revision',
sources = ['test_revision.py'],
Expand Down
29 changes: 29 additions & 0 deletions tests/python/pants_test/base/test_rcfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (nested_scopes, generators, division, absolute_import, with_statement,
print_function, unicode_literals)

from contextlib import contextmanager
from textwrap import dedent
import os
import unittest2 as unittest

from pants.base.rcfile import RcFile
from pants.util.contextutil import temporary_file


class ParseSpecTest(unittest.TestCase):
def test_parse_rcfile(self):
with temporary_file() as rc:
rc.write(dedent("""
[jvm]
options: --compile-java-args='-target 7 -source 7'
"""))
rc.close()
rcfile = RcFile([rc.name], default_prepend=False)
commands = ['jvm', 'fleem']
args = ['javac', 'Foo.java']
new_args = rcfile.apply_defaults(commands, args)
self.assertEquals(['javac', 'Foo.java', '--compile-java-args=-target 7 -source 7'], new_args)

0 comments on commit 77ccbb6

Please sign in to comment.