https://pantsbuild.org/ logo
p

plain-river-51682

09/17/2020, 8:42 AM
We currently have a bunch of bash files in our CI pipeline that get the list of targets to build (using
list, dependees, minimize, filter
). Is there a way to write a pants plugin that invokes these goals?
h

happy-kitchen-89482

09/17/2020, 4:25 PM
To clarify, you invoke several Pants commands and you'd prefer to have one custom command that does the same work?
p

plain-river-51682

09/18/2020, 7:49 AM
yes, right now we do this:
Copy code
local changed
  changed=($(./pants ${changed_parent} list))
  if [[ -z $changed ]]; then
    return 0
  fi

  local dependees
  dependees=($(./pants dependees --dependees-transitive --dependees-closed "${changed[@]}"))
  local minimized
  minimized=($(./pants minimize "${dependees[@]}"))

  local changed_targets
  changed_targets=($(./pants filter ${filter} "${minimized[@]}"))

  echo "Got changed targets ${changed_targets[@]}" "${TARGETS[@]}"
  TARGETS=("${changed_targets[@]}" "${TARGETS[@]}")
But bash syntax is clunky and we would like to add some more logic that would be easier to write in python. We would rather do
./pants run-ci-pipeline --step test
that would run the needed steps to calculate the targets and run tests against them
h

happy-kitchen-89482

09/18/2020, 8:01 PM
Yep, that should absolutely be possible with a custom goal. What version of Pants are you on, and what languages are you targeting?
p

plain-river-51682

09/19/2020, 9:18 AM
we are on 1.29.0 and build scala projects
h

happy-kitchen-89482

09/21/2020, 10:23 PM
OK, so you need the plugin API for the v1 engine, not the one for the new v2 engine (which doesn't have Scala support yet).
You'll want to create a custom v1 task, as described here: https://v1.pantsbuild.org/dev_tasks.html
You can see examples (including of the tasks that implement the
list, dependees, minimize, filter
functionality you're currently using separately) here: https://github.com/pantsbuild/pants/tree/1.29.x/src/python/pants/backend/project_info, https://github.com/pantsbuild/pants/tree/1.29.x/src/python/pants/backend/graph_info/tasks
(note the 1.29.x branch, the v1 code has been removed in the main development branch, as we're working towards a 2.x launch)
3 Views