Delete stale dependencies in addition to stale assets.
This commit is contained in:
@@ -191,25 +191,6 @@ class AssetHelper
|
||||
return manifests;
|
||||
}
|
||||
|
||||
public static function deleteStaleAssets(project:HXProject, targetDirectory:String):Void
|
||||
{
|
||||
var newAssets = [for (asset in project.assets) asset.targetPath];
|
||||
|
||||
var recordFile:String = targetDirectory + "/.assets";
|
||||
if (FileSystem.exists(recordFile))
|
||||
{
|
||||
for (oldAsset in File.getContent(recordFile).split("\n"))
|
||||
{
|
||||
if (oldAsset.length > 0 && newAssets.indexOf(oldAsset) < 0)
|
||||
{
|
||||
System.deleteFile(targetDirectory + "/bin/" + oldAsset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File.saveContent(recordFile, newAssets.join("\n"));
|
||||
}
|
||||
|
||||
private static function getAssetData(project:HXProject, pathGroups:Map<String, Array<String>>, libraries:Map<String, Library>, library:String,
|
||||
asset:Asset):Dynamic
|
||||
{
|
||||
|
||||
@@ -4,6 +4,8 @@ import haxe.rtti.Meta;
|
||||
import hxp.*;
|
||||
import lime.tools.AssetHelper;
|
||||
import lime.tools.CommandHelper;
|
||||
import sys.FileSystem;
|
||||
import sys.io.File;
|
||||
|
||||
class PlatformTarget
|
||||
{
|
||||
@@ -99,12 +101,12 @@ class PlatformTarget
|
||||
if (command == "update" || command == "build" || command == "test")
|
||||
{
|
||||
logCommand("update");
|
||||
// #if lime
|
||||
// AssetHelper.processLibraries (project, targetDirectory);
|
||||
// #end
|
||||
|
||||
_touchedFiles = [];
|
||||
update();
|
||||
|
||||
AssetHelper.deleteStaleAssets(project, targetDirectory);
|
||||
deleteStaleFiles(_touchedFiles);
|
||||
_touchedFiles = null;
|
||||
}
|
||||
|
||||
if (command == "build" || command == "test")
|
||||
@@ -170,4 +172,85 @@ class PlatformTarget
|
||||
@ignore public function update():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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user