Skip to content

Commit

Permalink
add filemap to compiled package (#20682)
Browse files Browse the repository at this point in the history
## Description 

Describe the changes or additions included in this PR.

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
jordanjennings-mysten authored Dec 19, 2024
1 parent 5e3709d commit f92d5a9
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use move_binary_format::file_format::CompiledModule;
use move_bytecode_source_map::utils::{serialize_to_json, source_map_from_file};
use move_bytecode_utils::Modules;
use move_command_line_common::files::{
extension_equals, find_filenames, try_exists, MOVE_COMPILED_EXTENSION, MOVE_EXTENSION,
SOURCE_MAP_EXTENSION,
extension_equals, find_filenames, try_exists, FileHash, MOVE_COMPILED_EXTENSION,
MOVE_EXTENSION, SOURCE_MAP_EXTENSION,
};
use move_compiler::{
compiled_unit::{AnnotatedCompiledUnit, CompiledUnit, NamedCompiledModule},
Expand All @@ -33,6 +33,7 @@ use move_docgen::{Docgen, DocgenOptions};
use move_model::{model::GlobalEnv, options::ModelBuilderOptions, run_model_builder_with_options};
use move_symbol_pool::Symbol;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use std::{
collections::{BTreeMap, BTreeSet},
io::Write,
Expand Down Expand Up @@ -84,6 +85,8 @@ pub struct CompiledPackage {
//
/// filename -> doctext
pub compiled_docs: Option<Vec<(String, String)>>,
/// The mapping of file hashes to file names and contents
pub file_map: MappedFiles,
}

/// Represents a compiled package that has been saved to disk. This holds only the minimal metadata
Expand Down Expand Up @@ -159,6 +162,8 @@ impl OnDiskCompiledPackage {

pub fn into_compiled_package(&self) -> Result<CompiledPackage> {
let root_name = self.package.compiled_package_info.package_name;
let mut file_map = MappedFiles::empty();

assert!(self.root_path.ends_with(root_name.as_str()));
let root_compiled_units = self.get_compiled_units_paths(root_name)?;
let root_compiled_units = root_compiled_units
Expand All @@ -173,6 +178,18 @@ impl OnDiskCompiledPackage {
}
}

for unit in root_compiled_units
.iter()
.chain(deps_compiled_units.iter().map(|(_, unit)| unit))
{
let contents = Arc::from(std::fs::read_to_string(&unit.source_path)?);
file_map.add(
FileHash::new(&contents),
FileName::from(unit.source_path.to_string_lossy().to_string()),
contents,
);
}

let docs_path = self
.root_path
.join(self.package.compiled_package_info.package_name.as_str())
Expand All @@ -198,6 +215,7 @@ impl OnDiskCompiledPackage {
root_compiled_units,
deps_compiled_units,
compiled_docs,
file_map,
})
}

Expand Down Expand Up @@ -607,6 +625,7 @@ impl CompiledPackage {
root_compiled_units,
deps_compiled_units,
compiled_docs,
file_map,
};

compiled_package.save_to_disk(project_root.join(CompiledPackageLayout::Root.path()))?;
Expand Down

0 comments on commit f92d5a9

Please sign in to comment.