1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub mod compilation;
pub mod resolution;
pub mod source_package;
use anyhow::Result;
use move_model::model::GlobalEnv;
use serde::{Deserialize, Serialize};
use std::{io::Write, path::Path};
use structopt::*;
use crate::{
compilation::{
build_plan::BuildPlan, compiled_package::CompiledPackage, model_builder::ModelBuilder,
},
resolution::resolution_graph::{ResolutionGraph, ResolvedGraph},
source_package::{layout, manifest_parser},
};
#[derive(Debug, StructOpt, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd)]
#[structopt(
name = "Move Package",
about = "Package and build system for Move code."
)]
pub struct BuildConfig {
#[structopt(name = "dev-mode", short = "d", long = "dev")]
pub dev_mode: bool,
#[structopt(name = "test-mode", short = "t", long = "test")]
pub test_mode: bool,
#[structopt(name = "generate-docs", long = "doc")]
pub generate_docs: bool,
#[structopt(name = "generate-abis", long = "abi")]
pub generate_abis: bool,
}
impl BuildConfig {
pub fn compile_package<W: Write>(self, path: &Path, writer: &mut W) -> Result<CompiledPackage> {
let resolved_graph = self.resolution_graph_for_package(path)?;
BuildPlan::create(resolved_graph)?.compile(writer)
}
pub fn move_model_for_package(self, path: &Path) -> Result<GlobalEnv> {
let resolved_graph = self.resolution_graph_for_package(path)?;
ModelBuilder::create(resolved_graph).build_model()
}
pub fn resolution_graph_for_package(mut self, path: &Path) -> Result<ResolvedGraph> {
if self.test_mode {
self.dev_mode = true;
}
let manifest_string =
std::fs::read_to_string(path.join(layout::SourcePackageLayout::Manifest.path()))?;
let toml_manifest = manifest_parser::parse_move_manifest_string(manifest_string)?;
let manifest = manifest_parser::parse_source_manifest(toml_manifest)?;
let resolution_graph = ResolutionGraph::new(manifest, path.to_path_buf(), self)?;
resolution_graph.resolve()
}
}