Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Move writePackageFile to UFCS, better document #2875

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions source/dub/test/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -656,17 +656,6 @@ public class FSEntry
}
}

/// Writes a package file for package `name` of version `vers` at `loc`.
public void writePackageFile (in string name, in string vers, in string recipe,
in PackageFormat fmt = PackageFormat.json,
in PlacementLocation location = PlacementLocation.user)
{
const path = FSEntry.getPackagePath(name, vers, location);
this.mkdir(path).writeFile(
NativePath(fmt == PackageFormat.json ? "dub.json" : "dub.sdl"),
recipe);
}

/// Returns: The final destination a specific package needs to be stored in
public static NativePath getPackagePath(in string name_, string vers,
PlacementLocation location = PlacementLocation.user)
Expand Down Expand Up @@ -794,3 +783,27 @@ public class FSEntry
}
}
}

/**
* Convenience function to write a package file
*
* Allows to write a package file (and only a package file) for a certain
* package name and version.
*
* Params:
* root = The root FSEntry
* name = The package name (typed as string for convenience)
* vers = The package version
* recipe = The text of the package recipe
* fmt = The format used for `recipe` (default to JSON)
* location = Where to place the package (default to user location)
*/
public void writePackageFile (FSEntry root, in string name, in string vers,
in string recipe, in PackageFormat fmt = PackageFormat.json,
in PlacementLocation location = PlacementLocation.user)
{
const path = FSEntry.getPackagePath(name, vers, location);
root.mkdir(path).writeFile(
NativePath(fmt == PackageFormat.json ? "dub.json" : "dub.sdl"),
recipe);
}
Loading