예제 #1
0
  def _list_deps(self, gopath, local_address):
    # TODO(John Sirois): Lift out a local go sources target chroot util - GoWorkspaceTask and
    # GoTargetGenerator both create these chroot symlink trees now.
    import_path = GoLocalSource.local_import_path(self._local_source_root, local_address)
    src_path = os.path.join(gopath, 'src', import_path)
    safe_mkdir(src_path)
    package_src_root = os.path.join(get_buildroot(), local_address.spec_path)
    for source_file in os.listdir(package_src_root):
      source_path = os.path.join(package_src_root, source_file)
      if GoLocalSource.is_go_source(source_path):
        dest_path = os.path.join(src_path, source_file)
        os.symlink(source_path, dest_path)

    # TODO(John Sirois): Lift up a small `go list utility` - GoFetch and GoTargetGenerator both use
    # this go command now as well as a version of the stdlib gathering done above in _go_stdlib.
    go_cmd = self._go_distribution.create_go_cmd('list', args=['-json', import_path], gopath=gopath)
    with self._workunit_factory(local_address.reference(),
                                cmd=str(go_cmd),
                                labels=[WorkUnitLabel.TOOL]) as workunit:
      # TODO(John Sirois): It would be nice to be able to tee the stdout to the workunit to we have
      # a capture of the json available for inspection in the server console.
      process = go_cmd.spawn(stdout=subprocess.PIPE, stderr=workunit.output('stderr'))
      out, _ = process.communicate()
      returncode = process.returncode
      workunit.set_outcome(WorkUnit.SUCCESS if returncode == 0 else WorkUnit.FAILURE)
      if returncode != 0:
        raise self.GenerationError('Problem listing imports for {}: {} failed with exit code {}'
                                   .format(local_address, go_cmd, returncode))
      data = json.loads(out)
      return data.get('Name'), data.get('Imports', []) + data.get('TestImports', [])
예제 #2
0
파일: go_buildgen.py 프로젝트: ttim/pants
    def _list_deps(self, gopath, local_address):
        # TODO(John Sirois): Lift out a local go sources target chroot util - GoWorkspaceTask and
        # GoTargetGenerator both create these chroot symlink trees now.
        import_path = GoLocalSource.local_import_path(self._local_source_root, local_address)
        src_path = os.path.join(gopath, "src", import_path)
        safe_mkdir(src_path)
        package_src_root = os.path.join(get_buildroot(), local_address.spec_path)
        for source_file in os.listdir(package_src_root):
            source_path = os.path.join(package_src_root, source_file)
            if GoLocalSource.is_go_source(source_path):
                dest_path = os.path.join(src_path, source_file)
                os.symlink(source_path, dest_path)

        return self._import_oracle.list_imports(import_path, gopath=gopath)
예제 #3
0
    def _list_deps(self, gopath, local_address):
        # TODO(John Sirois): Lift out a local go sources target chroot util - GoWorkspaceTask and
        # GoTargetGenerator both create these chroot symlink trees now.
        import_path = GoLocalSource.local_import_path(self._local_source_root,
                                                      local_address)
        src_path = os.path.join(gopath, 'src', import_path)
        safe_mkdir(src_path)
        package_src_root = os.path.join(get_buildroot(),
                                        local_address.spec_path)
        for source_file in os.listdir(package_src_root):
            source_path = os.path.join(package_src_root, source_file)
            if GoLocalSource.is_go_source(source_path):
                dest_path = os.path.join(src_path, source_file)
                os.symlink(source_path, dest_path)

        return self._import_oracle.list_imports(import_path, gopath=gopath)
예제 #4
0
 def calculate_sources(cls, targets):
     sources = set()
     for target in targets:
         sources.update(
             source for source in target.sources_relative_to_buildroot()
             if GoLocalSource.is_go_source(source))
     return sources
예제 #5
0
 def source_iter():
     remote_lib_source_dir = self.context.products.get_data(
         'go_remote_lib_src')[go_remote_lib]
     for path in os.listdir(remote_lib_source_dir):
         remote_src = os.path.join(remote_lib_source_dir, path)
         if GoLocalSource.is_go_source(remote_src):
             yield remote_src
예제 #6
0
    def _list_deps(self, gopath, local_address):
        # TODO(John Sirois): Lift out a local go sources target chroot util - GoWorkspaceTask and
        # GoTargetGenerator both create these chroot symlink trees now.
        import_path = GoLocalSource.local_import_path(self._local_source_root,
                                                      local_address)
        src_path = os.path.join(gopath, 'src', import_path)
        safe_mkdir(src_path)
        package_src_root = os.path.join(get_buildroot(),
                                        local_address.spec_path)
        for source_file in os.listdir(package_src_root):
            source_path = os.path.join(package_src_root, source_file)
            if GoLocalSource.is_go_source(source_path):
                dest_path = os.path.join(src_path, source_file)
                os.symlink(source_path, dest_path)

        # TODO(John Sirois): Lift up a small `go list utility` - GoFetch and GoTargetGenerator both use
        # this go command now as well as a version of the stdlib gathering done above in _go_stdlib.
        go_cmd = self._go_distribution.create_go_cmd(
            'list', args=['-json', import_path], gopath=gopath)
        with self._workunit_factory(local_address.reference(),
                                    cmd=str(go_cmd),
                                    labels=[WorkUnitLabel.TOOL]) as workunit:
            # TODO(John Sirois): It would be nice to be able to tee the stdout to the workunit to we have
            # a capture of the json available for inspection in the server console.
            process = go_cmd.spawn(stdout=subprocess.PIPE,
                                   stderr=workunit.output('stderr'))
            out, _ = process.communicate()
            returncode = process.returncode
            workunit.set_outcome(WorkUnit.SUCCESS if returncode ==
                                 0 else WorkUnit.FAILURE)
            if returncode != 0:
                raise self.GenerationError(
                    'Problem listing imports for {}: {} failed with exit code {}'
                    .format(local_address, go_cmd, returncode))
            data = json.loads(out)
            return data.get('Name'), data.get('Imports', []) + data.get(
                'TestImports', [])
예제 #7
0
 def import_path(self):
   """The import path as used in import statements in `.go` source files."""
   return GoLocalSource.local_import_path(self.target_base, self.address)
예제 #8
0
 def import_path(self):
     """The import path as used in import statements in `.go` source files."""
     return GoLocalSource.local_import_path(self.target_base, self.address)
예제 #9
0
 def source_iter():
   remote_lib_source_dir = self.context.products.get_data('go_remote_lib_src')[go_remote_lib]
   for path in os.listdir(remote_lib_source_dir):
     remote_src = os.path.join(remote_lib_source_dir, path)
     if GoLocalSource.is_go_source(remote_src):
       yield remote_src
예제 #10
0
 def calculate_sources(cls, targets):
   sources = set()
   for target in targets:
     sources.update(source for source in target.sources_relative_to_buildroot()
                    if GoLocalSource.is_go_source(source))
   return sources