|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | | -use std::fs; |
16 | 15 | use std::path::Path; |
17 | 16 | use std::process::Command as StdCommand; |
18 | 17 |
|
@@ -73,16 +72,7 @@ struct CommandPackage { |
73 | 72 |
|
74 | 73 | impl CommandPackage { |
75 | 74 | fn run(self) { |
76 | | - let main_version = package_version("serde-shape"); |
77 | | - let derive_version = package_version("serde-shape-derive"); |
78 | | - |
79 | | - run_command(make_package_cmd("serde-shape-derive", self.locked)); |
80 | | - |
81 | | - // Cargo would otherwise verify main against an already-published derive crate with the |
82 | | - // same version. Unpack the archive and patch the two packaged crates together instead. |
83 | | - run_command(make_package_archive_cmd("serde-shape", self.locked)); |
84 | | - unpack_package_archive("serde-shape", &main_version); |
85 | | - run_command(make_verify_main_package_cmd(&main_version, &derive_version)); |
| 75 | + run_command(make_package_cmd(self.locked)); |
86 | 76 | } |
87 | 77 | } |
88 | 78 |
|
@@ -182,77 +172,22 @@ fn make_build_cmd(locked: bool) -> StdCommand { |
182 | 172 | cmd |
183 | 173 | } |
184 | 174 |
|
185 | | -fn make_package_cmd(package: &str, locked: bool) -> StdCommand { |
| 175 | +fn make_package_cmd(locked: bool) -> StdCommand { |
186 | 176 | let mut cmd = find_command("cargo"); |
187 | | - cmd.args(["package", "--package", package, "--all-features"]); |
| 177 | + cmd.args([ |
| 178 | + "package", |
| 179 | + "--package", |
| 180 | + "serde-shape-derive", |
| 181 | + "--package", |
| 182 | + "serde-shape", |
| 183 | + "--all-features", |
| 184 | + ]); |
188 | 185 | if locked { |
189 | 186 | cmd.arg("--locked"); |
190 | 187 | } |
191 | 188 | cmd |
192 | 189 | } |
193 | 190 |
|
194 | | -fn make_package_archive_cmd(package: &str, locked: bool) -> StdCommand { |
195 | | - let mut cmd = make_package_cmd(package, locked); |
196 | | - cmd.arg("--no-verify"); |
197 | | - cmd |
198 | | -} |
199 | | - |
200 | | -fn unpack_package_archive(package: &str, version: &str) { |
201 | | - let package_root = workspace_dir().join("target/package"); |
202 | | - let package_dir = package_root.join(format!("{package}-{version}")); |
203 | | - if package_dir.exists() { |
204 | | - fs::remove_dir_all(&package_dir).expect("failed to remove stale package directory"); |
205 | | - } |
206 | | - |
207 | | - let mut cmd = find_command("tar"); |
208 | | - cmd.arg("-xzf") |
209 | | - .arg(package_root.join(format!("{package}-{version}.crate"))) |
210 | | - .arg("-C") |
211 | | - .arg(package_root); |
212 | | - run_command(cmd); |
213 | | -} |
214 | | - |
215 | | -fn make_verify_main_package_cmd(main_version: &str, derive_version: &str) -> StdCommand { |
216 | | - let package_dir = workspace_dir() |
217 | | - .join("target/package") |
218 | | - .join(format!("serde-shape-{main_version}")); |
219 | | - let derive_dir = workspace_dir() |
220 | | - .join("target/package") |
221 | | - .join(format!("serde-shape-derive-{derive_version}")); |
222 | | - let derive_dir = serde_json::to_string(&derive_dir.to_string_lossy()).unwrap(); |
223 | | - let patch = format!("patch.crates-io.serde-shape-derive.path={derive_dir}"); |
224 | | - |
225 | | - let mut cmd = find_command("cargo"); |
226 | | - cmd.args(["check", "--manifest-path"]) |
227 | | - .arg(package_dir.join("Cargo.toml")) |
228 | | - .args(["--all-features", "--config", &patch]); |
229 | | - cmd |
230 | | -} |
231 | | - |
232 | | -fn package_version(package: &str) -> String { |
233 | | - let mut cmd = find_command("cargo"); |
234 | | - cmd.args(["metadata", "--no-deps", "--format-version", "1"]); |
235 | | - let output = cmd.output().expect("failed to read workspace metadata"); |
236 | | - assert!( |
237 | | - output.status.success(), |
238 | | - "cargo metadata failed: {}", |
239 | | - String::from_utf8_lossy(&output.stderr) |
240 | | - ); |
241 | | - |
242 | | - let metadata: serde_json::Value = |
243 | | - serde_json::from_slice(&output.stdout).expect("cargo metadata should be valid JSON"); |
244 | | - metadata["packages"] |
245 | | - .as_array() |
246 | | - .and_then(|packages| { |
247 | | - packages |
248 | | - .iter() |
249 | | - .find(|candidate| candidate["name"] == package) |
250 | | - }) |
251 | | - .and_then(|package| package["version"].as_str()) |
252 | | - .unwrap_or_else(|| panic!("package {package} not found in cargo metadata")) |
253 | | - .to_owned() |
254 | | -} |
255 | | - |
256 | 191 | fn make_test_cmd(no_capture: bool, package: &str, features: &[&str]) -> StdCommand { |
257 | 192 | let mut cmd = find_command("cargo"); |
258 | 193 | cmd.args(["test", "-p", package, "--no-default-features"]); |
|
0 commit comments