Skip to content

Commit 6a7239c

Browse files
authored
Fix duplicate code in PlatformTarget subclasses, fix assets being included twice. (#1980)
2 parents ad52eb7 + 82618ef commit 6a7239c

File tree

12 files changed

+101
-484
lines changed

12 files changed

+101
-484
lines changed

src/lime/tools/PlatformTarget.hx

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,17 @@ class PlatformTarget
151151
}
152152
}
153153

154+
// Command implementations
155+
154156
@ignore public function build():Void {}
155157

156-
@ignore public function clean():Void {}
158+
public function clean():Void
159+
{
160+
if (FileSystem.exists(targetDirectory))
161+
{
162+
System.removeDirectory(targetDirectory);
163+
}
164+
}
157165

158166
@ignore public function deploy():Void {}
159167

@@ -171,7 +179,69 @@ class PlatformTarget
171179

172180
@ignore public function update():Void {}
173181

174-
@ignore public function watch():Void {}
182+
public function watch():Void
183+
{
184+
var hxml = getDisplayHXML();
185+
if (hxml == null)
186+
{
187+
return;
188+
}
189+
190+
var dirs = hxml.getClassPaths(true);
191+
192+
var outputPath = Path.combine(Sys.getCwd(), project.app.path);
193+
dirs = dirs.filter(function(dir)
194+
{
195+
return (!Path.startsWith(dir, outputPath));
196+
});
197+
198+
var command = ProjectHelper.getCurrentCommand();
199+
System.watch(command, dirs);
200+
}
201+
202+
// Common functionality used by subclasses
203+
204+
private function copyProjectAssets(outputDirectory:String, assetDirectory:String = null)
205+
{
206+
if (assetDirectory == null)
207+
{
208+
assetDirectory = outputDirectory;
209+
}
210+
else if (!StringTools.startsWith(assetDirectory, targetDirectory))
211+
{
212+
assetDirectory = Path.combine(outputDirectory, assetDirectory);
213+
}
214+
215+
var embedDirectory = Path.combine(targetDirectory, "obj/tmp");
216+
217+
for (asset in project.assets)
218+
{
219+
if (asset.type == AssetType.TEMPLATE)
220+
{
221+
var path = Path.combine(outputDirectory, asset.targetPath);
222+
System.mkdir(Path.directory(path));
223+
AssetHelper.copyAsset(asset, path, project.templateContext);
224+
}
225+
else if (asset.embed == true)
226+
{
227+
if (asset.sourcePath == "")
228+
{
229+
var path = Path.combine(embedDirectory, asset.targetPath);
230+
System.mkdir(Path.directory(path));
231+
AssetHelper.copyAsset(asset, path);
232+
asset.sourcePath = path;
233+
}
234+
}
235+
else
236+
{
237+
var path = Path.combine(assetDirectory, asset.targetPath);
238+
System.mkdir(Path.directory(path));
239+
AssetHelper.copyAssetIfNewer(asset, path);
240+
}
241+
}
242+
}
243+
244+
private function getDisplayHXML():HXML { return null; }
175245

176246
// Functions to track and delete stale files
177247

tools/platforms/AIRPlatform.hx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,6 @@ class AIRPlatform extends FlashPlatform
168168
}
169169
}
170170

171-
public override function clean():Void
172-
{
173-
if (FileSystem.exists(targetDirectory))
174-
{
175-
System.removeDirectory(targetDirectory);
176-
}
177-
}
178-
179171
public override function deploy():Void
180172
{
181173
if (targetFlags.exists("gdrive") || targetFlags.exists("zip"))
@@ -395,4 +387,6 @@ class AIRPlatform extends FlashPlatform
395387
}
396388

397389
@ignore public override function rebuild():Void {}
390+
391+
@ignore public override function watch():Void {}
398392
}

tools/platforms/AndroidPlatform.hx

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,6 @@ class AndroidPlatform extends PlatformTarget
260260
AndroidHelper.build(project, destination);
261261
}
262262

263-
public override function clean():Void
264-
{
265-
if (FileSystem.exists(targetDirectory))
266-
{
267-
System.removeDirectory(targetDirectory);
268-
}
269-
}
270-
271263
public override function deploy():Void
272264
{
273265
DeploymentHelper.deploy(project, targetFlags, targetDirectory, "Android");
@@ -301,7 +293,7 @@ class AndroidPlatform extends PlatformTarget
301293
}
302294
}
303295

304-
private function getDisplayHXML():HXML
296+
private override function getDisplayHXML():HXML
305297
{
306298
var path = targetDirectory + "/haxe/" + buildType + ".hxml";
307299

@@ -409,17 +401,6 @@ class AndroidPlatform extends PlatformTarget
409401

410402
// project = project.clone ();
411403

412-
for (asset in project.assets)
413-
{
414-
if (asset.embed && asset.sourcePath == "")
415-
{
416-
var path = Path.combine(targetDirectory + "/obj/tmp", asset.targetPath);
417-
System.mkdir(Path.directory(path));
418-
AssetHelper.copyAsset(asset, path);
419-
asset.sourcePath = path;
420-
}
421-
}
422-
423404
// initialize (project);
424405

425406
var destination = targetDirectory + "/bin";
@@ -430,36 +411,6 @@ class AndroidPlatform extends PlatformTarget
430411
System.mkdir(sourceSet + "/res/drawable-hdpi/");
431412
System.mkdir(sourceSet + "/res/drawable-xhdpi/");
432413

433-
for (asset in project.assets)
434-
{
435-
if (asset.type != AssetType.TEMPLATE)
436-
{
437-
var targetPath = "";
438-
439-
switch (asset.type)
440-
{
441-
default:
442-
// case SOUND, MUSIC:
443-
444-
// var extension = Path.extension (asset.sourcePath);
445-
// asset.flatName += ((extension != "") ? "." + extension : "");
446-
447-
// asset.resourceName = asset.flatName;
448-
targetPath = Path.combine(sourceSet + "/assets/", asset.resourceName);
449-
450-
// asset.resourceName = asset.id;
451-
// targetPath = sourceSet + "/res/raw/" + asset.flatName + "." + Path.extension (asset.targetPath);
452-
453-
// default:
454-
455-
// asset.resourceName = asset.flatName;
456-
// targetPath = sourceSet + "/assets/" + asset.resourceName;
457-
}
458-
459-
AssetHelper.copyAssetIfNewer(asset, targetPath);
460-
}
461-
}
462-
463414
if (project.targetFlags.exists("xml"))
464415
{
465416
project.haxeflags.push("-xml " + targetDirectory + "/types.xml");
@@ -667,27 +618,12 @@ class AndroidPlatform extends PlatformTarget
667618

668619
for (asset in project.assets)
669620
{
670-
if (asset.type == AssetType.TEMPLATE)
621+
if (asset.type != AssetType.TEMPLATE)
671622
{
672-
var targetPath = Path.combine(destination, asset.targetPath);
673-
System.mkdir(Path.directory(targetPath));
674-
AssetHelper.copyAsset(asset, targetPath, context);
623+
asset.targetPath = asset.resourceName;
675624
}
676625
}
677-
}
678-
679-
public override function watch():Void
680-
{
681-
var hxml = getDisplayHXML();
682-
var dirs = hxml.getClassPaths(true);
683-
684-
var outputPath = Path.combine(Sys.getCwd(), project.app.path);
685-
dirs = dirs.filter(function(dir)
686-
{
687-
return (!Path.startsWith(dir, outputPath));
688-
});
689626

690-
var command = ProjectHelper.getCurrentCommand();
691-
System.watch(command, dirs);
627+
copyProjectAssets(destination, sourceSet + "/assets/");
692628
}
693629
}

tools/platforms/FlashPlatform.hx

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,6 @@ class FlashPlatform extends PlatformTarget
103103
System.runCommand("", "haxe", [targetDirectory + "/haxe/" + buildType + ".hxml"]);
104104
}
105105

106-
public override function clean():Void
107-
{
108-
var targetPath = targetDirectory + "";
109-
110-
if (FileSystem.exists(targetPath))
111-
{
112-
System.removeDirectory(targetPath);
113-
}
114-
}
115-
116106
public override function deploy():Void
117107
{
118108
DeploymentHelper.deploy(project, targetFlags, targetDirectory, "Flash");
@@ -175,7 +165,7 @@ class FlashPlatform extends PlatformTarget
175165
return context;
176166
}
177167

178-
private function getDisplayHXML():HXML
168+
private override function getDisplayHXML():HXML
179169
{
180170
var path = targetDirectory + "/haxe/" + buildType + ".hxml";
181171

@@ -336,20 +326,6 @@ class FlashPlatform extends PlatformTarget
336326
}
337327
338328
}*/
339-
public override function watch():Void
340-
{
341-
var hxml = getDisplayHXML();
342-
var dirs = hxml.getClassPaths(true);
343-
344-
var outputPath = Path.combine(Sys.getCwd(), project.app.path);
345-
dirs = dirs.filter(function(dir)
346-
{
347-
return (!Path.startsWith(dir, outputPath));
348-
});
349-
350-
var command = ProjectHelper.getCurrentCommand();
351-
System.watch(command, dirs);
352-
}
353329

354330
@ignore public override function install():Void {}
355331

tools/platforms/HTML5Platform.hx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,6 @@ class HTML5Platform extends PlatformTarget
177177
}
178178
}
179179

180-
public override function clean():Void
181-
{
182-
if (FileSystem.exists(targetDirectory))
183-
{
184-
System.removeDirectory(targetDirectory);
185-
}
186-
}
187-
188180
public override function deploy():Void
189181
{
190182
var name = "HTML5";
@@ -209,7 +201,7 @@ class HTML5Platform extends PlatformTarget
209201
}
210202
}
211203

212-
private function getDisplayHXML():HXML
204+
private override function getDisplayHXML():HXML
213205
{
214206
var path = targetDirectory + "/haxe/" + buildType + ".hxml";
215207

@@ -583,17 +575,7 @@ class HTML5Platform extends PlatformTarget
583575
{
584576
// TODO: Use a custom live reload HTTP server for test/run instead
585577

586-
var hxml = getDisplayHXML();
587-
var dirs = hxml.getClassPaths(true);
588-
589-
var outputPath = Path.combine(Sys.getCwd(), project.app.path);
590-
dirs = dirs.filter(function(dir)
591-
{
592-
return (!Path.startsWith(dir, outputPath));
593-
});
594-
595-
var command = ProjectHelper.getCurrentCommand();
596-
System.watch(command, dirs);
578+
super.watch();
597579
}
598580

599581
@ignore public override function install():Void {}

0 commit comments

Comments
 (0)