Skip to content

Commit

Permalink
Experiment with CI
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi committed Feb 16, 2022
1 parent aecb385 commit f4c6e04
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
68 changes: 61 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ fn main() {
dylint_dst_file.display()
);

let zipped_lints = match zip_file(
&out_dir
.join("release")
.join("libink_lints@nightly-2021-11-04-x86_64-unknown-linux-gnu.so"),
&dylint_dst_file,
CompressionMethod::Stored,
) {
//#[cfg(not(target_os = "windows"))]
let p = &out_dir.join("release");
//.join("libink_lints@nightly-2021-11-04-x86_64-unknown-linux-gnu.so");
//#[cfg(target_os = "windows")]
//let p = &out_dir.join("release").join("libink_lints@nightly-2021-11-04-x86_64-unknown-linux-gnu.so");
let zipped_lints = match zip_lint_driver(p, &dylint_dst_file, CompressionMethod::Stored) {
Ok(_) => {
println!(
"done: {} written to {}",
Expand Down Expand Up @@ -203,6 +202,61 @@ fn zip_file(src_file: &Path, dst_file: &Path, method: CompressionMethod) -> Resu
Ok(())
}

fn zip_lint_driver(src_dir: &Path, dst_file: &Path, method: CompressionMethod) -> Result<()> {
if !src_dir.exists() {
anyhow::bail!("src_dir '{}' does not exist", src_dir.display());
}
if !src_dir.is_dir() {
anyhow::bail!("src_dir '{}' is not a directory", src_dir.display());
}

let file = File::create(dst_file)?;

let mut zip = ZipWriter::new(file);
let options = FileOptions::default()
.compression_method(method)
.unix_permissions(DEFAULT_UNIX_PERMISSIONS);

let mut buffer = Vec::new();
//let path = src_dir;
//println!("\npath: {:?}", path);

//println!("{}", path.display());

let walkdir = WalkDir::new(src_dir);
let it = walkdir.into_iter().filter_map(|e| e.ok());

//let mut file_path: Option<Path> = None;
for entry in it {
let path = entry.path();
let mut name = path.strip_prefix(&src_dir)?.to_path_buf();

let file_path = name.as_os_str().to_string_lossy();

if path.is_file() && path.display().to_string().contains("libink_lints@") {
println!("\nzip_lint {:?}", path);
//let tmp = name.as_os_str();
//let f_path = format!("{}", tmp.to_string_lossy()).to_string();
//file_path = Some(path.);
//let file_path = file_path.expect("file path must exist");
//let file_path = path.file_name().expect("failed").to_string_lossy();

//zip.start_file(dst_file.as_os_str().to_string_lossy(), options)?;
zip.start_file(file_path, options)?;
let mut f = File::open(path)?;

f.read_to_end(&mut buffer)?;
zip.write_all(&*buffer)?;
buffer.clear();

zip.finish()?;
println!("dst: {:?}", dst_file);
break;
}
}
Ok(())
}

/// Generate the `cargo:` key output
fn generate_cargo_keys() {
let output = Command::new("git")
Expand Down
1 change: 1 addition & 0 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ fn exec_cargo_dylint(crate_metadata: &CrateMetadata, verbosity: Verbosity) -> Re
"--manifest-path={}",
contract_manifest_path.as_path().display()
);
//let foo = format!("--lib={}/libink_lints.so", tmp_dir.path().display());
let args = vec!["ink_lints", &manifest_arg];
let dl_path = format!("{}", out_dir.display());
let env = Some(("DYLINT_LIBRARY_PATH", dl_path.as_str()));
Expand Down
6 changes: 5 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ pub fn unzip(template: &[u8], out_dir: PathBuf, name: Option<&str>) -> Result<()
.open(outpath.clone())
.map_err(|e| {
if e.kind() == std::io::ErrorKind::AlreadyExists {
anyhow::anyhow!("New contract file {} already exists", file.name())
anyhow::anyhow!(
"New contract file {} already exists at {:?}",
file.name(),
outpath
)
} else {
anyhow::anyhow!(e)
}
Expand Down

0 comments on commit f4c6e04

Please sign in to comment.