Unify asset copying code, and standardize asset embedding.
Having eight separate implementations made it harder to maintain. While an asset embedding bug got fixed on desktop targets, it got overlooked on others. This lead to assets being included twice on those other targets: once embedded, and once normally. (#1898) Now, that behavior is controlled from one place, and the bug is fixed for eight targets at once. This also standardizes the case of `asset.embed == true && asset.type == TEMPLATE`. Previously, some targets would prioritze `embed` over `type`, embedding the template into the app without even processing it as a template. Now, it will always prioritize `type`, processing templates as templates and never trying to embed them. Three targets are left out since they have more complex asset embedding behavior. I haven't checked if the bug is present on any of those.
This commit is contained in:
@@ -406,17 +406,6 @@ class AndroidPlatform extends PlatformTarget
|
||||
|
||||
// project = project.clone ();
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.embed && asset.sourcePath == "")
|
||||
{
|
||||
var path = Path.combine(targetDirectory + "/obj/tmp", asset.targetPath);
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path);
|
||||
asset.sourcePath = path;
|
||||
}
|
||||
}
|
||||
|
||||
// initialize (project);
|
||||
|
||||
var destination = targetDirectory + "/bin";
|
||||
@@ -427,36 +416,6 @@ class AndroidPlatform extends PlatformTarget
|
||||
System.mkdir(sourceSet + "/res/drawable-hdpi/");
|
||||
System.mkdir(sourceSet + "/res/drawable-xhdpi/");
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.type != AssetType.TEMPLATE)
|
||||
{
|
||||
var targetPath = "";
|
||||
|
||||
switch (asset.type)
|
||||
{
|
||||
default:
|
||||
// case SOUND, MUSIC:
|
||||
|
||||
// var extension = Path.extension (asset.sourcePath);
|
||||
// asset.flatName += ((extension != "") ? "." + extension : "");
|
||||
|
||||
// asset.resourceName = asset.flatName;
|
||||
targetPath = Path.combine(sourceSet + "/assets/", asset.resourceName);
|
||||
|
||||
// asset.resourceName = asset.id;
|
||||
// targetPath = sourceSet + "/res/raw/" + asset.flatName + "." + Path.extension (asset.targetPath);
|
||||
|
||||
// default:
|
||||
|
||||
// asset.resourceName = asset.flatName;
|
||||
// targetPath = sourceSet + "/assets/" + asset.resourceName;
|
||||
}
|
||||
|
||||
AssetHelper.copyAssetIfNewer(asset, targetPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (project.targetFlags.exists("xml"))
|
||||
{
|
||||
project.haxeflags.push("-xml " + targetDirectory + "/types.xml");
|
||||
@@ -663,13 +622,13 @@ class AndroidPlatform extends PlatformTarget
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.type == AssetType.TEMPLATE)
|
||||
if (asset.type != AssetType.TEMPLATE)
|
||||
{
|
||||
var targetPath = Path.combine(destination, asset.targetPath);
|
||||
System.mkdir(Path.directory(targetPath));
|
||||
AssetHelper.copyAsset(asset, targetPath, context);
|
||||
asset.targetPath = asset.resourceName;
|
||||
}
|
||||
}
|
||||
|
||||
copyProjectAssets(destination, sourceSet + "/assets/");
|
||||
}
|
||||
|
||||
public override function watch():Void
|
||||
|
||||
@@ -169,7 +169,7 @@ class IOSPlatform extends PlatformTarget
|
||||
{
|
||||
project.haxeflags.push("-xml " + targetDirectory + "/types.xml");
|
||||
}
|
||||
|
||||
|
||||
if (project.targetFlags.exists("json"))
|
||||
{
|
||||
project.haxeflags.push("--json " + targetDirectory + "/types.json");
|
||||
@@ -524,17 +524,6 @@ class IOSPlatform extends PlatformTarget
|
||||
|
||||
// project = project.clone ();
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.embed && asset.sourcePath == "")
|
||||
{
|
||||
var path = Path.combine(targetDirectory + "/" + project.app.file + "/obj/tmp", asset.targetPath);
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path);
|
||||
asset.sourcePath = path;
|
||||
}
|
||||
}
|
||||
|
||||
// var manifest = new Asset ();
|
||||
// manifest.id = "__manifest__";
|
||||
// manifest.data = AssetHelper.createManifest (project).serialize ();
|
||||
@@ -857,30 +846,7 @@ class IOSPlatform extends PlatformTarget
|
||||
}
|
||||
}
|
||||
|
||||
System.mkdir(projectDirectory + "/assets");
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.type != AssetType.TEMPLATE)
|
||||
{
|
||||
var targetPath = Path.combine(projectDirectory + "/assets/", asset.resourceName);
|
||||
|
||||
// var sourceAssetPath:String = projectDirectory + "haxe/" + asset.sourcePath;
|
||||
|
||||
System.mkdir(Path.directory(targetPath));
|
||||
AssetHelper.copyAssetIfNewer(asset, targetPath);
|
||||
|
||||
// System.mkdir (Path.directory (sourceAssetPath));
|
||||
// System.linkFile (flatAssetPath, sourceAssetPath, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var targetPath = Path.combine(projectDirectory, asset.targetPath);
|
||||
|
||||
System.mkdir(Path.directory(targetPath));
|
||||
AssetHelper.copyAsset(asset, targetPath, context);
|
||||
}
|
||||
}
|
||||
copyProjectAssets(projectDirectory, "assets");
|
||||
|
||||
if (project.targetFlags.exists("xcode") && System.hostPlatform == MAC && command == "update")
|
||||
{
|
||||
|
||||
@@ -553,17 +553,6 @@ class LinuxPlatform extends PlatformTarget
|
||||
// project = project.clone ();
|
||||
// initialize (project);
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.embed && asset.sourcePath == "")
|
||||
{
|
||||
var path = Path.combine(targetDirectory + "/obj/tmp", asset.targetPath);
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path);
|
||||
asset.sourcePath = path;
|
||||
}
|
||||
}
|
||||
|
||||
if (project.targetFlags.exists("xml"))
|
||||
{
|
||||
project.haxeflags.push("-xml " + targetDirectory + "/types.xml");
|
||||
@@ -606,24 +595,7 @@ class LinuxPlatform extends PlatformTarget
|
||||
}
|
||||
|
||||
// context.HAS_ICON = IconHelper.createIcon (project.icons, 256, 256, Path.combine (applicationDirectory, "icon.png"));
|
||||
for (asset in project.assets)
|
||||
{
|
||||
var path = Path.combine(applicationDirectory, asset.targetPath);
|
||||
|
||||
if (asset.embed != true)
|
||||
{
|
||||
if (asset.type != AssetType.TEMPLATE)
|
||||
{
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAssetIfNewer(asset, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
copyProjectAssets(applicationDirectory);
|
||||
}
|
||||
|
||||
public override function watch():Void
|
||||
|
||||
@@ -525,17 +525,6 @@ class MacPlatform extends PlatformTarget
|
||||
project.haxeflags.push("--json " + targetDirectory + "/types.json");
|
||||
}
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.embed && asset.sourcePath == "")
|
||||
{
|
||||
var path = Path.combine(targetDirectory + "/obj/tmp", asset.targetPath);
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path);
|
||||
asset.sourcePath = path;
|
||||
}
|
||||
}
|
||||
|
||||
var context = generateContext();
|
||||
context.OUTPUT_DIR = targetDirectory;
|
||||
|
||||
@@ -584,22 +573,7 @@ class MacPlatform extends PlatformTarget
|
||||
|
||||
context.HAS_ICON = IconHelper.createMacIcon(icons, Path.combine(contentDirectory, "icon.icns"));
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.embed != true)
|
||||
{
|
||||
if (asset.type != AssetType.TEMPLATE)
|
||||
{
|
||||
System.mkdir(Path.directory(Path.combine(contentDirectory, asset.targetPath)));
|
||||
AssetHelper.copyAssetIfNewer(asset, Path.combine(contentDirectory, asset.targetPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
System.mkdir(Path.directory(Path.combine(targetDirectory, asset.targetPath)));
|
||||
AssetHelper.copyAsset(asset, Path.combine(targetDirectory, asset.targetPath), context);
|
||||
}
|
||||
}
|
||||
}
|
||||
copyProjectAssets(targetDirectory, contentDirectory);
|
||||
}
|
||||
|
||||
public override function watch():Void
|
||||
|
||||
@@ -434,17 +434,6 @@ class TVOSPlatform extends PlatformTarget
|
||||
|
||||
// project = project.clone ();
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.embed && asset.sourcePath == "")
|
||||
{
|
||||
var path = Path.combine(targetDirectory + "/" + project.app.file + "/obj/tmp", asset.targetPath);
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path);
|
||||
asset.sourcePath = path;
|
||||
}
|
||||
}
|
||||
|
||||
// var manifest = new Asset ();
|
||||
// manifest.id = "__manifest__";
|
||||
// manifest.data = AssetHelper.createManifest (project).serialize ();
|
||||
@@ -628,30 +617,7 @@ class TVOSPlatform extends PlatformTarget
|
||||
}
|
||||
}
|
||||
|
||||
System.mkdir(projectDirectory + "/assets");
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.type != AssetType.TEMPLATE)
|
||||
{
|
||||
var targetPath = Path.combine(projectDirectory + "/assets/", asset.resourceName);
|
||||
|
||||
// var sourceAssetPath:String = projectDirectory + "haxe/" + asset.sourcePath;
|
||||
|
||||
System.mkdir(Path.directory(targetPath));
|
||||
AssetHelper.copyAssetIfNewer(asset, targetPath);
|
||||
|
||||
// System.mkdir (Path.directory (sourceAssetPath));
|
||||
// System.linkFile (flatAssetPath, sourceAssetPath, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var targetPath = Path.combine(projectDirectory, asset.targetPath);
|
||||
|
||||
System.mkdir(Path.directory(targetPath));
|
||||
AssetHelper.copyAsset(asset, targetPath, context);
|
||||
}
|
||||
}
|
||||
copyProjectAssets(projectDirectory, "assets");
|
||||
|
||||
if (project.targetFlags.exists("xcode") && System.hostPlatform == MAC && command == "update")
|
||||
{
|
||||
|
||||
@@ -203,17 +203,6 @@ class TizenPlatform extends PlatformTarget
|
||||
|
||||
// project = project.clone ();
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.embed && asset.sourcePath == "")
|
||||
{
|
||||
var path = Path.combine(targetDirectory + "/obj/tmp", asset.targetPath);
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path);
|
||||
asset.sourcePath = path;
|
||||
}
|
||||
}
|
||||
|
||||
var destination = targetDirectory + "/bin/";
|
||||
System.mkdir(destination);
|
||||
|
||||
@@ -256,30 +245,9 @@ class TizenPlatform extends PlatformTarget
|
||||
ProjectHelper.recursiveSmartCopyTemplate(project, "haxe", targetDirectory + "/haxe", context);
|
||||
ProjectHelper.recursiveSmartCopyTemplate(project, "tizen/hxml", targetDirectory + "/haxe", context);
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
var path = Path.combine(destination + "res/", asset.targetPath);
|
||||
|
||||
System.mkdir(Path.directory(path));
|
||||
|
||||
if (asset.type != AssetType.TEMPLATE)
|
||||
{
|
||||
if (asset.targetPath == "/appinfo.json")
|
||||
{
|
||||
AssetHelper.copyAsset(asset, path, context);
|
||||
}
|
||||
else
|
||||
{
|
||||
// going to root directory now, but should it be a forced "assets" folder later?
|
||||
|
||||
AssetHelper.copyAssetIfNewer(asset, path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetHelper.copyAsset(asset, path, context);
|
||||
}
|
||||
}
|
||||
// going to root directory now, but should it be a forced "assets" folder later?
|
||||
copyProjectAssets(destination + "res/", "");
|
||||
// copyProjectAssets(destination + "res/", "assets");
|
||||
}
|
||||
|
||||
@ignore public override function install():Void {}
|
||||
|
||||
@@ -396,17 +396,6 @@ class WebAssemblyPlatform extends PlatformTarget
|
||||
|
||||
// project = project.clone ();
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.embed && asset.sourcePath == "")
|
||||
{
|
||||
var path = Path.combine(targetDirectory + "/obj/tmp", asset.targetPath);
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path);
|
||||
asset.sourcePath = path;
|
||||
}
|
||||
}
|
||||
|
||||
// for (asset in project.assets)
|
||||
// {
|
||||
// asset.resourceName = "assets/" + asset.resourceName;
|
||||
@@ -481,37 +470,13 @@ class WebAssemblyPlatform extends PlatformTarget
|
||||
}
|
||||
}
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
var path = Path.combine(targetDirectory + "/obj/assets", asset.targetPath);
|
||||
|
||||
if (asset.type != AssetType.TEMPLATE)
|
||||
{
|
||||
// if (asset.type != AssetType.FONT) {
|
||||
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAssetIfNewer(asset, path);
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
ProjectHelper.recursiveSmartCopyTemplate(project, "webassembly/template", destination, context);
|
||||
ProjectHelper.recursiveSmartCopyTemplate(project, "haxe", targetDirectory + "/haxe", context);
|
||||
ProjectHelper.recursiveSmartCopyTemplate(project, "webassembly/hxml", targetDirectory + "/haxe", context);
|
||||
// ProjectHelper.recursiveSmartCopyTemplate(project, "webassembly/cpp", targetDirectory + "/obj", context);
|
||||
ProjectHelper.recursiveSmartCopyTemplate(project, "cpp/static", targetDirectory + "/obj", context);
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
var path = Path.combine(destination, asset.targetPath);
|
||||
|
||||
if (asset.type == AssetType.TEMPLATE)
|
||||
{
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path, context);
|
||||
}
|
||||
}
|
||||
copyProjectAssets(destination, targetDirectory + "/obj/assets");
|
||||
}
|
||||
|
||||
@ignore public override function install():Void {}
|
||||
|
||||
@@ -962,17 +962,6 @@ class WindowsPlatform extends PlatformTarget
|
||||
project.haxeflags.push("--json " + targetDirectory + "/types.json");
|
||||
}
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.embed && asset.sourcePath == "")
|
||||
{
|
||||
var path = Path.combine(targetDirectory + "/obj/tmp", asset.targetPath);
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path);
|
||||
asset.sourcePath = path;
|
||||
}
|
||||
}
|
||||
|
||||
var context = generateContext();
|
||||
context.OUTPUT_DIR = targetDirectory;
|
||||
|
||||
@@ -1040,24 +1029,7 @@ class WindowsPlatform extends PlatformTarget
|
||||
|
||||
}*/
|
||||
|
||||
for (asset in project.assets)
|
||||
{
|
||||
if (asset.embed != true)
|
||||
{
|
||||
var path = Path.combine(applicationDirectory, asset.targetPath);
|
||||
|
||||
if (asset.type != AssetType.TEMPLATE)
|
||||
{
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAssetIfNewer(asset, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.mkdir(Path.directory(path));
|
||||
AssetHelper.copyAsset(asset, path, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
copyProjectAssets(applicationDirectory);
|
||||
}
|
||||
|
||||
private function updateUWP():Void
|
||||
|
||||
Reference in New Issue
Block a user