Skip to content

Commit 58a0f92

Browse files
committed
workspace
1 parent 690764f commit 58a0f92

1 file changed

Lines changed: 40 additions & 27 deletions

File tree

cargo-concordium/src/build.rs

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ const ENCODER: base64::engine::GeneralPurpose = general_purpose::STANDARD;
5353
///
5454
/// Used for converting crate names, which often contain `-`, to module names,
5555
/// which cannot have `-`.
56-
fn to_snake_case(string: &str) -> String { string.replace('-', "_") }
56+
fn to_snake_case(string: &str) -> String {
57+
string.replace('-', "_")
58+
}
5759

5860
/// Get the crate's metadata either by looking for the `Cargo.toml` file at the
5961
/// `--manifest-path` or at the ancestors of the current directory.
@@ -114,32 +116,34 @@ impl SchemaBuildOptions {
114116
}
115117

116118
/// Return whether the schema should be embedded.
117-
pub fn embed(self) -> bool { matches!(self, SchemaBuildOptions::BuildAndEmbed) }
119+
pub fn embed(self) -> bool {
120+
matches!(self, SchemaBuildOptions::BuildAndEmbed)
121+
}
118122
}
119123

120124
/// Build information returned by the [`build_contract`] function.
121125
pub struct BuildInfo {
122126
/// Size of the module that was built, including custom section.
123-
pub total_module_len: usize,
127+
pub total_module_len: usize,
124128
/// The schema, if any was built.
125-
pub schema: Option<schema::VersionedModuleSchema>,
129+
pub schema: Option<schema::VersionedModuleSchema>,
126130
/// The metadata used for building the contract (the actual code, not the
127131
/// schema).
128-
pub metadata: cargo_metadata::Metadata,
132+
pub metadata: cargo_metadata::Metadata,
129133
/// If a reproducible/verifiable build is requested, this contains the build
130134
/// information that should be embedded in the module, together with a
131135
/// list of file paths that were used to build the artifact. The file
132136
/// paths are relative to the package root.
133137
pub stored_build_info: Option<(utils::VersionedBuildInfo, Vec<PathBuf>)>,
134138
/// The path to the file of the built module.
135-
pub out_filename: PathBuf,
139+
pub out_filename: PathBuf,
136140
}
137141

138142
/// Result of [`create_archive`]. It contains the actual archive with a
139143
/// list of files that were included.
140144
pub struct TarArchiveData {
141145
/// The archive itself.
142-
tar_archive: Vec<u8>,
146+
tar_archive: Vec<u8>,
143147
/// The list of files in the archive, the paths are relative to the root of
144148
/// the archive.
145149
archived_files: Vec<PathBuf>,
@@ -252,7 +256,7 @@ struct ContainerBuildOutput {
252256
/// The output Wasm file containing the unprocessed contract module.
253257
output_wasm: Vec<u8>,
254258
/// Information about the build so that it can be reproduced.
255-
build_info: utils::VersionedBuildInfo,
259+
build_info: utils::VersionedBuildInfo,
256260
/// The sources that were built, archived as a tar file.
257261
tar_archive: TarArchiveData,
258262
}
@@ -261,9 +265,9 @@ struct ContainerBuildOutput {
261265
struct PackageData<'a> {
262266
/// The target directory of the package that is being
263267
/// built. This is used to exclude it from bundling.
264-
package_target_dir: &'a Path,
268+
package_target_dir: &'a Path,
265269
/// The root of the package to build.
266-
package_root_path: &'a Path,
270+
package_root_path: &'a Path,
267271
/// The package-name-version pair to mimics the behaviour or cargo package.
268272
/// The paths in the tar archive are
269273
package_version_string: &'a str,
@@ -295,13 +299,18 @@ fn build_in_container<'a>(
295299
tar_path: &Path,
296300
source_link: Option<String>,
297301
) -> anyhow::Result<ContainerBuildOutput> {
298-
let tar_archive = create_archive(package_root_path, package_version_string, &[
299-
out_path,
300-
tar_path,
301-
package_target_dir,
302-
])?;
302+
let tar_archive = create_archive(
303+
package_root_path,
304+
package_version_string,
305+
&[out_path, tar_path, package_target_dir],
306+
)?;
303307

304308
let archive_hash = sha2::Sha256::digest(&tar_archive.tar_archive);
309+
310+
println!("package_target_dir: {:?}", package_target_dir);
311+
println!("package_root_path: {:?}", package_root_path);
312+
println!("package_version_string: {:?}", package_version_string);
313+
println!("tar_path: {:?}", tar_path);
305314

306315
let build_command = [
307316
"cargo",
@@ -421,6 +430,12 @@ pub(crate) fn build_contract(
421430
.parent()
422431
.context("Unable to get package root path.")?;
423432

433+
434+
println!("resolve: {:#?}", metadata.resolve.is_some());
435+
println!("package: {:#?}", package.name);
436+
println!("package_root: {:#?}", package_root);
437+
// println!("metadata: {:#?}", metadata);p
438+
424439
let package_root_path = package_root.canonicalize()?;
425440

426441
let package_version_string = format!("{}-{}", package.name, package.version);
@@ -472,7 +487,7 @@ pub(crate) fn build_contract(
472487
if build_schema.embed() {
473488
schema_bytes = contracts_common::to_bytes(&schema);
474489
let custom_section = CustomSection {
475-
name: "concordium-schema".into(),
490+
name: "concordium-schema".into(),
476491
contents: &schema_bytes,
477492
};
478493
Some((Some(custom_section), schema))
@@ -494,7 +509,7 @@ pub(crate) fn build_contract(
494509
if build_schema.embed() {
495510
schema_bytes = contracts_common::to_bytes(&schema);
496511
let custom_section = CustomSection {
497-
name: "concordium-schema".into(),
512+
name: "concordium-schema".into(),
498513
contents: &schema_bytes,
499514
};
500515
Some((Some(custom_section), schema))
@@ -536,8 +551,8 @@ pub(crate) fn build_contract(
536551
} = build_in_container(
537552
image,
538553
PackageData {
539-
package_target_dir: package_target_dir.as_path(),
540-
package_root_path: package_root_path.as_path(),
554+
package_target_dir: package_target_dir.as_path(),
555+
package_root_path: package_root_path.as_path(),
541556
package_version_string: &package_version_string,
542557
},
543558
args_without_manifest,
@@ -642,7 +657,7 @@ pub(crate) fn build_contract(
642657
// Embed build info section if present.
643658
if let Some((build_info, _)) = &stored_build_info {
644659
let cs = CustomSection {
645-
name: BUILD_INFO_SECTION_NAME.into(),
660+
name: BUILD_INFO_SECTION_NAME.into(),
646661
contents: &contracts_common::to_bytes(&build_info),
647662
};
648663
write_custom_section(&mut output_bytes, &cs)?;
@@ -1347,13 +1362,11 @@ pub fn build_and_run_wasm_test(
13471362
let target_dir = metadata.target_directory.as_std_path().join("concordium");
13481363

13491364
let (mut cmd, filename) = cargo_build_cmd(extra_args, target_dir, &metadata)?;
1350-
cmd.arg("--features").arg(
1351-
if enable_debug {
1352-
"concordium-std/wasm-test,concordium-std/debug"
1353-
} else {
1354-
"concordium-std/wasm-test"
1355-
},
1356-
);
1365+
cmd.arg("--features").arg(if enable_debug {
1366+
"concordium-std/wasm-test,concordium-std/debug"
1367+
} else {
1368+
"concordium-std/wasm-test"
1369+
});
13571370

13581371
// Output what we are doing so that it is easier to debug if the user
13591372
// has their own features or options.

0 commit comments

Comments
 (0)