Skip to content

Commit

Permalink
Fix source path display on windows (#885)
Browse files Browse the repository at this point in the history
commit-id:18fc4713

---

**Stack**:
- #884
- #885⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do
not merge manually using the UI - doing so may have unexpected results.*
  • Loading branch information
maciektr committed Nov 8, 2023
1 parent 300918b commit 6f8cca7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions scarb/src/core/manifest/toml_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ impl TomlManifest {

if targets.is_empty() {
trace!("manifest has no targets, assuming default `lib` target");
let default_source_path = root.join(DEFAULT_SOURCE_PATH);
let default_source_path = root.join(DEFAULT_SOURCE_PATH.as_path());
let target =
Target::without_params(TargetKind::LIB, package_name.clone(), default_source_path);
targets.push(target);
Expand Down Expand Up @@ -675,14 +675,14 @@ impl TomlManifest {
default_name: &SmolStr,
root: &Utf8Path,
) -> Result<Option<Target>> {
let default_source_path = root.join(DEFAULT_SOURCE_PATH);
let default_source_path = root.join(DEFAULT_SOURCE_PATH.as_path());
let Some(target) = target else {
return Ok(None);
};

if let Some(source_path) = &target.source_path {
ensure!(
kind == TargetKind::TEST || source_path == DEFAULT_SOURCE_PATH,
kind == TargetKind::TEST || source_path == DEFAULT_SOURCE_PATH.as_path(),
"`{kind}` target cannot specify custom `source-path`"
);
}
Expand Down
6 changes: 5 additions & 1 deletion scarb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#![deny(rustdoc::private_intra_doc_links)]
#![warn(rust_2018_idioms)]

use camino::Utf8PathBuf;
use once_cell::sync::Lazy;
pub use subcommands::EXTERNAL_CMD_PREFIX;

pub mod compiler;
Expand All @@ -26,8 +28,10 @@ pub const SCARB_ENV: &str = "SCARB";
pub const MANIFEST_FILE_NAME: &str = "Scarb.toml";
pub const VCS_INFO_FILE_NAME: &str = "VCS.json";
pub const LOCK_FILE_NAME: &str = "Scarb.lock";
pub const DEFAULT_SOURCE_PATH: &str = "src/lib.cairo";
pub const DEFAULT_MODULE_MAIN_FILE: &str = "lib.cairo";
pub const DEFAULT_TESTS_PATH: &str = "tests";
pub const DEFAULT_TARGET_DIR_NAME: &str = "target";
pub const SCARB_IGNORE_FILE_NAME: &str = ".scarbignore";

pub static DEFAULT_SOURCE_PATH: Lazy<Utf8PathBuf> =
Lazy::new(|| ["src", "lib.cairo"].iter().collect());
2 changes: 1 addition & 1 deletion scarb/src/ops/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn mk(
)?;

// Create hello world source files (with respective parent directories) if none exist.
let source_path = canonical_path.join(DEFAULT_SOURCE_PATH);
let source_path = canonical_path.join(DEFAULT_SOURCE_PATH.as_path());
if !source_path.exists() {
fsx::create_dir_all(source_path.parent().unwrap())?;

Expand Down
2 changes: 1 addition & 1 deletion scarb/src/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn generate_cairo_compilation_units(
Target::without_params(
TargetKind::LIB,
member.id.name.clone(),
member.root().join(DEFAULT_SOURCE_PATH),
member.root().join(DEFAULT_SOURCE_PATH.as_path()),
)
});

Expand Down

0 comments on commit 6f8cca7

Please sign in to comment.