def get_bootstrap_options(self):
    """Returns an Options instance that only knows about the bootstrap options."""
    if not self._bootstrap_options:
      flags = set()
      def capture_the_flags(*args, **kwargs):
        flags.update(args)
      register_bootstrap_options(capture_the_flags, buildroot=self._buildroot)
      # Take just the bootstrap args, so we don't choke on other global-scope args on the cmd line.
      bargs = filter(lambda x: x.partition('=')[0] in flags, self._args or [])

      self._bootstrap_options = Options(env=self._env, config=self._pre_bootstrap_config,
                                        known_scopes=[GLOBAL_SCOPE], args=bargs)
      register_bootstrap_options(self._bootstrap_options.register_global, buildroot=self._buildroot)
      bootstrap_option_values = self._bootstrap_options.for_global_scope()
      Config.reset_default_bootstrap_option_values(values=bootstrap_option_values)

      # Now re-read the config, post-bootstrapping. Note the order: First whatever we bootstrapped
      # from (typically pants.ini), then config override, then rcfiles.
      configpaths = list(self._pre_bootstrap_config.sources())
      if bootstrap_option_values.config_override:
        configpaths.append(bootstrap_option_values.config_override)
      if bootstrap_option_values.pantsrc:
        rcfiles = [os.path.expanduser(rcfile) for rcfile in bootstrap_option_values.pantsrc_files]
        existing_rcfiles = filter(os.path.exists, rcfiles)
        configpaths.extend(existing_rcfiles)

      self._post_bootstrap_config = Config.load(configpaths)
      Config.cache(self._post_bootstrap_config)

    return self._bootstrap_options
Example #2
0
    def setUp(self):
        super(ScalaLibraryTest, self).setUp()

        self.create_file(
            'pants.ini',
            dedent('''
        [compile.scala]
        runtime-deps: []
        '''))

        # TODO: Required because target code has no direct config reference. Remove after fixing that.
        Config.cache(Config.load())

        self.add_to_build_file(
            '3rdparty',
            dedent('''
        jar_library(
          name='hub-and-spoke',
          jars=[
            jar('org.jalopy', 'hub-and-spoke', '0.0.1')
          ]
        )
        '''))

        self.add_to_build_file(
            'scala',
            dedent('''
        scala_library(
          name='lib',
          sources=[],
          java_sources=[
            'java:explicit_scala_dep',
            'java:no_scala_dep',
          ]
        )
        '''))

        self.add_to_build_file(
            'java',
            dedent('''
        java_library(
          name='explicit_scala_dep',
          sources=[],
          dependencies=[
            'scala:lib',
            '3rdparty:hub-and-spoke',
          ]
        )

        java_library(
          name='no_scala_dep',
          sources=[],
          dependencies=[]
        )
        '''))

        self.lib_hub_and_spoke = self.target('3rdparty:hub-and-spoke')
        self.scala_library = self.target('scala:lib')
        self.java_library_explicit_dep = self.target('java:explicit_scala_dep')
        self.java_library_no_dep = self.target('java:no_scala_dep')
  def get_bootstrap_options(self):
    """Returns an Options instance that only knows about the bootstrap options."""
    if not self._bootstrap_options:
      flags = set()

      def capture_the_flags(*args, **kwargs):
        for flag in Parser.expand_flags(*args, **kwargs):
          flags.add(flag.name)
          if flag.inverse_name:
            flags.add(flag.inverse_name)

      register_bootstrap_options(capture_the_flags, buildroot=self._buildroot)
      # Take just the bootstrap args, so we don't choke on other global-scope args on the cmd line.
      bargs = filter(lambda x: x.partition('=')[0] in flags, self._args or [])

      self._bootstrap_options = Options(env=self._env, config=self._pre_bootstrap_config,
                                        known_scopes=[GLOBAL_SCOPE], args=bargs)
      register_bootstrap_options(self._bootstrap_options.register_global, buildroot=self._buildroot)
      bootstrap_option_values = self._bootstrap_options.for_global_scope()
      Config.reset_default_bootstrap_option_values(values=bootstrap_option_values)

      # Now re-read the config, post-bootstrapping. Note the order: First whatever we bootstrapped
      # from (typically pants.ini), then config override, then rcfiles.
      configpaths = list(self._pre_bootstrap_config.sources())
      if bootstrap_option_values.config_override:
        configpaths.append(bootstrap_option_values.config_override)
      if bootstrap_option_values.pantsrc:
        rcfiles = [os.path.expanduser(rcfile) for rcfile in bootstrap_option_values.pantsrc_files]
        existing_rcfiles = filter(os.path.exists, rcfiles)
        configpaths.extend(existing_rcfiles)

      self._post_bootstrap_config = Config.load(configpaths)
      Config.cache(self._post_bootstrap_config)

    return self._bootstrap_options
Example #4
0
    def setUpClass(cls):
        """Ensure that all code has a config to read from the cache.

    TODO: Yuck. Get rid of this after plumbing options through in the right places.
    """
        super(BaseTest, cls).setUpClass()
        Config.cache(Config.load())
Example #5
0
  def setUpClass(cls):
    """Ensure that all code has a config to read from the cache.

    TODO: Yuck. Get rid of this after plumbing options through in the right places.
    """
    super(BaseTest, cls).setUpClass()
    Config.cache(Config.load())
 def test_depmap_jar_path(self):
   with temporary_dir(root_dir=self.workdir_root()) as workdir:
     test_target = 'examples/tests/java/com/pants/examples/usethrift:usethrift'
     json_data = self.run_depmap_project_info(test_target, workdir)
     # Hack because Bootstrapper.instance() reads config from cache. Will go away after we plumb
     # options into IvyUtil properly.
     Config.cache(Config.load())
     ivy_cache_dir = Bootstrapper.instance().ivy_cache_dir
     self.assertEquals(json_data.get('libraries').get('commons-lang:commons-lang:2.5'),
                     [os.path.join(ivy_cache_dir,
                                   'commons-lang/commons-lang/jars/commons-lang-2.5.jar')])
 def __init__(self, env=None, configpath=None, args=None, buildroot=None):
   self._buildroot = buildroot or get_buildroot()
   self._env = env or os.environ.copy()
   Config.reset_default_bootstrap_option_values(buildroot=self._buildroot)
   self._pre_bootstrap_config = Config.load([configpath] if configpath else None)
   self._post_bootstrap_config = None  # Will be set later.
   self._args = args or sys.argv
   self._bootstrap_options = None  # We memoize the bootstrap options here.
   self._full_options = None  # We memoize the full options here.
   # So other startup code has config to work with. This will go away once we replace direct
   # config accesses with options, and plumb those through everywhere that needs them.
   Config.cache(self._pre_bootstrap_config)
 def __init__(self, env=None, configpath=None, args=None, buildroot=None):
   self._buildroot = buildroot or get_buildroot()
   self._env = env or os.environ.copy()
   Config.reset_default_bootstrap_option_values(buildroot=self._buildroot)
   self._pre_bootstrap_config = Config.load([configpath] if configpath else None)
   self._post_bootstrap_config = None  # Will be set later.
   self._args = args or sys.argv
   self._bootstrap_options = None  # We memoize the bootstrap options here.
   self._full_options = None  # We memoize the full options here.
   # So other startup code has config to work with. This will go away once we replace direct
   # config accesses with options, and plumb those through everywhere that needs them.
   Config.cache(self._pre_bootstrap_config)
  def get_bootstrap_options(self):
    """:returns: an Options instance that only knows about the bootstrap options.
    :rtype: Options
    """
    if not self._bootstrap_options:
      flags = set()
      short_flags = set()

      def capture_the_flags(*args, **kwargs):
        for flag in Parser.expand_flags(*args, **kwargs):
          flags.add(flag.name)
          if len(flag.name) == 2:
            short_flags.add(flag.name)
          if flag.inverse_name:
            flags.add(flag.inverse_name)

      register_bootstrap_options(capture_the_flags, buildroot=self._buildroot)

      def is_bootstrap_option(arg):
        components = arg.split('=', 1)
        if components[0] in flags:
          return True
        for flag in short_flags:
          if arg.startswith(flag):
            return True
        return False

      # Take just the bootstrap args, so we don't choke on other global-scope args on the cmd line.
      # Stop before '--' since args after that are pass-through and may have duplicate names to our
      # bootstrap options.
      bargs = filter(is_bootstrap_option, itertools.takewhile(lambda arg: arg != '--', self._args))

      self._bootstrap_options = Options(env=self._env, config=self._pre_bootstrap_config,
                                        known_scopes=[GLOBAL_SCOPE], args=bargs)
      register_bootstrap_options(self._bootstrap_options.register_global, buildroot=self._buildroot)
      bootstrap_option_values = self._bootstrap_options.for_global_scope()
      Config.reset_default_bootstrap_option_values(values=bootstrap_option_values)

      # Now re-read the config, post-bootstrapping. Note the order: First whatever we bootstrapped
      # from (typically pants.ini), then config override, then rcfiles.
      configpaths = list(self._pre_bootstrap_config.sources())
      if bootstrap_option_values.config_override:
        configpaths.append(bootstrap_option_values.config_override)
      if bootstrap_option_values.pantsrc:
        rcfiles = [os.path.expanduser(rcfile) for rcfile in bootstrap_option_values.pantsrc_files]
        existing_rcfiles = filter(os.path.exists, rcfiles)
        configpaths.extend(existing_rcfiles)

      self._post_bootstrap_config = Config.load(configpaths)
      Config.cache(self._post_bootstrap_config)

    return self._bootstrap_options
Example #10
0
  def setUp(self):
    super(ScalaLibraryTest, self).setUp()

    self.create_file('pants.ini', dedent('''
        [compile.scala]
        runtime-deps: []
        '''))

    # TODO: Required because target code has no direct config reference. Remove after fixing that.
    Config.cache(Config.load())

    self.add_to_build_file('3rdparty', dedent('''
        jar_library(
          name='hub-and-spoke',
          jars=[
            jar('org.jalopy', 'hub-and-spoke', '0.0.1')
          ]
        )
        '''))

    self.add_to_build_file('scala', dedent('''
        scala_library(
          name='lib',
          sources=[],
          java_sources=[
            'java:explicit_scala_dep',
            'java:no_scala_dep',
          ]
        )
        '''))

    self.add_to_build_file('java', dedent('''
        java_library(
          name='explicit_scala_dep',
          sources=[],
          dependencies=[
            'scala:lib',
            '3rdparty:hub-and-spoke',
          ]
        )

        java_library(
          name='no_scala_dep',
          sources=[],
          dependencies=[]
        )
        '''))

    self.lib_hub_and_spoke = self.target('3rdparty:hub-and-spoke')
    self.scala_library = self.target('scala:lib')
    self.java_library_explicit_dep = self.target('java:explicit_scala_dep')
    self.java_library_no_dep = self.target('java:no_scala_dep')
  def get_bootstrap_options(self):
    """Returns an Options instance that only knows about the bootstrap options."""
    if not self._bootstrap_options:
      flags = set()
      short_flags = set()

      def capture_the_flags(*args, **kwargs):
        for flag in Parser.expand_flags(*args, **kwargs):
          flags.add(flag.name)
          if len(flag.name) == 2:
            short_flags.add(flag.name)
          if flag.inverse_name:
            flags.add(flag.inverse_name)

      register_bootstrap_options(capture_the_flags, buildroot=self._buildroot)

      def is_bootstrap_option(arg):
        components = arg.split('=', 1)
        if components[0] in flags:
          return True
        for flag in short_flags:
          if arg.startswith(flag):
            return True
        return False

      # Take just the bootstrap args, so we don't choke on other global-scope args on the cmd line.
      # Stop before '--' since args after that are pass-through and may have duplicate names to our
      # bootstrap options.
      bargs = filter(is_bootstrap_option, itertools.takewhile(lambda arg: arg != '--', self._args))

      self._bootstrap_options = Options(env=self._env, config=self._pre_bootstrap_config,
                                        known_scopes=[GLOBAL_SCOPE], args=bargs)
      register_bootstrap_options(self._bootstrap_options.register_global, buildroot=self._buildroot)
      bootstrap_option_values = self._bootstrap_options.for_global_scope()
      Config.reset_default_bootstrap_option_values(values=bootstrap_option_values)

      # Now re-read the config, post-bootstrapping. Note the order: First whatever we bootstrapped
      # from (typically pants.ini), then config override, then rcfiles.
      configpaths = list(self._pre_bootstrap_config.sources())
      if bootstrap_option_values.config_override:
        configpaths.append(bootstrap_option_values.config_override)
      if bootstrap_option_values.pantsrc:
        rcfiles = [os.path.expanduser(rcfile) for rcfile in bootstrap_option_values.pantsrc_files]
        existing_rcfiles = filter(os.path.exists, rcfiles)
        configpaths.extend(existing_rcfiles)

      self._post_bootstrap_config = Config.load(configpaths)
      Config.cache(self._post_bootstrap_config)

    return self._bootstrap_options
Example #12
0
 def test_depmap_jar_path(self):
     with temporary_dir(root_dir=self.workdir_root()) as workdir:
         test_target = 'examples/tests/java/com/pants/examples/usethrift:usethrift'
         json_data = self.run_depmap_project_info(test_target, workdir)
         # Hack because Bootstrapper.instance() reads config from cache. Will go away after we plumb
         # options into IvyUtil properly.
         Config.cache(Config.load())
         ivy_cache_dir = Bootstrapper.instance().ivy_cache_dir
         self.assertEquals(
             json_data.get('libraries').get(
                 'commons-lang:commons-lang:2.5'),
             [
                 os.path.join(
                     ivy_cache_dir,
                     'commons-lang/commons-lang/jars/commons-lang-2.5.jar')
             ])
Example #13
0
def create_context(config='', options=None, target_roots=None, **kwargs):
    """Creates a ``Context`` with no config values, options, or targets by default.

  :param config: Either a ``Context`` object or else a string representing the contents of the
    pants.ini to parse the config from.
  :param options: An optional dict of scope -> (dict of name -> new-style option values).
  :param target_roots: An optional list of target roots to seed the context target graph from.
  :param ``**kwargs``: Any additional keyword arguments to pass through to the Context constructor.
  """
    config = config if isinstance(config, Config) else create_config(config)
    # TODO: Get rid of this temporary hack after we plumb options through everywhere and can get
    # rid of the config cache.
    Config.cache(config)

    run_tracker = create_run_tracker()
    target_roots = maybe_list(target_roots, Target) if target_roots else []
    return Context(config, create_options(options or {}), run_tracker,
                   target_roots, **kwargs)
Example #14
0
def create_context(config='', options=None, target_roots=None, **kwargs):
  """Creates a ``Context`` with no config values, options, or targets by default.

  :param config: Either a ``Context`` object or else a string representing the contents of the
    pants.ini to parse the config from.
  :param options: An optional dict of scope -> (dict of name -> new-style option values).
  :param target_roots: An optional list of target roots to seed the context target graph from.
  :param ``**kwargs``: Any additional keyword arguments to pass through to the Context constructor.
  """
  config = config if isinstance(config, Config) else create_config(config)
  # TODO: Get rid of this temporary hack after we plumb options through everywhere and can get
  # rid of the config cache.
  Config.cache(config)

  run_tracker = create_run_tracker()
  target_roots = maybe_list(target_roots, Target) if target_roots else []
  return Context(config, create_options(options or {}),
                 run_tracker, target_roots, **kwargs)
 def test_export_jar_path(self):
   with temporary_dir(root_dir=self.workdir_root()) as workdir:
     test_target = 'examples/tests/java/org/pantsbuild/example/usethrift:usethrift'
     json_data = self.run_export(test_target, workdir, self._resolve_args)
     # Hack because Bootstrapper.instance() reads config from cache. Will go away after we plumb
     # options into IvyUtil properly.
     Config.cache(Config.load())
     ivy_cache_dir = Bootstrapper.instance().ivy_cache_dir
     common_lang_lib_info = json_data.get('libraries').get('commons-lang:commons-lang:2.5')
     self.assertIsNotNone(common_lang_lib_info)
     self.assertEquals(
       common_lang_lib_info.get('default'),
       os.path.join(ivy_cache_dir, 'commons-lang/commons-lang/jars/commons-lang-2.5.jar')
     )
     self.assertEquals(
       common_lang_lib_info.get('javadoc'),
       os.path.join(ivy_cache_dir, 'commons-lang/commons-lang/javadocs/commons-lang-2.5-javadoc.jar')
     )
     self.assertEquals(
       common_lang_lib_info.get('sources'),
       os.path.join(ivy_cache_dir, 'commons-lang/commons-lang/sources/commons-lang-2.5-sources.jar')
     )
Example #16
0
  def setUp(self):
    super(FileDepsTest, self).setUp()

    # TODO(John Sirois): Rationalize much of this target emission setup.  Lots of tests do similar
    # things: https://github.com/pantsbuild/pants/issues/525
    def create_target(path, definition, sources=None):
      if sources:
        self.create_files(path, sources)
      self.add_to_build_file(path, definition)

    self.create_file('pants.ini',
                     contents=dedent('''
                       [compile.scala]
                       runtime-deps: ['tools:scala-library']
                     '''),
                     mode='a')

    # TODO: Required because target code has no direct config reference. Remove after fixing that.
    Config.cache(Config.load())

    create_target(path='tools',
                  definition=dedent('''
                    jar_library(
                      name='scala-library',
                      jars=[
                        jar('org.scala-lang', 'scala-library', '2.11.2'),
                      ]
                    )
                  '''))

    create_target(path='src/scala/core',
                  definition=dedent('''
                    scala_library(
                      name='core',
                      sources=[
                        'core1.scala'
                      ],
                      java_sources=[
                        'src/java/core'
                      ]
                    )
                  '''),
                  sources=['core1.scala'])

    create_target(path='src/java/core',
                  definition=dedent('''
                    java_library(
                      name='core',
                      sources=[
                        'core1.java',
                        'core2.java'
                      ],
                      dependencies=[
                        'src/scala/core'
                      ]
                    )
                  '''),
                  sources=['core1.java', 'core2.java'])

    create_target(path='src/resources/lib',
                  definition=dedent('''
                    resources(
                      name='lib',
                      sources=[
                        'data.json'
                      ]
                    )
                  '''),
                  sources=['data.json'])

    create_target(path='src/thrift/storage',
                  definition=dedent('''
                    java_thrift_library(
                      name='storage',
                      sources=[
                        'data_types.thrift'
                      ]
                    )
                  '''),
                  sources=['src/thrift/storage/data_types.thrift'])

    create_target(path='src/java/lib',
                  definition=dedent('''
                    java_library(
                      name='lib',
                      sources=[
                        'lib1.java'
                      ],
                      dependencies=[
                        'src/scala/core',
                        'src/thrift/storage'
                      ],
                      resources=[
                        'src/resources/lib'
                      ]
                    )
                  '''),
                  sources=['lib1.java'])

    # Derive a synthetic target from the src/thrift/storage thrift target as-if doing code-gen.
    self.create_file('.pants.d/gen/thrift/java/storage/Angle.java')
    self.make_target(spec='.pants.d/gen/thrift/java/storage',
                     target_type=JavaLibrary,
                     derived_from=self.target('src/thrift/storage'),
                     sources=['Angle.java'])
    synthetic_java_lib = self.target('.pants.d/gen/thrift/java/storage')

    java_lib = self.target('src/java/lib')
    java_lib.inject_dependency(synthetic_java_lib.address)

    create_target(path='src/java/bin',
                  definition=dedent('''
                    jvm_binary(
                      name='bin',
                      source='main.java',
                      main='bin.Main',
                      dependencies=[
                        'src/java/lib'
                      ]
                    )
                  '''),
                  sources=['main.java'])

    create_target(path='project',
                  definition=dedent('''
                    jvm_app(
                      name='app',
                      binary='src/java/bin',
                      bundles=[
                        bundle().add(['config/app.yaml'])
                      ]
                    )
                  '''),
                  sources=['config/app.yaml'])
Example #17
0
  def setUp(self):
    super(FileDepsTest, self).setUp()

    # TODO(John Sirois): Rationalize much of this target emission setup.  Lots of tests do similar
    # things: https://github.com/pantsbuild/pants/issues/525
    def create_target(path, definition, sources=None):
      if sources:
        self.create_files(path, sources)
      self.add_to_build_file(path, definition)

    self.create_file('pants.ini',
                     contents=dedent('''
                       [scala-compile]
                       runtime-deps: ['tools:scala-library']
                     '''),
                     mode='a')

    # TODO: Required because target code has no direct config reference. Remove after fixing that.
    Config.cache(Config.load())

    create_target(path='tools',
                  definition=dedent('''
                    jar_library(
                      name='scala-library',
                      jars=[
                        jar('org.scala-lang', 'scala-library', '2.11.2'),
                      ]
                    )
                  '''))

    create_target(path='src/scala/core',
                  definition=dedent('''
                    scala_library(
                      name='core',
                      sources=[
                        'core1.scala'
                      ],
                      java_sources=[
                        'src/java/core'
                      ]
                    )
                  '''),
                  sources=['core1.scala'])

    create_target(path='src/java/core',
                  definition=dedent('''
                    java_library(
                      name='core',
                      sources=[
                        'core1.java',
                        'core2.java'
                      ],
                      dependencies=[
                        'src/scala/core'
                      ]
                    )
                  '''),
                  sources=['core1.java', 'core2.java'])

    create_target(path='src/resources/lib',
                  definition=dedent('''
                    resources(
                      name='lib',
                      sources=[
                        'data.json'
                      ]
                    )
                  '''),
                  sources=['data.json'])

    create_target(path='src/thrift/storage',
                  definition=dedent('''
                    java_thrift_library(
                      name='storage',
                      sources=[
                        'data_types.thrift'
                      ]
                    )
                  '''),
                  sources=['src/thrift/storage/data_types.thrift'])

    create_target(path='src/java/lib',
                  definition=dedent('''
                    java_library(
                      name='lib',
                      sources=[
                        'lib1.java'
                      ],
                      dependencies=[
                        'src/scala/core',
                        'src/thrift/storage'
                      ],
                      resources=[
                        'src/resources/lib'
                      ]
                    )
                  '''),
                  sources=['lib1.java'])

    # Derive a synthetic target from the src/thrift/storage thrift target as-if doing code-gen.
    self.create_file('.pants.d/gen/thrift/java/storage/Angle.java')
    self.make_target(spec='.pants.d/gen/thrift/java/storage',
                     target_type=JavaLibrary,
                     derived_from=self.target('src/thrift/storage'),
                     sources=['Angle.java'])
    synthetic_java_lib = self.target('.pants.d/gen/thrift/java/storage')

    java_lib = self.target('src/java/lib')
    java_lib.inject_dependency(synthetic_java_lib.address)

    create_target(path='src/java/bin',
                  definition=dedent('''
                    jvm_binary(
                      name='bin',
                      source='main.java',
                      main='bin.Main',
                      dependencies=[
                        'src/java/lib'
                      ]
                    )
                  '''),
                  sources=['main.java'])

    create_target(path='project',
                  definition=dedent('''
                    jvm_app(
                      name='app',
                      binary='src/java/bin',
                      bundles=[
                        bundle().add(['config/app.yaml'])
                      ]
                    )
                  '''),
                  sources=['config/app.yaml'])