Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build to .gitignore in sui move new #20395

Merged
merged 20 commits into from
Nov 26, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions external-crates/move/crates/move-cli/src/base/new.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

use anyhow::anyhow;
use anyhow::{self, bail};
use clap::*;
use move_core_types::identifier::Identifier;
use move_package::source_package::layout::SourcePackageLayout;
use std::{fmt::Display, fs::create_dir_all, io::Write, path::Path};

// TODO get a stable path to this stdlib
// pub const MOVE_STDLIB_PACKAGE_NAME: &str = "MoveStdlib";
// pub const MOVE_STDLIB_PACKAGE_PATH: &str = "{ \
// git = \"https://github.com/move-language/move.git\", \
// subdir = \"language/move-stdlib\", rev = \"main\" \
// }";
mdgeorge4153 marked this conversation as resolved.
Show resolved Hide resolved
pub const MOVE_STDLIB_ADDR_NAME: &str = "std";
pub const MOVE_STDLIB_ADDR_VALUE: &str = "0x1";

Expand Down Expand Up @@ -43,17 +37,43 @@ impl New {
custom: &str, // anything else that needs to end up being in Move.toml (or empty string)
) -> anyhow::Result<()> {
// TODO warn on build config flags
let Self { name } = self;

if !Identifier::is_valid(&name) {
return Err(anyhow!(
if !Identifier::is_valid(&self.name) {
bail!(
mdgeorge4153 marked this conversation as resolved.
Show resolved Hide resolved
"Invalid package name. Package name must start with a lowercase letter \
and consist only of lowercase letters, numbers, and underscores."
));
);
}

let path = path.unwrap_or_else(|| Path::new(&name));
let path = path.unwrap_or_else(|| Path::new(&self.name));
create_dir_all(path.join(SourcePackageLayout::Sources.path()))?;

self.write_move_toml(path, deps, addrs, custom)?;
self.write_gitignore(path)?;
Ok(())
}

/// add `build/*` to `{path}/.gitignore`
fn write_gitignore(&self, path: &Path) -> anyhow::Result<()> {
mdgeorge4153 marked this conversation as resolved.
Show resolved Hide resolved
let mut w = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(path.join(".gitignore"))?;
mdgeorge4153 marked this conversation as resolved.
Show resolved Hide resolved

writeln!(w, "build/*")?;
mdgeorge4153 marked this conversation as resolved.
Show resolved Hide resolved
Ok(())
}

/// create default `Move.toml`
fn write_move_toml(
&self,
path: &Path,
deps: impl IntoIterator<Item = (impl Display, impl Display)>,
addrs: impl IntoIterator<Item = (impl Display, impl Display)>,
custom: &str, // anything else that needs to end up being in Move.toml (or empty string)
) -> anyhow::Result<()> {
let Self { name } = self;

let mut w = std::fs::File::create(path.join(SourcePackageLayout::Manifest.path()))?;
writeln!(
w,
Expand All @@ -63,7 +83,7 @@ edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
# license = "" # e.g., "MIT", "GPL", "Apache 2.0"
# authors = ["..."] # e.g., ["Joe Smith ([email protected])", "John Snow ([email protected])"]

[dependencies]"#
[dependencies]"#,
mdgeorge4153 marked this conversation as resolved.
Show resolved Hide resolved
)?;
for (dep_name, dep_val) in deps {
writeln!(w, "{dep_name} = {dep_val}")?;
Expand Down
Loading