Merge pull request #1790 from player-03/stale_assets
Automatically delete stale assets and dependency files.
This commit is contained in:
@@ -4,6 +4,8 @@ import haxe.rtti.Meta;
|
|||||||
import hxp.*;
|
import hxp.*;
|
||||||
import lime.tools.AssetHelper;
|
import lime.tools.AssetHelper;
|
||||||
import lime.tools.CommandHelper;
|
import lime.tools.CommandHelper;
|
||||||
|
import sys.FileSystem;
|
||||||
|
import sys.io.File;
|
||||||
|
|
||||||
class PlatformTarget
|
class PlatformTarget
|
||||||
{
|
{
|
||||||
@@ -99,10 +101,12 @@ class PlatformTarget
|
|||||||
if (command == "update" || command == "build" || command == "test")
|
if (command == "update" || command == "build" || command == "test")
|
||||||
{
|
{
|
||||||
logCommand("update");
|
logCommand("update");
|
||||||
// #if lime
|
|
||||||
// AssetHelper.processLibraries (project, targetDirectory);
|
_touchedFiles = [];
|
||||||
// #end
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
|
deleteStaleFiles(_touchedFiles);
|
||||||
|
_touchedFiles = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == "build" || command == "test")
|
if (command == "build" || command == "test")
|
||||||
@@ -168,4 +172,85 @@ class PlatformTarget
|
|||||||
@ignore public function update():Void {}
|
@ignore public function update():Void {}
|
||||||
|
|
||||||
@ignore public function watch():Void {}
|
@ignore public function watch():Void {}
|
||||||
|
|
||||||
|
// Functions to track and delete stale files
|
||||||
|
|
||||||
|
/**
|
||||||
|
Files that were copied into the output directory due to something in
|
||||||
|
project.xml, but which might not be included next time.
|
||||||
|
|
||||||
|
`PlatformTarget` will handle assets and templates, but subclasses are
|
||||||
|
responsible for adding any other files they copy (e.g., dependencies).
|
||||||
|
**/
|
||||||
|
private var _touchedFiles:Array<String> = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Calls `System.copyIfNewer()` with the given arguments, then records the
|
||||||
|
file in `_touchedFiles`. See `_touchedFiles` for information about what
|
||||||
|
needs to be recorded.
|
||||||
|
**/
|
||||||
|
private function copyIfNewer(source:String, destination:String):Void
|
||||||
|
{
|
||||||
|
System.copyIfNewer(source, destination);
|
||||||
|
|
||||||
|
if (_touchedFiles != null)
|
||||||
|
{
|
||||||
|
_touchedFiles.push(destination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function deleteStaleFiles(touchedFiles:Array<String>):Void
|
||||||
|
{
|
||||||
|
if (project.defines.exists("lime-ignore-stale-files")) return;
|
||||||
|
|
||||||
|
for (asset in project.assets)
|
||||||
|
{
|
||||||
|
touchedFiles.push(targetDirectory + "/bin/" + asset.targetPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
var record:String = targetDirectory + "/.files";
|
||||||
|
if (FileSystem.exists(record))
|
||||||
|
{
|
||||||
|
for (oldFile in File.getContent(record).split("\n"))
|
||||||
|
{
|
||||||
|
if (oldFile.length > 0 && touchedFiles.indexOf(oldFile) < 0)
|
||||||
|
{
|
||||||
|
System.deleteFile(oldFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File.saveContent(record, touchedFiles.join("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Calls `System.recursiveCopy()` with the given arguments, then records
|
||||||
|
the files in `_touchedFiles`. See `_touchedFiles` for information about
|
||||||
|
what needs to be recorded.
|
||||||
|
**/
|
||||||
|
private function recursiveCopy(source:String, destination:String, context:Dynamic = null, process:Bool = true):Void
|
||||||
|
{
|
||||||
|
System.recursiveCopy(source, destination, context, process);
|
||||||
|
|
||||||
|
if (_touchedFiles == null || !FileSystem.exists(source)) return;
|
||||||
|
|
||||||
|
function recurse(source:String, destination:String):Void
|
||||||
|
{
|
||||||
|
for (file in FileSystem.readDirectory(source))
|
||||||
|
{
|
||||||
|
if (file.charAt(0) == ".") continue;
|
||||||
|
|
||||||
|
if (FileSystem.isDirectory(source + "/" + file))
|
||||||
|
{
|
||||||
|
recurse(source + "/" + file, destination + "/" + file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_touchedFiles.push(destination + "/" + file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recurse(source, destination);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -595,17 +595,17 @@ class AndroidPlatform extends PlatformTarget
|
|||||||
{
|
{
|
||||||
if (FileSystem.isDirectory(javaPath))
|
if (FileSystem.isDirectory(javaPath))
|
||||||
{
|
{
|
||||||
System.recursiveCopy(javaPath, sourceSet + "/java", context, true);
|
recursiveCopy(javaPath, sourceSet + "/java", context, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Path.extension(javaPath) == "jar")
|
if (Path.extension(javaPath) == "jar")
|
||||||
{
|
{
|
||||||
System.copyIfNewer(javaPath, destination + "/app/libs/" + Path.withoutDirectory(javaPath));
|
copyIfNewer(javaPath, destination + "/app/libs/" + Path.withoutDirectory(javaPath));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.copyIfNewer(javaPath, sourceSet + "/java/" + Path.withoutDirectory(javaPath));
|
copyIfNewer(javaPath, sourceSet + "/java/" + Path.withoutDirectory(javaPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -618,7 +618,7 @@ class AndroidPlatform extends PlatformTarget
|
|||||||
|
|
||||||
for (library in cast(context.ANDROID_LIBRARY_PROJECTS, Array<Dynamic>))
|
for (library in cast(context.ANDROID_LIBRARY_PROJECTS, Array<Dynamic>))
|
||||||
{
|
{
|
||||||
System.recursiveCopy(library.source, destination + "/deps/" + library.name, context, true);
|
recursiveCopy(library.source, destination + "/deps/" + library.name, context, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectHelper.recursiveSmartCopyTemplate(project, "android/template", destination, context);
|
ProjectHelper.recursiveSmartCopyTemplate(project, "android/template", destination, context);
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ class HTML5Platform extends PlatformTarget
|
|||||||
var name = Path.withoutDirectory(dependency.path);
|
var name = Path.withoutDirectory(dependency.path);
|
||||||
|
|
||||||
context.linkedLibraries.push("./" + dependencyPath + "/" + name);
|
context.linkedLibraries.push("./" + dependencyPath + "/" + name);
|
||||||
System.copyIfNewer(dependency.path, Path.combine(destination, Path.combine(dependencyPath, name)));
|
copyIfNewer(dependency.path, Path.combine(destination, Path.combine(dependencyPath, name)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -862,7 +862,7 @@ class IOSPlatform extends PlatformTarget
|
|||||||
fileName = "lib" + fileName;
|
fileName = "lib" + fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.copyIfNewer(dependency.path, projectDirectory + "/lib/" + arch + "/" + fileName);
|
copyIfNewer(dependency.path, projectDirectory + "/lib/" + arch + "/" + fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -633,7 +633,7 @@ class TVOSPlatform extends PlatformTarget
|
|||||||
fileName = "lib" + fileName;
|
fileName = "lib" + fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.copyIfNewer(dependency.path, projectDirectory + "/lib/" + arch + "/" + fileName);
|
copyIfNewer(dependency.path, projectDirectory + "/lib/" + arch + "/" + fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -471,7 +471,7 @@ class WebAssemblyPlatform extends PlatformTarget
|
|||||||
var name = Path.withoutDirectory(dependency.path);
|
var name = Path.withoutDirectory(dependency.path);
|
||||||
|
|
||||||
context.linkedLibraries.push("./" + dependencyPath + "/" + name);
|
context.linkedLibraries.push("./" + dependencyPath + "/" + name);
|
||||||
System.copyIfNewer(dependency.path, Path.combine(destination, Path.combine(dependencyPath, name)));
|
copyIfNewer(dependency.path, Path.combine(destination, Path.combine(dependencyPath, name)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ class WindowsPlatform extends PlatformTarget
|
|||||||
if (StringTools.endsWith(dependency.path, ".dll"))
|
if (StringTools.endsWith(dependency.path, ".dll"))
|
||||||
{
|
{
|
||||||
var fileName = Path.withoutDirectory(dependency.path);
|
var fileName = Path.withoutDirectory(dependency.path);
|
||||||
System.copyIfNewer(dependency.path, applicationDirectory + "/" + fileName);
|
copyIfNewer(dependency.path, applicationDirectory + "/" + fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1121,7 +1121,7 @@ class WindowsPlatform extends PlatformTarget
|
|||||||
var name = Path.withoutDirectory(dependency.path);
|
var name = Path.withoutDirectory(dependency.path);
|
||||||
|
|
||||||
context.linkedLibraries.push("./js/lib/" + name);
|
context.linkedLibraries.push("./js/lib/" + name);
|
||||||
System.copyIfNewer(dependency.path, Path.combine(destination, Path.combine("js/lib", name)));
|
copyIfNewer(dependency.path, Path.combine(destination, Path.combine("js/lib", name)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user