Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ce2f888
Remove `extra` field from config
adamspofford-dfinity Jun 20, 2022
aec799d
Restore default type:motoko behavior
adamspofford-dfinity Jun 20, 2022
f2f5533
does that work?
adamspofford-dfinity Jun 21, 2022
261dadd
fix basic-project e2e
viviveevee Jul 5, 2022
21e1f80
Merge branch 'master' into spofford/full-serde
viviveevee Jul 5, 2022
f358155
`main` is Motoko-specific
adamspofford-dfinity Jul 5, 2022
47d89d4
Work around serde-rs/serde#2231
adamspofford-dfinity Jul 5, 2022
fdbb0a6
Merge branch 'spofford/full-serde' of https://github.com/dfinity/sdk …
adamspofford-dfinity Jul 5, 2022
b836726
forgot to delete that
adamspofford-dfinity Jul 5, 2022
cafcf51
this is never read, but it sure is written
adamspofford-dfinity Jul 5, 2022
d09b1ad
Revert "`main` is Motoko-specific"
adamspofford-dfinity Jul 5, 2022
3d663ca
required fields
adamspofford-dfinity Jul 5, 2022
fc1d1be
Update error_context asset
adamspofford-dfinity Jul 5, 2022
8d5dc2b
shellcheck
adamspofford-dfinity Jul 5, 2022
38a74e2
paths are not strings
adamspofford-dfinity Jul 5, 2022
a002cec
Update build.bash
adamspofford-dfinity Jul 5, 2022
086774e
Update build.bash
adamspofford-dfinity Jul 5, 2022
6544b91
shellcheck
adamspofford-dfinity Jul 5, 2022
2ae9f59
Merge branch 'master' into spofford/full-serde
viviveevee Jul 6, 2022
dd0d901
Merge branch 'master' into spofford/full-serde
adamspofford-dfinity Jul 6, 2022
7e12a6d
Merge branch 'master' into spofford/full-serde
adamspofford-dfinity Jul 8, 2022
29630a5
Merge branch 'master' into spofford/full-serde
viviveevee Jul 11, 2022
c8c824b
fix Cargo.lock
viviveevee Jul 11, 2022
ab43a02
valid canister type makes dfx stop work
viviveevee Jul 12, 2022
df038c3
Merge branch 'master' into spofford/full-serde
viviveevee Jul 12, 2022
6942118
fix dfx config test bc field candid is now required for rust canisters
viviveevee Jul 12, 2022
710af37
rm debug print
viviveevee Jul 12, 2022
c13dcd7
fix copy/paste mistake
viviveevee Jul 12, 2022
bb701c1
Merge branch 'master' into spofford/full-serde
mergify[bot] Jul 12, 2022
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
36 changes: 29 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion e2e/assets/error_context/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"main": "main.mo"
},
"npm_missing": {
"type": "assets"
"type": "assets",
"source": []
},
"asset_bad_source_path": {
"type": "assets",
Expand Down
10 changes: 8 additions & 2 deletions e2e/tests-dfx/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,16 @@ teardown() {

@test "build fails if canister type is not supported" {
dfx_start
dfx config canisters.e2e_project_backend.type unknown_canister_type
dfx canister create --all
# shellcheck disable=SC2094
cat <<<"$(jq '.canisters.e2e_project.type="unknown_canister_type"' dfx.json)" >dfx.json
assert_command_fail dfx build
assert_match "Cannot find builder for canister"
# shellcheck disable=SC2016
assert_match 'unknown variant `unknown_canister_type`'

# If canister type is invalid, `dfx stop` fails
# shellcheck disable=SC2094
cat <<<"$(jq '.canisters.e2e_project.type="motoko"' dfx.json)" >dfx.json
}

@test "can build a custom canister type" {
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests-dfx/config.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load ../utils/_
setup() {
standard_setup

dfx_new
dfx_new_rust
}

teardown() {
Expand All @@ -18,15 +18,15 @@ teardown() {

assert_command dfx config canisters.e2e_project_backend.type
# shellcheck disable=SC2154
assert_eq '"motoko"' "$stdout"
assert_eq '"rust"' "$stdout"

assert_command dfx config canisters.e2e_project_backend.type "rust"
assert_command dfx config canisters.e2e_project_backend.type "motoko"
# shellcheck disable=SC2154
assert_eq "" "$stdout"

assert_command dfx config canisters.e2e_project_backend.type
# shellcheck disable=SC2154
assert_eq '"rust"' "$stdout"
assert_eq '"motoko"' "$stdout"

assert_command_fail dfx config non_existent

Expand Down
4 changes: 3 additions & 1 deletion src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ anyhow = "1.0.56"
argon2 = "0.4.0"
atty = "0.2.13"
base64 = "0.13.0"
byte-unit = { version = "4.0.14", features = ["serde"] }
candid = { version = "0.7.10", features = [ "random" ] }
clap = { version = "3.1.6", features = [ "derive" ] }
console = "0.15.0"
Expand All @@ -41,14 +42,15 @@ fn-error-context = "0.2.0"
futures = "0.3.21"
garcon = { version = "0.2", features = ["async"] }
hex = {version = "0.4.2", features = ["serde"] }
humantime = "2.1.0"
humantime-serde = "1.1.1"
ic-types = "0.3.0"
ic-wasm = { version = "0.1.3", default-features = false, features = ["optimize"]}
indicatif = "0.16.0"
itertools = "0.10.3"
lazy-init = "0.5.0"
lazy_static = "1.4.0"
libflate = "1.1.2"
humanize-rs = "0.1.5"
mime = "0.3.16"
mime_guess = "2.0.4"
mockall = "0.11.0"
Expand Down
3 changes: 1 addition & 2 deletions src/dfx/src/commands/canister/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use ic_types::principal::Principal;

use anyhow::{anyhow, bail, Context};
use clap::Parser;
use humanize_rs::duration;
use slog::info;
use time::OffsetDateTime;

Expand Down Expand Up @@ -130,7 +129,7 @@ pub async fn exec(
.get_selected_identity_principal()
.expect("Selected identity not instantiated.");

let timeout = duration::parse(&opts.expire_after)
let timeout = humantime::parse_duration(&opts.expire_after)
.map_err(|_| anyhow!("Cannot parse expire_after as a duration (e.g. `1h`, `1h 30m`)"))?;
//let timeout = Duration::from_secs(opts.expire_after);
let expiration_system_time = SystemTime::now()
Expand Down
5 changes: 2 additions & 3 deletions src/dfx/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,13 @@ fn display_urls(env: &dyn Environment) -> DfxResult {
};
if let Some(canister_id) = canister_id {
let canister_info = CanisterInfo::load(&config, canister_name, Some(canister_id))?;
let is_frontend = canister_config.extras.get("frontend").is_some();

if is_frontend {
if canister_config.frontend.is_some() {
let url = construct_frontend_url(network, &canister_id)?;
frontend_urls.insert(canister_name, url);
}

if canister_info.get_type() != "assets" {
if !canister_info.is_assets() {
let url = construct_ui_canister_url(network, &canister_id, ui_canister_id)?;
if let Some(ui_canister_url) = url {
candid_urls.insert(canister_name, ui_canister_url);
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn exec(env: &dyn Environment, opts: GenerateOpts) -> DfxResult {
let canister_name = canister.get_name();
let canister_id = store.get(canister_name)?;
if let Some(info) = canister_pool.get_canister_info(&canister_id) {
if info.get_type() == "motoko" {
if info.is_motoko() {
build_before_generate = true;
}
}
Expand Down
27 changes: 12 additions & 15 deletions src/dfx/src/commands/language_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::lib::package_arguments::{self, PackageArguments};
use anyhow::{anyhow, bail, Context};
use clap::Parser;
use fn_error_context::context;
use std::path::PathBuf;
use std::process::Stdio;

const CANISTER_ARG: &str = "canister";
Expand Down Expand Up @@ -47,7 +48,7 @@ pub fn exec(env: &dyn Environment, opts: LanguageServiceOpts) -> DfxResult {
}

#[context("Failed to determine main path.")]
fn get_main_path(config: &ConfigInterface, canister_name: Option<String>) -> DfxResult<String> {
fn get_main_path(config: &ConfigInterface, canister_name: Option<String>) -> DfxResult<PathBuf> {
// TODO try and point at the actual dfx.json path
let dfx_json = CONFIG_FILE_NAME;

Expand Down Expand Up @@ -80,24 +81,20 @@ fn get_main_path(config: &ConfigInterface, canister_name: Option<String>) -> Dfx
}
}
}?;

canister
.extras
.get("main")
.and_then(|v| v.as_str())
.ok_or_else(|| {
error_invalid_data!(
"Canister {0} lacks a 'main' element in {1}",
canister_name,
dfx_json
)
})
.map(|s| s.to_owned())
if let Some(main) = canister.main {
Ok(main)
} else {
Err(error_invalid_data!(
"Canister {0} lacks a 'main' element in {1}",
canister_name,
dfx_json
))
}
}

fn run_ide(
env: &dyn Environment,
main_path: String,
main_path: PathBuf,
package_arguments: PackageArguments,
) -> DfxResult {
let output = env
Expand Down
37 changes: 16 additions & 21 deletions src/dfx/src/commands/remote/generate_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::util::check_candid_file;
use anyhow::Context;
use clap::Parser;
use slog::info;
use std::path::Path;

/// Generate bindings for remote canisters from their .did declarations
#[derive(Parser)]
Expand Down Expand Up @@ -43,11 +42,9 @@ pub fn exec(env: &dyn Environment, opts: GenerateBindingOpts) -> DfxResult {
for canister in canister_pool.get_canister_list() {
let info = canister.get_info();
if let Some(candid) = info.get_remote_candid() {
let main_optional: Option<String> = info.get_extra_optional("main")?;
let main_optional = info.get_main_file();
if let Some(main) = main_optional {
let main_path = Path::new(&main);
let candid_path = Path::new(&candid);
if !candid_path.exists() {
if !candid.exists() {
info!(
log,
"Candid file {} for canister {} does not exist. Skipping.",
Expand All @@ -56,55 +53,53 @@ pub fn exec(env: &dyn Environment, opts: GenerateBindingOpts) -> DfxResult {
);
continue;
}
if main_path.exists() {
if main.exists() {
if opts.overwrite {
info!(
log,
"Overwriting main file {} of canister {}.",
main,
main.display(),
canister.get_name()
);
} else {
info!(
log,
"Main file {} of canister {} already exists. Skipping. Use --overwrite if you want to re-create it.",
main,
main.display(),
canister.get_name()
);
continue;
}
}
let (type_env, did_types) = check_candid_file(candid_path)?;
let bindings = if main.ends_with(&".mo") {
let (type_env, did_types) = check_candid_file(&candid)?;
let extension = main.extension().unwrap_or_default();
let bindings = if extension == "mo" {
Some(candid::bindings::motoko::compile(&type_env, &did_types))
} else if main.ends_with(&".rs") {
} else if extension == "rs" {
Some(candid::bindings::rust::compile(&type_env, &did_types))
} else if main.ends_with(&".js") {
} else if extension == "js" {
Some(candid::bindings::javascript::compile(&type_env, &did_types))
} else if main.ends_with(&".ts") {
} else if extension == "ts" {
Some(candid::bindings::typescript::compile(&type_env, &did_types))
} else {
info!(
log,
"Unsupported filetype found in {}.main: {}. Use one of the following: .mo, .rs, .js, .ts",
canister.get_name(),
main
main.display()
);
None
};

if let Some(bindings_string) = bindings {
std::fs::write(&main_path, &bindings_string).with_context(|| {
format!(
"Failed to write bindings to {}.",
main_path.to_string_lossy()
)
std::fs::write(&main, &bindings_string).with_context(|| {
format!("Failed to write bindings to {}.", main.display())
})?;
info!(
log,
"Generated {} using {} for canister {}.",
main,
candid.to_string_lossy(),
main.display(),
candid.display(),
canister.get_name()
)
}
Expand Down
Loading