determinator

Struct Determinator

Source
pub struct Determinator<'g, 'a> { /* private fields */ }
Expand description

Determine target dependencies from changed files and packages in a workspace.

For more about how the determinator works, see the crate-level documentation.

This struct has two lifetime parameters:

  • 'g stands for the lifetime of the new graph. The DeterminatorSet will be bound to this lifetime.
  • 'a is the lifetime of the old graph, Cargo options, and changed paths. The DeterminatorSet will not be bound to this lifetime.

Implementations§

Source§

impl<'g, 'a> Determinator<'g, 'a>

Source

pub fn new(old: &'a PackageGraph, new: &'g PackageGraph) -> Self

Creates a new instance of Determinator with old and new package graphs.

Source

pub fn add_changed_paths( &mut self, paths: impl IntoIterator<Item = &'a (impl AsRef<Utf8Path> + ?Sized + 'a)>, ) -> &mut Self

Adds a list of changed paths. This list is used as a source of information for the determinator.

This should consist of paths that are changed since the base revision. Paths on Windows may use either / or \\ as separators.

Utf8Paths0 in this crate provides a convenient way to handle null-separated paths as produced by source control systems.

§Should you include untracked and ignored files?

For comparisons against the working directory, one may or may not wish to include untracked files. A few points to consider:

  • If your code uses a library like datatest, simply creating a file in the right place is enough to add a new test. If untracked files are not included, the user may have to run git add before the determinator picks the change up.
  • On the other hand, if a user wishes to include a new test in their PR, they’re going to have to run git add at some point anyway.
  • Some users may have untracked files lying around in their repository for long periods of time, and those files may cause false positives.
  • Git makes it surprisingly hard to list out untracked files, requiring git status --porcelain -z with some additional filtering on top to do so. git diff doesn’t have an option to list untracked files.
  • This is generally moot in CI, since those workflows will likely be comparing against a commit.
  • In most cases, ignored files should not be considered by the determinator, since they don’t affect CI builds.

On balance, only considering tracked files appears to be the right approach for most situations.

Source

pub fn match_path( &self, path: impl AsRef<Utf8Path>, match_cb: impl FnMut(&'g PackageId), ) -> PathMatch

Returns what would happen if a given path was added to the changed set.

This does not add any path to the changed set, but indicates what would happen if a path is added.

This method may be used to ensure that all paths in a repository are covered by at least one rule if they don’t match a package.

match_cb is called for all package IDs that the path matches.

Source

pub fn set_rules( &mut self, rules: &DeterminatorRules, ) -> Result<&mut Self, RulesError>

Processes and configures determinator rules.

Returns an error if the rules were invalid in some way.

Source

pub fn set_cargo_options( &mut self, cargo_options: &'a CargoOptions<'a>, ) -> &mut Self

Configures Cargo options.

These options are used to determine if the build for a particular package has changed.

If no options are specified, the default CargoOptions, as specified by CargoOptions::new, are used, with one exception: dev-dependencies are built by default.

Source

pub fn default_cargo_options() -> CargoOptions<'static>

Returns the default Cargo options used by the determinator.

These are the same as the defaults returned by CargoOptions::new, except:

  • dev-dependencies are enabled
  • the host and target platforms are set to the current platform
Source

pub fn set_features_only<'b>( &mut self, workspace_names: impl IntoIterator<Item = &'b str>, features: StandardFeatures, ) -> Result<&mut Self, Error>

Configures features-only packages that are used in build simulations.

The packages and features will be used for feature unification. This is useful for pseudo-packages or workspace-hack packages, including those generated by tools like Hakari.

For more about features_only, see the documentation for CargoSet::new.

The package names are expected to be present in the new graph, but may not be present in the old PackageGraph.

  • If a package name isn’t in the new graph, this method returns an error.
  • If a package name isn’t in the old graph, it is ignored.
Source

pub fn compute(&self) -> DeterminatorSet<'g>

Uses the old and new sets and the list of changed files to compute the list of projects that is affected.

Trait Implementations§

Source§

impl<'g, 'a> Clone for Determinator<'g, 'a>

Source§

fn clone(&self) -> Determinator<'g, 'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'g, 'a> Debug for Determinator<'g, 'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'g, 'a> Freeze for Determinator<'g, 'a>

§

impl<'g, 'a> RefUnwindSafe for Determinator<'g, 'a>

§

impl<'g, 'a> Send for Determinator<'g, 'a>

§

impl<'g, 'a> Sync for Determinator<'g, 'a>

§

impl<'g, 'a> Unpin for Determinator<'g, 'a>

§

impl<'g, 'a> UnwindSafe for Determinator<'g, 'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V