@@ -5,83 +5,19 @@ mod cargo_tree_resolver;
5
5
mod dependency;
6
6
mod metadata_annotation;
7
7
8
- use std:: env;
9
8
use std:: fs;
10
9
use std:: path:: { Path , PathBuf } ;
11
10
use std:: str:: FromStr ;
12
11
13
12
use anyhow:: { bail, Context , Result } ;
14
13
use camino:: Utf8Path ;
15
- use cargo_lock:: Lockfile as CargoLockfile ;
16
- use cargo_metadata:: Metadata as CargoMetadata ;
17
14
use tracing:: debug;
18
15
19
16
pub ( crate ) use self :: cargo_bin:: * ;
20
17
pub ( crate ) use self :: cargo_tree_resolver:: * ;
21
18
pub ( crate ) use self :: dependency:: * ;
22
19
pub ( crate ) use self :: metadata_annotation:: * ;
23
20
24
- // TODO: This should also return a set of [crate-index::IndexConfig]s for packages in metadata.packages
25
- /// A Trait for generating metadata (`cargo metadata` output and a lock file) from a Cargo manifest.
26
- pub ( crate ) trait MetadataGenerator {
27
- fn generate < T : AsRef < Path > > ( & self , manifest_path : T ) -> Result < ( CargoMetadata , CargoLockfile ) > ;
28
- }
29
-
30
- /// Generates Cargo metadata and a lockfile from a provided manifest.
31
- pub ( crate ) struct Generator {
32
- /// The path to a `cargo` binary
33
- cargo_bin : Cargo ,
34
-
35
- /// The path to a `rustc` binary
36
- rustc_bin : PathBuf ,
37
- }
38
-
39
- impl Generator {
40
- pub ( crate ) fn new ( ) -> Self {
41
- let rustc_bin = PathBuf :: from ( env:: var ( "RUSTC" ) . unwrap_or_else ( |_| "rustc" . to_string ( ) ) ) ;
42
- Generator {
43
- cargo_bin : Cargo :: new (
44
- PathBuf :: from ( env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . to_string ( ) ) ) ,
45
- rustc_bin. clone ( ) ,
46
- ) ,
47
- rustc_bin,
48
- }
49
- }
50
-
51
- pub ( crate ) fn with_cargo ( mut self , cargo_bin : Cargo ) -> Self {
52
- self . cargo_bin = cargo_bin;
53
- self
54
- }
55
-
56
- pub ( crate ) fn with_rustc ( mut self , rustc_bin : PathBuf ) -> Self {
57
- self . rustc_bin = rustc_bin;
58
- self
59
- }
60
- }
61
-
62
- impl MetadataGenerator for Generator {
63
- fn generate < T : AsRef < Path > > ( & self , manifest_path : T ) -> Result < ( CargoMetadata , CargoLockfile ) > {
64
- let manifest_dir = manifest_path
65
- . as_ref ( )
66
- . parent ( )
67
- . expect ( "The manifest should have a parent directory" ) ;
68
- let lockfile = {
69
- let lock_path = manifest_dir. join ( "Cargo.lock" ) ;
70
- if !lock_path. exists ( ) {
71
- bail ! ( "No `Cargo.lock` file was found with the given manifest" )
72
- }
73
- cargo_lock:: Lockfile :: load ( lock_path) ?
74
- } ;
75
-
76
- let metadata = self
77
- . cargo_bin
78
- . metadata_command_with_options ( manifest_path. as_ref ( ) , vec ! [ "--locked" . to_owned( ) ] ) ?
79
- . exec ( ) ?;
80
-
81
- Ok ( ( metadata, lockfile) )
82
- }
83
- }
84
-
85
21
/// A configuration describing how to invoke [cargo update](https://doc.rust-lang.org/cargo/commands/cargo-update.html).
86
22
#[ derive( Debug , Clone , PartialEq , Eq ) ]
87
23
pub enum CargoUpdateRequest {
@@ -340,14 +276,6 @@ impl VendorGenerator {
340
276
}
341
277
}
342
278
343
- /// A helper function for writing Cargo metadata to a file.
344
- pub ( crate ) fn write_metadata ( path : & Path , metadata : & cargo_metadata:: Metadata ) -> Result < ( ) > {
345
- let content =
346
- serde_json:: to_string_pretty ( metadata) . context ( "Failed to serialize Cargo Metadata" ) ?;
347
-
348
- fs:: write ( path, content) . context ( "Failed to write metadata to disk" )
349
- }
350
-
351
279
/// A helper function for deserializing Cargo metadata and lockfiles
352
280
pub ( crate ) fn load_metadata (
353
281
metadata_path : & Path ,
0 commit comments