Skip to content

Commit f4c6e04

Browse files
committed
Experiment with CI
1 parent aecb385 commit f4c6e04

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

build.rs

+61-7
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ fn main() {
8686
dylint_dst_file.display()
8787
);
8888

89-
let zipped_lints = match zip_file(
90-
&out_dir
91-
.join("release")
92-
.join("libink_lints@nightly-2021-11-04-x86_64-unknown-linux-gnu.so"),
93-
&dylint_dst_file,
94-
CompressionMethod::Stored,
95-
) {
89+
//#[cfg(not(target_os = "windows"))]
90+
let p = &out_dir.join("release");
91+
//.join("libink_lints@nightly-2021-11-04-x86_64-unknown-linux-gnu.so");
92+
//#[cfg(target_os = "windows")]
93+
//let p = &out_dir.join("release").join("libink_lints@nightly-2021-11-04-x86_64-unknown-linux-gnu.so");
94+
let zipped_lints = match zip_lint_driver(p, &dylint_dst_file, CompressionMethod::Stored) {
9695
Ok(_) => {
9796
println!(
9897
"done: {} written to {}",
@@ -203,6 +202,61 @@ fn zip_file(src_file: &Path, dst_file: &Path, method: CompressionMethod) -> Resu
203202
Ok(())
204203
}
205204

205+
fn zip_lint_driver(src_dir: &Path, dst_file: &Path, method: CompressionMethod) -> Result<()> {
206+
if !src_dir.exists() {
207+
anyhow::bail!("src_dir '{}' does not exist", src_dir.display());
208+
}
209+
if !src_dir.is_dir() {
210+
anyhow::bail!("src_dir '{}' is not a directory", src_dir.display());
211+
}
212+
213+
let file = File::create(dst_file)?;
214+
215+
let mut zip = ZipWriter::new(file);
216+
let options = FileOptions::default()
217+
.compression_method(method)
218+
.unix_permissions(DEFAULT_UNIX_PERMISSIONS);
219+
220+
let mut buffer = Vec::new();
221+
//let path = src_dir;
222+
//println!("\npath: {:?}", path);
223+
224+
//println!("{}", path.display());
225+
226+
let walkdir = WalkDir::new(src_dir);
227+
let it = walkdir.into_iter().filter_map(|e| e.ok());
228+
229+
//let mut file_path: Option<Path> = None;
230+
for entry in it {
231+
let path = entry.path();
232+
let mut name = path.strip_prefix(&src_dir)?.to_path_buf();
233+
234+
let file_path = name.as_os_str().to_string_lossy();
235+
236+
if path.is_file() && path.display().to_string().contains("libink_lints@") {
237+
println!("\nzip_lint {:?}", path);
238+
//let tmp = name.as_os_str();
239+
//let f_path = format!("{}", tmp.to_string_lossy()).to_string();
240+
//file_path = Some(path.);
241+
//let file_path = file_path.expect("file path must exist");
242+
//let file_path = path.file_name().expect("failed").to_string_lossy();
243+
244+
//zip.start_file(dst_file.as_os_str().to_string_lossy(), options)?;
245+
zip.start_file(file_path, options)?;
246+
let mut f = File::open(path)?;
247+
248+
f.read_to_end(&mut buffer)?;
249+
zip.write_all(&*buffer)?;
250+
buffer.clear();
251+
252+
zip.finish()?;
253+
println!("dst: {:?}", dst_file);
254+
break;
255+
}
256+
}
257+
Ok(())
258+
}
259+
206260
/// Generate the `cargo:` key output
207261
fn generate_cargo_keys() {
208262
let output = Command::new("git")

src/cmd/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ fn exec_cargo_dylint(crate_metadata: &CrateMetadata, verbosity: Verbosity) -> Re
396396
"--manifest-path={}",
397397
contract_manifest_path.as_path().display()
398398
);
399+
//let foo = format!("--lib={}/libink_lints.so", tmp_dir.path().display());
399400
let args = vec!["ink_lints", &manifest_arg];
400401
let dl_path = format!("{}", out_dir.display());
401402
let env = Some(("DYLINT_LIBRARY_PATH", dl_path.as_str()));

src/util.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ pub fn unzip(template: &[u8], out_dir: PathBuf, name: Option<&str>) -> Result<()
229229
.open(outpath.clone())
230230
.map_err(|e| {
231231
if e.kind() == std::io::ErrorKind::AlreadyExists {
232-
anyhow::anyhow!("New contract file {} already exists", file.name())
232+
anyhow::anyhow!(
233+
"New contract file {} already exists at {:?}",
234+
file.name(),
235+
outpath
236+
)
233237
} else {
234238
anyhow::anyhow!(e)
235239
}

0 commit comments

Comments
 (0)