docs: def build_core_constraints(system_info, core_resource=Cores):
      """Return a set of place-and-route
      :py:class:`~rig.place_and_route.constraints.ReserveResourceConstraint`
      which reserve any cores that that are already in use.
  
      The returned list of
      :py:class:`~rig.place_and_route.constraints.ReserveResourceConstraint`\ s
      reserves all cores not in an Idle state (i.e. not a monitor and not already
      running an application).
  
      .. note::
  
          Historically, every application was required to add a
          :py:class:~rig.place_and_route.constraints.ReserveResourceConstraint to
          reserve the monitor processor on each chip. This method improves upon
          this approach by automatically generating constraints which reserve not
          just the monitor core but also any other cores which are already in
          use.
  
      Parameters
      ----------
      system_info : :py:class:`rig.machine_control.machine_controller.SystemInfo`
          The resource availability information for a SpiNNaker machine,
          typically produced by
          :py:meth:`rig.machine_control.MachineController.get_system_info`.
      core_resource : resource (Default: :py:data:`~rig.place_and_route.Cores`)
          The resource identifier used for cores.
  
      Returns
      -------
      [:py:class:`rig.place_and_route.constraints.ReserveResourceConstraint`, \
              ...]
          A set of place-and-route constraints which reserves all non-idle cores.
          The resource type given in the ``core_resource`` argument will be
          reserved accordingly.
      """
      constraints = []
  
      # Find the set of cores which are universally reserved
      globally_reserved = None
      for chip_info in itervalues(system_info):
          reserved = sum(1 << c for c, state in enumerate(chip_info.core_states)
                         if state != AppState.idle)
          if globally_reserved is None:
              globally_reserved = reserved
          else:
              globally_reserved &= reserved
  
      if globally_reserved is None:
          globally_reserved = 0
  
      constraints.extend(_get_minimal_core_reservations(
          core_resource,
          [core for core in range(18) if (1 << core) & globally_reserved]))
  
      # Create chip-specific resource reservations for any special cases
      for chip, chip_info in iteritems(system_info):
          constraints.extend(_get_minimal_core_reservations(
              core_resource,
              [core for core, state in enumerate(chip_info.core_states)
               if state != AppState.idle and
                  not globally_reserved & (1 << core)],
              chip))
  
      return constraints