From de7f9071a8b14f8a821dc107d87c3b150311a559 Mon Sep 17 00:00:00 2001 From: Demyan Kimitsa Date: Wed, 12 Apr 2023 11:28:46 +0300 Subject: [PATCH] * actool: support for AltIcons and other options (#718) # the issue - originally was reported in #636 (support for alt icons) - also if xcassets contain multiple icons -- random one was picked for the app - also if xcassets contain multiple launch images -- random one was picked for the app # the fix `robovm.xml` was extended with `actool` options: ``` AppIcon true ``` new parameters: - `appicon` - specifies which icon to use for app (in case of multiple) - `launchImage` -- specifies which launchImage to use (in case of multiple) - `includeAllAppIcons` -- will add `--include-all-app-icons` command line argument to include all app icons - `args` -- allows to add raw arguments for actool --- .../compiler/config/tools/ActoolOptions.java | 55 ++++++++++++ .../robovm/compiler/config/tools/Tools.java | 9 +- .../robovm/compiler/util/ToolchainUtil.java | 85 ++++++++++++++----- 3 files changed, 127 insertions(+), 22 deletions(-) create mode 100755 compiler/compiler/src/main/java/org/robovm/compiler/config/tools/ActoolOptions.java diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/config/tools/ActoolOptions.java b/compiler/compiler/src/main/java/org/robovm/compiler/config/tools/ActoolOptions.java new file mode 100755 index 000000000..4703570a6 --- /dev/null +++ b/compiler/compiler/src/main/java/org/robovm/compiler/config/tools/ActoolOptions.java @@ -0,0 +1,55 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.robovm.compiler.config.tools; + +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Settings to provide custom actool arguments + * @author dkimitsa + */ +public class ActoolOptions { + @ElementList(required = false, entry = "arg") + private ArrayList args; + + @Element(required = false) + private String appIcon; + + @Element(required = false) + private String launchImage; + + @Element(required = false) + private Boolean includeAllAppIcons; + + public List getArguments() { + return args != null ? Collections.unmodifiableList(args) : Collections.emptyList(); + } + + public String getAppIconName() { + return appIcon; + } + + public String getLaunchImageName() { + return launchImage; + } + + public boolean shouldIncludeAllAppIcons() { + return includeAllAppIcons != null ? includeAllAppIcons : false; + } +} diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/config/tools/Tools.java b/compiler/compiler/src/main/java/org/robovm/compiler/config/tools/Tools.java index add9ee765..6fadf9cc7 100755 --- a/compiler/compiler/src/main/java/org/robovm/compiler/config/tools/Tools.java +++ b/compiler/compiler/src/main/java/org/robovm/compiler/config/tools/Tools.java @@ -28,7 +28,10 @@ public class Tools { @Element(required = false) private LinkerOptions linker; - + + @Element(required = false) + private ActoolOptions actool; + public TextureAtlas getTextureAtlas() { return textureAtlas; } @@ -36,4 +39,8 @@ public TextureAtlas getTextureAtlas() { public LinkerOptions getLinker() { return linker; } + + public ActoolOptions getActool() { + return actool; + } } diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/util/ToolchainUtil.java b/compiler/compiler/src/main/java/org/robovm/compiler/util/ToolchainUtil.java index 431145bd9..f50ab192d 100755 --- a/compiler/compiler/src/main/java/org/robovm/compiler/util/ToolchainUtil.java +++ b/compiler/compiler/src/main/java/org/robovm/compiler/util/ToolchainUtil.java @@ -21,8 +21,8 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.robovm.compiler.config.Config; -import org.robovm.compiler.config.CpuArch; import org.robovm.compiler.config.OS; +import org.robovm.compiler.config.tools.ActoolOptions; import org.robovm.compiler.config.tools.TextureAtlas; import org.robovm.compiler.log.ConsoleLogger; import org.robovm.compiler.log.Logger; @@ -239,37 +239,80 @@ public static void actool(Config config, File partialInfoPlist, File outDir, Fil public static void actool(Config config, File partialInfoPlist, File outDir, List inDirs) throws IOException { List opts = new ArrayList<>(); - String appIconSetName = null; + boolean appIconSetNameByArgs = false; String launchImagesName = null; - - final String appiconset = "appiconset"; - final String launchimage = "launchimage"; - - for (File inDir : inDirs) { - for (String fileName : inDir.list()) { - String ext = FilenameUtils.getExtension(fileName); - if (ext.equals(appiconset)) { - appIconSetName = FilenameUtils.getBaseName(fileName); - } else if (ext.equals(launchimage)) { - launchImagesName = FilenameUtils.getBaseName(fileName); + boolean launchImagesNameByArgs = false; + boolean includeAllAppIcons = false; + + // pick values from config of robovm.xml + if (config.getTools() != null && config.getTools().getActool() != null) { + ActoolOptions options = config.getTools().getActool(); + opts.addAll(options.getArguments()); + // if "--app-icon" specified in arguments will not use iconName option or look up for asset + appIconSetNameByArgs = opts.contains("--app-icon"); + // if "--launch-image" specified in arguments will not use launchImagesName option or look up for asset + launchImagesNameByArgs = opts.contains("--launch-image"); + // pick other options + includeAllAppIcons = options.shouldIncludeAllAppIcons(); + appIconSetName = appIconSetNameByArgs ? null : options.getAppIconName(); + launchImagesName = launchImagesNameByArgs ? null: options.getLaunchImageName(); + } + + // look for icon and launch image sets if not specified by config + // these options might be provided also in argument list. do lookup only if required + List availableIcons = appIconSetName == null && !appIconSetNameByArgs ? new ArrayList<>() : null; + List availableImages = launchImagesName == null && !launchImagesNameByArgs ? new ArrayList<>() : null; + if (availableIcons != null || availableImages != null) { + final String appiconset = "appiconset"; + final String launchimage = "launchimage"; + + for (File inDir : inDirs) { + for (String fileName : inDir.list()) { + String ext = FilenameUtils.getExtension(fileName); + if (ext.equals(appiconset)) { + if (availableIcons != null) + availableIcons.add(FilenameUtils.getBaseName(fileName)); + } else if (ext.equals(launchimage)) { + if (availableImages != null) + availableImages.add(FilenameUtils.getBaseName(fileName)); + } } } - } - if (appIconSetName != null || launchImagesName != null) { - if (appIconSetName != null) { - opts.add("--app-icon"); - opts.add(appIconSetName); + + // pick values + if (availableIcons != null && availableIcons.size() >= 1) { + appIconSetName = availableIcons.get(0); + if (availableIcons.size() > 1) + config.getLogger().error("actool: multiple .appiconset found but %s will be used", appIconSetName); } - if (launchImagesName != null) { - opts.add("--launch-image"); - opts.add(launchImagesName); + if (availableImages != null && availableImages.size() >= 1) { + launchImagesName = availableImages.get(0); + if (availableImages.size() > 1) + config.getLogger().error("actool: multiple .launchimage found but %s will be used", launchImagesName); } + } + if (appIconSetName != null) { + opts.add("--app-icon"); + opts.add(appIconSetName); + appIconSetNameByArgs = true; + } + if (launchImagesName != null) { + opts.add("--launch-image"); + opts.add(launchImagesName); + launchImagesNameByArgs = true; + } + + if (appIconSetNameByArgs || launchImagesNameByArgs) { opts.add("--output-partial-info-plist"); opts.add(partialInfoPlist); } + if (includeAllAppIcons) { + opts.add("--include-all-app-icons"); + } + opts.add("--platform"); if (IOSTarget.isDeviceArch(config.getArch())) { opts.add("iphoneos");