Skip to content

Commit e8da195

Browse files
authored
Revert accidental breaking change introduced in #655 (#694)
Changing type of a field (introduced in #655) is a semver breaking change, and we can only do it in `scarb-metadata 2.0` release. This PR reverts this type back.
1 parent 0de448b commit e8da195

File tree

3 files changed

+110
-17
lines changed

3 files changed

+110
-17
lines changed

scarb-metadata/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ pub struct ManifestMetadata {
381381
pub license_file: Option<String>,
382382
/// A path to a file in the package root (relative to its `Scarb.toml`) that contains general
383383
/// information about the package.
384-
pub readme: Option<Utf8PathBuf>,
384+
pub readme: Option<String>,
385385
/// A URL to the source repository for this package.
386386
pub repository: Option<String>,
387387
/// A map of additional internet links related to this package.

scarb/src/ops/metadata.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ fn collect_package_metadata(package: &Package) -> m::PackageMetadata {
104104
.keywords(package.manifest.metadata.keywords.clone())
105105
.license(package.manifest.metadata.license.clone())
106106
.license_file(package.manifest.metadata.license_file.clone())
107-
.readme(package.manifest.metadata.readme.clone())
107+
.readme(
108+
package
109+
.manifest
110+
.metadata
111+
.readme
112+
.as_ref()
113+
.map(ToString::to_string),
114+
)
108115
.repository(package.manifest.metadata.repository.clone())
109116
.urls(package.manifest.metadata.urls.clone())
110117
.tool(

scarb/tests/metadata.rs

+101-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use std::collections::BTreeMap;
22

33
use assert_fs::prelude::*;
4-
use camino::Utf8PathBuf;
54
use indoc::indoc;
6-
use serde_json::json;
7-
85
use scarb_metadata::{Cfg, ManifestMetadataBuilder, Metadata, PackageMetadata};
96
use scarb_test_support::command::{CommandExt, Scarb};
7+
use scarb_test_support::fsx::PathBufUtf8Ext;
108
use scarb_test_support::project_builder::ProjectBuilder;
119
use scarb_test_support::workspace_builder::WorkspaceBuilder;
10+
use serde_json::json;
1211

1312
fn packages_by_name(meta: Metadata) -> BTreeMap<String, PackageMetadata> {
1413
meta.packages
@@ -285,7 +284,14 @@ fn manifest_targets_and_metadata() {
285284
]))
286285
.license(Some("MIT License".to_string()))
287286
.license_file(Some("./license.md".to_string()))
288-
.readme(Utf8PathBuf::from_path_buf(t.join("README.md").canonicalize().unwrap()).ok())
287+
.readme(
288+
t.join("README.md")
289+
.canonicalize()
290+
.unwrap()
291+
.try_into_utf8()
292+
.unwrap()
293+
.into_string()
294+
)
289295
.repository(Some("https://github.com/johndoe/repo".to_string()))
290296
.tool(Some(BTreeMap::from_iter([
291297
("meta".to_string(), json!("data")),
@@ -610,7 +616,14 @@ fn infer_readme_simple() {
610616
.unwrap()
611617
.manifest_metadata
612618
.readme,
613-
Utf8PathBuf::from_path_buf(t.join("README").canonicalize().unwrap()).ok()
619+
Some(
620+
t.join("README")
621+
.canonicalize()
622+
.unwrap()
623+
.try_into_utf8()
624+
.unwrap()
625+
.into_string()
626+
)
614627
);
615628

616629
t.child("README.txt").touch().unwrap();
@@ -629,7 +642,14 @@ fn infer_readme_simple() {
629642
.unwrap()
630643
.manifest_metadata
631644
.readme,
632-
Utf8PathBuf::from_path_buf(t.join("README.txt").canonicalize().unwrap()).ok()
645+
Some(
646+
t.join("README.txt")
647+
.canonicalize()
648+
.unwrap()
649+
.try_into_utf8()
650+
.unwrap()
651+
.into_string()
652+
)
633653
);
634654

635655
t.child("README.md").touch().unwrap();
@@ -648,7 +668,14 @@ fn infer_readme_simple() {
648668
.unwrap()
649669
.manifest_metadata
650670
.readme,
651-
Utf8PathBuf::from_path_buf(t.join("README.md").canonicalize().unwrap()).ok()
671+
Some(
672+
t.join("README.md")
673+
.canonicalize()
674+
.unwrap()
675+
.try_into_utf8()
676+
.unwrap()
677+
.into_string()
678+
)
652679
);
653680

654681
t.child("Scarb.toml")
@@ -683,7 +710,14 @@ fn infer_readme_simple() {
683710
.unwrap()
684711
.manifest_metadata
685712
.readme,
686-
Utf8PathBuf::from_path_buf(t.join("a/b/c/MEREAD.md").canonicalize().unwrap()).ok()
713+
Some(
714+
t.join("a/b/c/MEREAD.md")
715+
.canonicalize()
716+
.unwrap()
717+
.try_into_utf8()
718+
.unwrap()
719+
.into_string()
720+
)
687721
);
688722
}
689723

@@ -762,7 +796,14 @@ fn infer_readme_simple_bool() {
762796
.unwrap()
763797
.manifest_metadata
764798
.readme,
765-
Utf8PathBuf::from_path_buf(t.join("README.md").canonicalize().unwrap()).ok()
799+
Some(
800+
t.join("README.md")
801+
.canonicalize()
802+
.unwrap()
803+
.try_into_utf8()
804+
.unwrap()
805+
.into_string()
806+
)
766807
);
767808
}
768809

@@ -944,27 +985,72 @@ fn infer_readme_workspace() {
944985
let packages = packages_by_name(meta);
945986
assert_eq!(
946987
packages.get("hello").unwrap().manifest_metadata.readme,
947-
Utf8PathBuf::from_path_buf(t.join("MEREAD.md").canonicalize().unwrap()).ok()
988+
Some(
989+
t.join("MEREAD.md")
990+
.canonicalize()
991+
.unwrap()
992+
.try_into_utf8()
993+
.unwrap()
994+
.into_string()
995+
)
948996
);
949997
assert_eq!(
950998
packages.get("t7").unwrap().manifest_metadata.readme,
951-
Utf8PathBuf::from_path_buf(t.join("MEREAD.md").canonicalize().unwrap()).ok()
999+
Some(
1000+
t.join("MEREAD.md")
1001+
.canonicalize()
1002+
.unwrap()
1003+
.try_into_utf8()
1004+
.unwrap()
1005+
.into_string()
1006+
)
9521007
);
9531008
assert_eq!(
9541009
packages.get("t1").unwrap().manifest_metadata.readme,
955-
Utf8PathBuf::from_path_buf(t.join("MEREAD.md").canonicalize().unwrap()).ok()
1010+
Some(
1011+
t.join("MEREAD.md")
1012+
.canonicalize()
1013+
.unwrap()
1014+
.try_into_utf8()
1015+
.unwrap()
1016+
.into_string()
1017+
)
9561018
);
9571019
assert_eq!(
9581020
packages.get("t2").unwrap().manifest_metadata.readme,
959-
Utf8PathBuf::from_path_buf(t.child("t2").join("README.md").canonicalize().unwrap()).ok()
1021+
Some(
1022+
t.child("t2")
1023+
.join("README.md")
1024+
.canonicalize()
1025+
.unwrap()
1026+
.try_into_utf8()
1027+
.unwrap()
1028+
.into_string()
1029+
)
9601030
);
9611031
assert_eq!(
9621032
packages.get("t3").unwrap().manifest_metadata.readme,
963-
Utf8PathBuf::from_path_buf(t.child("t3").join("README.txt").canonicalize().unwrap()).ok()
1033+
Some(
1034+
t.child("t3")
1035+
.join("README.txt")
1036+
.canonicalize()
1037+
.unwrap()
1038+
.try_into_utf8()
1039+
.unwrap()
1040+
.into_string()
1041+
)
9641042
);
9651043
assert_eq!(
9661044
packages.get("t4").unwrap().manifest_metadata.readme,
967-
Utf8PathBuf::from_path_buf(t.child("t4").join("TEST.txt").canonicalize().unwrap()).ok()
1045+
Some(
1046+
t.child("t4")
1047+
.join("TEST.txt")
1048+
.canonicalize()
1049+
.unwrap()
1050+
.try_into_utf8()
1051+
.unwrap()
1052+
.into_string()
1053+
)
9681054
);
9691055
assert_eq!(packages.get("t5").unwrap().manifest_metadata.readme, None);
9701056
assert_eq!(packages.get("t6").unwrap().manifest_metadata.readme, None);

0 commit comments

Comments
 (0)