Separate getNativesZipFile and getPrebuiltNatives. Improve code quality.

* Fix the task 'getPrebuiltNatives'

* Do not replace native if it's newer than zip
fix-openal-soft-deadlink
Thodoris Sotiropoulos 5 years ago committed by Riccardo Balbo
parent d8a42d0817
commit 4d734ac297
  1. 31
      build.gradle

@ -168,18 +168,23 @@ if(skipPrebuildLibraries!="true"&&buildNativeProjects!="true"){
String nativesZipFile="${rootPath}" + File.separator + "build"+ File.separator +nativesSnasphot+"-natives.zip" String nativesZipFile="${rootPath}" + File.separator + "build"+ File.separator +nativesSnasphot+"-natives.zip"
String nativesPath="${rootPath}" + File.separator + "build"+ File.separator +"native" String nativesPath="${rootPath}" + File.separator + "build"+ File.separator +"native"
build.dependsOn('getPrebuiltNatives')
task getPrebuiltNatives() { task getNativesZipFile {
outputs.file nativesZipFile
doFirst { doFirst {
File target = file(nativesZipFile); File target = file(nativesZipFile);
if (!target.exists()) {
println("Download natives from "+nativesUrl+" to "+nativesZipFile); println("Download natives from "+nativesUrl+" to "+nativesZipFile);
target.getParentFile().mkdirs(); target.getParentFile().mkdirs();
ant.get(src: nativesUrl, dest: target); ant.get(src: nativesUrl, dest: target);
} }
}
task extractPrebuiltNatives {
inputs.file nativesZipFile
outputs.dir nativesPath
dependsOn getNativesZipFile
doFirst {
for(File src : zipTree(nativesZipFile)){ for(File src : zipTree(nativesZipFile)){
String srcRel=src.getAbsolutePath().substring((int)(nativesZipFile.length()+1)); String srcRel=src.getAbsolutePath().substring((int)(nativesZipFile.length()+1));
srcRel=srcRel.substring(srcRel.indexOf("/")+1); srcRel=srcRel.substring(srcRel.indexOf("/")+1);
@ -189,29 +194,17 @@ if(skipPrebuildLibraries!="true"&&buildNativeProjects!="true"){
String p1=srcRel.substring(0,j); String p1=srcRel.substring(0,j);
String p2=srcRel.substring(j); String p2=srcRel.substring(j);
if(!p1.equals("android")&&!p2.startsWith("/native")) srcRel=p1+"/native"+p2; if(!p1.equals("android")&&!p2.startsWith("/native")) srcRel=p1+"/native"+p2;
//
File dest=new File(nativesPath+File.separator+srcRel); File dest=new File(nativesPath+File.separator+srcRel);
boolean doCopy = !(dest.exists() && dest.lastModified() > src.lastModified())
boolean include=false; if (doCopy) {
if(!dest.exists()){
include=true;
println("Copy "+src+" "+dest); println("Copy "+src+" "+dest);
}else if(dest.lastModified()<src.lastModified()){
include=true;
println("Copy "+src+" "+dest+ ". Source is newer. src "+src.lastModified()+ " dest "+dest.lastModified());
}
else{
println(""+dest+" Up to date. Skip.");
}
if(include){
dest.getParentFile().mkdirs(); dest.getParentFile().mkdirs();
Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
} }
} }
} }
} }
build.dependsOn extractPrebuiltNatives
} }
} }

Loading…
Cancel
Save