Skip to content

Commit 8f03308

Browse files
jneemtorhovland
andcommitted
Add workspace publishing
Co-authored-by: Tor Hovland <55164+torhovland@users.noreply.github.com>
1 parent 5f7e074 commit 8f03308

File tree

7 files changed

+527
-186
lines changed

7 files changed

+527
-186
lines changed

src/cargo/ops/cargo_package.rs

+34-35
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,6 @@ struct GitVcsInfo {
9393
dirty: bool,
9494
}
9595

96-
/// Packages a single package in a workspace, returning the resulting tar file.
97-
///
98-
/// # Panics
99-
/// Panics if `opts.list` is true. In that case you probably don't want to
100-
/// actually build the package tarball; you should just make and print the list
101-
/// of files. (We don't currently provide a public API for that, but see how
102-
/// [`package`] does it.)
103-
pub fn package_one(
104-
ws: &Workspace<'_>,
105-
pkg: &Package,
106-
opts: &PackageOpts<'_>,
107-
) -> CargoResult<FileLock> {
108-
assert!(!opts.list);
109-
110-
let ar_files = prepare_archive(ws, pkg, opts)?;
111-
let tarball = create_package(ws, pkg, ar_files, None)?;
112-
113-
if opts.verify {
114-
run_verify(ws, pkg, &tarball, None, opts)?;
115-
}
116-
117-
Ok(tarball)
118-
}
119-
12096
// Builds a tarball and places it in the output directory.
12197
fn create_package(
12298
ws: &Workspace<'_>,
@@ -179,6 +155,29 @@ fn create_package(
179155
/// Returns the generated package files. If `opts.list` is true, skips
180156
/// generating package files and returns an empty list.
181157
pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<FileLock>> {
158+
Ok(do_package(ws, opts)?.into_iter().map(|x| x.2).collect())
159+
}
160+
161+
/// Packages an entire workspace.
162+
///
163+
/// Returns the generated package files and the dependencies between them. If
164+
/// `opts.list` is true, skips generating package files and returns an empty
165+
/// list.
166+
pub(crate) fn package_with_dep_graph(
167+
ws: &Workspace<'_>,
168+
opts: &PackageOpts<'_>,
169+
) -> CargoResult<LocalDependencies<(CliFeatures, FileLock)>> {
170+
let output = do_package(ws, opts)?;
171+
172+
Ok(local_deps(output.into_iter().map(
173+
|(pkg, opts, tarball)| (pkg, (opts.cli_features, tarball)),
174+
)))
175+
}
176+
177+
fn do_package<'a>(
178+
ws: &Workspace<'_>,
179+
opts: &PackageOpts<'a>,
180+
) -> CargoResult<Vec<(Package, PackageOpts<'a>, FileLock)>> {
182181
let specs = &opts.to_package.to_package_id_specs(ws)?;
183182
// If -p is used, we should check spec is matched with the members (See #13719)
184183
if let ops::Packages::Packages(_) = opts.to_package {
@@ -264,7 +263,7 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<Fi
264263
}
265264
}
266265

267-
Ok(outputs.into_iter().map(|x| x.2).collect())
266+
Ok(outputs)
268267
}
269268

270269
/// Determine which registry the packages are for.
@@ -308,15 +307,14 @@ fn get_registry(
308307
}
309308

310309
/// Just the part of the dependency graph that's between the packages we're packaging.
311-
/// (Is the package name a good key? Does it uniquely identify packages?)
312310
#[derive(Clone, Debug, Default)]
313-
struct LocalDependencies {
314-
packages: HashMap<PackageId, (Package, CliFeatures)>,
315-
graph: Graph<PackageId, ()>,
311+
pub(crate) struct LocalDependencies<T> {
312+
pub packages: HashMap<PackageId, (Package, T)>,
313+
pub graph: Graph<PackageId, ()>,
316314
}
317315

318-
impl LocalDependencies {
319-
fn sort(&self) -> Vec<(Package, CliFeatures)> {
316+
impl<T: Clone> LocalDependencies<T> {
317+
pub fn sort(&self) -> Vec<(Package, T)> {
320318
self.graph
321319
.sort()
322320
.into_iter()
@@ -335,9 +333,10 @@ impl LocalDependencies {
335333
/// ignoring dev dependencies.
336334
///
337335
/// We assume that the packages all belong to this workspace.
338-
fn local_deps(packages: impl Iterator<Item = (Package, CliFeatures)>) -> LocalDependencies {
339-
let packages: HashMap<PackageId, (Package, CliFeatures)> =
340-
packages.map(|pkg| (pkg.0.package_id(), pkg)).collect();
336+
fn local_deps<T>(packages: impl Iterator<Item = (Package, T)>) -> LocalDependencies<T> {
337+
let packages: HashMap<PackageId, (Package, T)> = packages
338+
.map(|(pkg, payload)| (pkg.package_id(), (pkg, payload)))
339+
.collect();
341340

342341
// Dependencies have source ids but not package ids. We draw an edge
343342
// whenever a dependency's source id matches one of our packages. This is
@@ -349,7 +348,7 @@ fn local_deps(packages: impl Iterator<Item = (Package, CliFeatures)>) -> LocalDe
349348
.collect();
350349

351350
let mut graph = Graph::new();
352-
for (pkg, _features) in packages.values() {
351+
for (pkg, _payload) in packages.values() {
353352
graph.add(pkg.package_id());
354353
for dep in pkg.dependencies() {
355354
// Ignore local dev-dependencies because they aren't needed for intra-workspace

src/cargo/ops/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use self::cargo_fetch::{fetch, FetchOptions};
1010
pub use self::cargo_install::{install, install_list};
1111
pub use self::cargo_new::{init, new, NewOptions, NewProjectKind, VersionControl};
1212
pub use self::cargo_output_metadata::{output_metadata, ExportInfo, OutputMetadataOptions};
13-
pub use self::cargo_package::{check_yanked, package, package_one, PackageOpts};
13+
pub use self::cargo_package::{check_yanked, package, PackageOpts};
1414
pub use self::cargo_pkgid::pkgid;
1515
pub use self::cargo_read_manifest::read_package;
1616
pub use self::cargo_run::run;

0 commit comments

Comments
 (0)