Skip to content

Commit

Permalink
Revert accidental breaking change introduced in #655
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaput committed Sep 20, 2023
1 parent 0de448b commit 6e3e28c
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 17 deletions.
2 changes: 1 addition & 1 deletion scarb-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ pub struct ManifestMetadata {
pub license_file: Option<String>,
/// A path to a file in the package root (relative to its `Scarb.toml`) that contains general
/// information about the package.
pub readme: Option<Utf8PathBuf>,
pub readme: Option<String>,
/// A URL to the source repository for this package.
pub repository: Option<String>,
/// A map of additional internet links related to this package.
Expand Down
9 changes: 8 additions & 1 deletion scarb/src/ops/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ fn collect_package_metadata(package: &Package) -> m::PackageMetadata {
.keywords(package.manifest.metadata.keywords.clone())
.license(package.manifest.metadata.license.clone())
.license_file(package.manifest.metadata.license_file.clone())
.readme(package.manifest.metadata.readme.clone())
.readme(
package
.manifest
.metadata
.readme
.as_ref()
.map(ToString::to_string),
)
.repository(package.manifest.metadata.repository.clone())
.urls(package.manifest.metadata.urls.clone())
.tool(
Expand Down
116 changes: 101 additions & 15 deletions scarb/tests/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use std::collections::BTreeMap;

use assert_fs::prelude::*;
use camino::Utf8PathBuf;
use indoc::indoc;
use serde_json::json;

use scarb_metadata::{Cfg, ManifestMetadataBuilder, Metadata, PackageMetadata};
use scarb_test_support::command::{CommandExt, Scarb};
use scarb_test_support::fsx::PathBufUtf8Ext;
use scarb_test_support::project_builder::ProjectBuilder;
use scarb_test_support::workspace_builder::WorkspaceBuilder;
use serde_json::json;

fn packages_by_name(meta: Metadata) -> BTreeMap<String, PackageMetadata> {
meta.packages
Expand Down Expand Up @@ -285,7 +284,14 @@ fn manifest_targets_and_metadata() {
]))
.license(Some("MIT License".to_string()))
.license_file(Some("./license.md".to_string()))
.readme(Utf8PathBuf::from_path_buf(t.join("README.md").canonicalize().unwrap()).ok())
.readme(
t.join("README.md")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
.repository(Some("https://github.com/johndoe/repo".to_string()))
.tool(Some(BTreeMap::from_iter([
("meta".to_string(), json!("data")),
Expand Down Expand Up @@ -610,7 +616,14 @@ fn infer_readme_simple() {
.unwrap()
.manifest_metadata
.readme,
Utf8PathBuf::from_path_buf(t.join("README").canonicalize().unwrap()).ok()
Some(
t.join("README")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);

t.child("README.txt").touch().unwrap();
Expand All @@ -629,7 +642,14 @@ fn infer_readme_simple() {
.unwrap()
.manifest_metadata
.readme,
Utf8PathBuf::from_path_buf(t.join("README.txt").canonicalize().unwrap()).ok()
Some(
t.join("README.txt")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);

t.child("README.md").touch().unwrap();
Expand All @@ -648,7 +668,14 @@ fn infer_readme_simple() {
.unwrap()
.manifest_metadata
.readme,
Utf8PathBuf::from_path_buf(t.join("README.md").canonicalize().unwrap()).ok()
Some(
t.join("README.md")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);

t.child("Scarb.toml")
Expand Down Expand Up @@ -683,7 +710,14 @@ fn infer_readme_simple() {
.unwrap()
.manifest_metadata
.readme,
Utf8PathBuf::from_path_buf(t.join("a/b/c/MEREAD.md").canonicalize().unwrap()).ok()
Some(
t.join("a/b/c/MEREAD.md")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);
}

Expand Down Expand Up @@ -762,7 +796,14 @@ fn infer_readme_simple_bool() {
.unwrap()
.manifest_metadata
.readme,
Utf8PathBuf::from_path_buf(t.join("README.md").canonicalize().unwrap()).ok()
Some(
t.join("README.md")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);
}

Expand Down Expand Up @@ -944,27 +985,72 @@ fn infer_readme_workspace() {
let packages = packages_by_name(meta);
assert_eq!(
packages.get("hello").unwrap().manifest_metadata.readme,
Utf8PathBuf::from_path_buf(t.join("MEREAD.md").canonicalize().unwrap()).ok()
Some(
t.join("MEREAD.md")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);
assert_eq!(
packages.get("t7").unwrap().manifest_metadata.readme,
Utf8PathBuf::from_path_buf(t.join("MEREAD.md").canonicalize().unwrap()).ok()
Some(
t.join("MEREAD.md")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);
assert_eq!(
packages.get("t1").unwrap().manifest_metadata.readme,
Utf8PathBuf::from_path_buf(t.join("MEREAD.md").canonicalize().unwrap()).ok()
Some(
t.join("MEREAD.md")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);
assert_eq!(
packages.get("t2").unwrap().manifest_metadata.readme,
Utf8PathBuf::from_path_buf(t.child("t2").join("README.md").canonicalize().unwrap()).ok()
Some(
t.child("t2")
.join("README.md")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);
assert_eq!(
packages.get("t3").unwrap().manifest_metadata.readme,
Utf8PathBuf::from_path_buf(t.child("t3").join("README.txt").canonicalize().unwrap()).ok()
Some(
t.child("t3")
.join("README.txt")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);
assert_eq!(
packages.get("t4").unwrap().manifest_metadata.readme,
Utf8PathBuf::from_path_buf(t.child("t4").join("TEST.txt").canonicalize().unwrap()).ok()
Some(
t.child("t4")
.join("TEST.txt")
.canonicalize()
.unwrap()
.try_into_utf8()
.unwrap()
.into_string()
)
);
assert_eq!(packages.get("t5").unwrap().manifest_metadata.readme, None);
assert_eq!(packages.get("t6").unwrap().manifest_metadata.readme, None);
Expand Down

0 comments on commit 6e3e28c

Please sign in to comment.