diff --git a/standalone-openfl-app/src/Main.hx b/standalone-openfl-app/src/Main.hx index a96ae288..c7375d3e 100644 --- a/standalone-openfl-app/src/Main.hx +++ b/standalone-openfl-app/src/Main.hx @@ -1,6 +1,7 @@ package; import openfl.display.Sprite; +import Assets; // Forces build(macros.AssetMacro.build()) to run. class Main extends Sprite { public function new() { diff --git a/standalone-openfl-app/src/macros/AssetMacro.hx b/standalone-openfl-app/src/macros/AssetMacro.hx index be7055ee..c48d406a 100644 --- a/standalone-openfl-app/src/macros/AssetMacro.hx +++ b/standalone-openfl-app/src/macros/AssetMacro.hx @@ -41,7 +41,10 @@ class AssetMacro { var manifestDir = outputDir + "/manifest"; var assetsOutputDir = outputDir + "/assets"; - // Create directories if they don't exist + // These directories are owned by this macro. Recreate them so removed or + // renamed source assets cannot survive as stale build output. + removeDirectory(manifestDir); + removeDirectory(assetsOutputDir); createDirectory(manifestDir); createDirectory(assetsOutputDir); copyLimeNativeLibrary(outputDir); @@ -241,6 +244,20 @@ class AssetMacro { } } + private static function removeDirectory(path:String):Void { + if (!FileSystem.exists(path)) return; + + for (entry in FileSystem.readDirectory(path)) { + var entryPath = path + "/" + entry; + if (FileSystem.isDirectory(entryPath)) { + removeDirectory(entryPath); + } else { + FileSystem.deleteFile(entryPath); + } + } + FileSystem.deleteDirectory(path); + } + /** Stage the Lime CFFI module that matches the selected haxelib version. */ private static function copyLimeNativeLibrary(outputDir:String):Void { var platformDirectory = if (Context.defined("linux")) {