pub fn run_model_builder_with_options_and_compilation_flags<
    Paths: Into<MoveSymbol>,
    NamedAddress: Into<MoveSymbol>,
>(
    move_sources: Vec<AddressScopedFiles<Paths, NamedAddress>>,
    deps: Vec<AddressScopedFiles<Paths, NamedAddress>>,
    options: ModelBuilderOptions,
    flags: Flags,
) -> anyhow::Result<GlobalEnv> {
    let mut env = GlobalEnv::new();
    env.set_extension(options);

    // Step 1: parse the program to get comments and a separation of targets and dependencies.
    let (files, comments_and_compiler_res) = Compiler::new(move_sources, deps)
        .set_flags(flags)
        .run::<PASS_PARSER>()?;
    let (comment_map, compiler) = match comments_and_compiler_res {
        Err(diags) => {
            // Add source files so that the env knows how to translate locations of parse errors
            for (fhash, (fname, fsrc)) in &files {
                env.add_source(*fhash, fname.as_str(), fsrc, /* is_dep */ false);
            }
            add_move_lang_diagnostics(&mut env, diags);
            return Ok(env);
        }
        Ok(res) => res,
    };
    let (compiler, parsed_prog) = compiler.into_ast();
    // Add source files for targets and dependencies
    let dep_files: BTreeSet<_> = parsed_prog
        .lib_definitions
        .iter()
        .map(|(_, def)| def.file_hash())
        .collect();
    for fhash in files.keys().sorted() {
        let (fname, fsrc) = files.get(fhash).unwrap();
        env.add_source(*fhash, fname.as_str(), fsrc, dep_files.contains(fhash));
    }

    // Add any documentation comments found by the Move compiler to the env.
    for (fhash, documentation) in comment_map {
        let file_id = env.get_file_id(fhash).expect("file name defined");
        env.add_documentation(
            file_id,
            documentation
                .into_iter()
                .map(|(idx, s)| (ByteIndex(idx), s))
                .collect(),
        )
    }

    // Step 2: run the compiler up to expansion
    let parsed_prog = {
        let P::Program {
            named_address_maps,
            mut source_definitions,
            lib_definitions,
        } = parsed_prog;
        source_definitions.extend(lib_definitions);
        P::Program {
            named_address_maps,
            source_definitions,
            lib_definitions: vec![],
        }
    };
    let (compiler, expansion_ast) = match compiler.at_parser(parsed_prog).run::<PASS_EXPANSION>() {
        Err(diags) => {
            add_move_lang_diagnostics(&mut env, diags);
            return Ok(env);
        }
        Ok(compiler) => compiler.into_ast(),
    };
    // Extract the module/script closure
    let mut visited_modules = BTreeSet::new();
    for (_, mident, mdef) in &expansion_ast.modules {
        let src_file_hash = mdef.loc.file_hash();
        if !dep_files.contains(&src_file_hash) {
            collect_related_modules_recursive(mident, &expansion_ast.modules, &mut visited_modules);
        }
    }
    for sdef in expansion_ast.scripts.values() {
        let src_file_hash = sdef.loc.file_hash();
        if !dep_files.contains(&src_file_hash) {
            for (_, mident, _neighbor) in &sdef.immediate_neighbors {
                collect_related_modules_recursive(
                    mident,
                    &expansion_ast.modules,
                    &mut visited_modules,
                );
            }
        }
    }

    // Step 3: selective compilation.
    let expansion_ast = {
        let E::Program { modules, scripts } = expansion_ast;
        let modules = modules.filter_map(|mident, mut mdef| {
            visited_modules.contains(&mident.value).then(|| {
                mdef.is_source_module = true;
                mdef
            })
        });
        E::Program { modules, scripts }
    };
    // Run the compiler fully to the compiled units
    let units = match compiler
        .at_expansion(expansion_ast.clone())
        .run::<PASS_COMPILATION>()
    {
        Err(diags) => {
            add_move_lang_diagnostics(&mut env, diags);
            return Ok(env);
        }
        Ok(compiler) => {
            let (units, warnings) = compiler.into_compiled_units();
            if !warnings.is_empty() {
                // NOTE: these diagnostics are just warnings. it should be feasible to continue the
                // model building here. But before that, register the warnings to the `GlobalEnv`
                // first so we get a chance to report these warnings as well.
                add_move_lang_diagnostics(&mut env, warnings);
            }
            units
        }
    };
    // Check for bytecode verifier errors (there should not be any)
    let diags = compiled_unit::verify_units(&units);
    if !diags.is_empty() {
        add_move_lang_diagnostics(&mut env, diags);
        return Ok(env);
    }

    // Now that it is known that the program has no errors, run the spec checker on verified units
    // plus expanded AST. This will populate the environment including any errors.
    run_spec_checker(&mut env, units, expansion_ast);
    Ok(env)
}
/// Build the move model with custom compilation flags and custom options
/// This collects transitive dependencies for move sources from the provided directory list.
Build the move model with custom compilation flags and custom options
This collects transitive dependencies for move sources from the provided directory list.
Build the move model with custom compilation flags and custom options This collects transitive dependencies for move sources from the provided directory list .
pub fn run_model_builder_with_options_and_compilation_flags<
    Paths: Into<MoveSymbol>,
    NamedAddress: Into<MoveSymbol>,
>(
    move_sources: Vec<AddressScopedFiles<Paths, NamedAddress>>,
    deps: Vec<AddressScopedFiles<Paths, NamedAddress>>,
    options: ModelBuilderOptions,
    flags: Flags,
) -> anyhow::Result<GlobalEnv> {
    let mut env = GlobalEnv::new();
    env.set_extension(options);
    // Step 1: parse the program to get comments and a separation of targets and dependencies.
    let (files, comments_and_compiler_res) = Compiler::new(move_sources, deps)
        .set_flags(flags)
        .run::<PASS_PARSER>()?;
    let (comment_map, compiler) = match comments_and_compiler_res {
        Err(diags) => {
            // Add source files so that the env knows how to translate locations of parse errors
            for (fhash, (fname, fsrc)) in &files {
                env.add_source(*fhash, fname.as_str(), fsrc, /* is_dep */ false);
            }
            add_move_lang_diagnostics(&mut env, diags);
            return Ok(env);
        }
        Ok(res) => res,
    };
    let (compiler, parsed_prog) = compiler.into_ast();
    // Add source files for targets and dependencies
    let dep_files: BTreeSet<_> = parsed_prog
        .lib_definitions
        .iter()
        .map(|(_, def)| def.file_hash())
        .collect();
    for fhash in files.keys().sorted() {
        let (fname, fsrc) = files.get(fhash).unwrap();
        env.add_source(*fhash, fname.as_str(), fsrc, dep_files.contains(fhash));
    }
    // Add any documentation comments found by the Move compiler to the env.
    for (fhash, documentation) in comment_map {
        let file_id = env.get_file_id(fhash).expect("file name defined");
        env.add_documentation(
            file_id,
            documentation
                .into_iter()
                .map(|(idx, s)| (ByteIndex(idx), s))
                .collect(),
        )
    }
    // Step 2: run the compiler up to expansion
    let parsed_prog = {
        let P::Program {
            named_address_maps,
            mut source_definitions,
            lib_definitions,
        } = parsed_prog;
        source_definitions.extend(lib_definitions);
        P::Program {
            named_address_maps,
            source_definitions,
            lib_definitions: vec![],
        }
    };
    let (compiler, expansion_ast) = match compiler.at_parser(parsed_prog).run::<PASS_EXPANSION>() {
        Err(diags) => {
            add_move_lang_diagnostics(&mut env, diags);
            return Ok(env);
        }
        Ok(compiler) => compiler.into_ast(),
    };
    // Extract the module/script closure
    let mut visited_modules = BTreeSet::new();
    for (_, mident, mdef) in &expansion_ast.modules {
        let src_file_hash = mdef.loc.file_hash();
        if !dep_files.contains(&src_file_hash) {
            collect_related_modules_recursive(mident, &expansion_ast.modules, &mut visited_modules);
        }
    }
    for sdef in expansion_ast.scripts.values() {
        let src_file_hash = sdef.loc.file_hash();
        if !dep_files.contains(&src_file_hash) {
            for (_, mident, _neighbor) in &sdef.immediate_neighbors {
                collect_related_modules_recursive(
                    mident,
                    &expansion_ast.modules,
                    &mut visited_modules,
                );
            }
        }
    }
    // Step 3: selective compilation.
    let expansion_ast = {
        let E::Program { modules, scripts } = expansion_ast;
        let modules = modules.filter_map(|mident, mut mdef| {
            visited_modules.contains(&mident.value).then(|| {
                mdef.is_source_module = true;
                mdef
            })
        });
        E::Program { modules, scripts }
    };
    // Run the compiler fully to the compiled units
    let units = match compiler
        .at_expansion(expansion_ast.clone())
        .run::<PASS_COMPILATION>()
    {
        Err(diags) => {
            add_move_lang_diagnostics(&mut env, diags);
            return Ok(env);
        }
        Ok(compiler) => {
            let (units, warnings) = compiler.into_compiled_units();
            if !warnings.is_empty() {
                // NOTE: these diagnostics are just warnings. it should be feasible to continue the
                // model building here. But before that, register the warnings to the `GlobalEnv`
                // first so we get a chance to report these warnings as well.
                add_move_lang_diagnostics(&mut env, warnings);
            }
            units
        }
    };
    // Check for bytecode verifier errors (there should not be any)
    let diags = compiled_unit::verify_units(&units);
    if !diags.is_empty() {
        add_move_lang_diagnostics(&mut env, diags);
        return Ok(env);
    }
    // Now that it is known that the program has no errors, run the spec checker on verified units
    // plus expanded AST. This will populate the environment including any errors.
    run_spec_checker(&mut env, units, expansion_ast);
    Ok(env)
}
pub fn run_model_builder_with_options_and_compilation_flags < Paths : Into < MoveSymbol > , NamedAddress : Into < MoveSymbol > , > ( move_sources : Vec < AddressScopedFiles < Paths , NamedAddress > > , deps : Vec < AddressScopedFiles < Paths , NamedAddress > > , options : ModelBuilderOptions , flags : Flags , ) -> anyhow :: Result < GlobalEnv > { let mut env = GlobalEnv :: new ( ) ; env . set_extension ( options ) ; // Step 1: parse the program to get comments and a separation of targets and dependencies. let ( files , comments_and_compiler_res ) = Compiler :: new ( move_sources , deps ) . set_flags ( flags ) . run :: < PASS_PARSER > ( ) ? ; let ( comment_map , compiler ) = match comments_and_compiler_res { Err ( diags ) => { // Add source files so that the env knows how to translate locations of parse errors for ( fhash , ( fname , fsrc ) ) in & files { env . add_source ( * fhash , fname . as_str ( ) , fsrc , /* is_dep */ false ) ; } add_move_lang_diagnostics ( & mut env , diags ) ; return Ok ( env ) ; } Ok ( res ) => res , } ; let ( compiler , parsed_prog ) = compiler . into_ast ( ) ; // Add source files for targets and dependencies let dep_files : BTreeSet < _ > = parsed_prog . lib_definitions . iter ( ) . map ( | ( _ , def ) | def . file_hash ( ) ) . collect ( ) ; for fhash in files . keys ( ) . sorted ( ) { let ( fname , fsrc ) = files . get ( fhash ) . unwrap ( ) ; env . add_source ( * fhash , fname . as_str ( ) , fsrc , dep_files . contains ( fhash ) ) ; } // Add any documentation comments found by the Move compiler to the env. for ( fhash , documentation ) in comment_map { let file_id = env . get_file_id ( fhash ) . expect ( " " ) ; env . add_documentation ( file_id , documentation . into_iter ( ) . map ( | ( idx , s ) | ( ByteIndex ( idx ) , s ) ) . collect ( ) , ) } // Step 2: run the compiler up to expansion let parsed_prog = { let P :: Program { named_address_maps , mut source_definitions , lib_definitions , } = parsed_prog ; source_definitions . extend ( lib_definitions ) ; P :: Program { named_address_maps , source_definitions , lib_definitions : vec ! [ ] , } } ; let ( compiler , expansion_ast ) = match compiler . at_parser ( parsed_prog ) . run :: < PASS_EXPANSION > ( ) { Err ( diags ) => { add_move_lang_diagnostics ( & mut env , diags ) ; return Ok ( env ) ; } Ok ( compiler ) => compiler . into_ast ( ) , } ; // Extract the module/script closure let mut visited_modules = BTreeSet :: new ( ) ; for ( _ , mident , mdef ) in & expansion_ast . modules { let src_file_hash = mdef . loc . file_hash ( ) ; if ! dep_files . contains ( & src_file_hash ) { collect_related_modules_recursive ( mident , & expansion_ast . modules , & mut visited_modules ) ; } } for sdef in expansion_ast . scripts . values ( ) { let src_file_hash = sdef . loc . file_hash ( ) ; if ! dep_files . contains ( & src_file_hash ) { for ( _ , mident , _neighbor ) in & sdef . immediate_neighbors { collect_related_modules_recursive ( mident , & expansion_ast . modules , & mut visited_modules , ) ; } } } // Step 3: selective compilation. let expansion_ast = { let E :: Program { modules , scripts } = expansion_ast ; let modules = modules . filter_map ( | mident , mut mdef | { visited_modules . contains ( & mident . value ) . then ( | | { mdef . is_source_module = true ; mdef } ) } ) ; E :: Program { modules , scripts } } ; // Run the compiler fully to the compiled units let units = match compiler . at_expansion ( expansion_ast . clone ( ) ) . run :: < PASS_COMPILATION > ( ) { Err ( diags ) => { add_move_lang_diagnostics ( & mut env , diags ) ; return Ok ( env ) ; } Ok ( compiler ) => { let ( units , warnings ) = compiler . into_compiled_units ( ) ; if ! warnings . is_empty ( ) { // NOTE: these diagnostics are just warnings. it should be feasible to continue the // model building here. But before that, register the warnings to the `GlobalEnv` // first so we get a chance to report these warnings as well. add_move_lang_diagnostics ( & mut env , warnings ) ; } units } } ; // Check for bytecode verifier errors (there should not be any) let diags = compiled_unit :: verify_units ( & units ) ; if ! diags . is_empty ( ) { add_move_lang_diagnostics ( & mut env , diags ) ; return Ok ( env ) ; } // Now that it is known that the program has no errors, run the spec checker on verified units // plus expanded AST. This will populate the environment including any errors. run_spec_checker ( & mut env , units , expansion_ast ) ; Ok ( env ) }
Build the move model with custom compilation flags and custom options
This collects transitive dependencies for move sources from the provided directory list.
Build the move model with custom compilation flags and custom options This collects transitive dependencies for move sources from the provided directory list .
move_sources
Vec<AddressScopedFiles<Paths, NamedAddress>>
deps
Vec<AddressScopedFiles<Paths, NamedAddress>>
options
ModelBuilderOptions
flags
Flags