-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve internal merging of app/extension manifests #260
Conversation
# Conflicts: # server/src/main/java/com/defold/extender/Extender.java
@@ -88,6 +88,21 @@ class Extender { | |||
private static final String MANIFEST_ANDROID= "AndroidManifest.xml"; | |||
private static final String MANIFEST_HTML5 = "engine_template.html"; | |||
|
|||
|
|||
// Check that the manifest only contains valid platforms | |||
private final String[] ALLOWED_MANIFEST_PLATFORMS = new String[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from below
// Merge the platform configs from build.yml into a single instance: common -> platform -> arch-platform | ||
this.platformConfig = new PlatformConfig(); | ||
this.platformConfig.context = new HashMap<>(config.context); // the context from build.yml | ||
|
||
for (String platformAlt : ExtenderUtil.getPlatformAlternatives(platform)) { | ||
PlatformConfig platformConfigAlt = config.platforms.get(platformAlt); | ||
if (platformConfigAlt == null) | ||
continue; | ||
|
||
ExtenderUtil.mergeObjects(this.platformConfig, platformConfigAlt); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example where we merge each file (e.g. build.yml) using all the platform names in order:
- common
- win32
- x86_64-win32
this.platformVariantConfig = new PlatformConfig(); | ||
if (baseVariantManifest != null) { | ||
for (String platformAlt : ExtenderUtil.getPlatformAlternatives(platform)) { | ||
AppManifestPlatformConfig configAlt = baseVariantManifest.platforms.get(platformAlt); | ||
if (configAlt == null) | ||
continue; | ||
PlatformConfig platformConfigAlt = ExtenderUtil.createPlatformConfig(configAlt); | ||
ExtenderUtil.mergeObjects(this.platformVariantConfig, platformConfigAlt); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the variants, e.g. release.appmanifest
// Merge the app manifest info into a single config | ||
this.platformAppConfig = new PlatformConfig(); | ||
for (String platformAlt : ExtenderUtil.getPlatformAlternatives(platform)) { | ||
AppManifestPlatformConfig configAlt = appManifest.platforms.get(platformAlt); | ||
if (configAlt == null) { | ||
continue; | ||
} | ||
|
||
PlatformConfig platformConfigAlt = ExtenderUtil.createPlatformConfig(configAlt); | ||
ExtenderUtil.mergeObjects(this.platformAppConfig, platformConfigAlt); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, finally, the game.appmanifest
|
||
resolveVariables(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually, I think we want to delay as long as possible.
I.e. until the point where it's needed, just before e.g. invoking the command.
public static PlatformConfig createPlatformConfig(AppManifestPlatformConfig appconfig) throws ExtenderException { | ||
PlatformConfig config = new PlatformConfig(); | ||
config.context = mergeMaps(config.context, appconfig.context); | ||
return config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we operate on PlatformConfig, we needed an easy convert function.
String result = Mustache.compiler().compile(template).execute(context); | ||
while (!result.equals(template)) { | ||
template = result; | ||
result = Mustache.compiler().compile(template).execute(context); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A problem we previously had was that if one variable contained another expression, we couldn't resolve that:
env:
a: "foo"
b: "{{env.a}}"
c: "{{env.b}}"
@@ -28,7 +33,7 @@ public List<String> execute(List<String> templates, Map<String, Object> context) | |||
List<String> out = new ArrayList<>(); | |||
for (String template : templates) { | |||
try { | |||
out.add(Mustache.compiler().compile(template).execute(context)); | |||
out.add(this.execute(template, context)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the internal function that resolves recursively.
@@ -355,6 +356,60 @@ public void testAppManifestContext() throws IOException, ExtenderException { | |||
assertEquals( expectedItems, context.get("flags") ); | |||
} | |||
|
|||
@Test | |||
public void testMergedContexts() throws IOException, ExtenderException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test for my actual use case (removing profiler libraries)
if (!this.cacheClearOnExit) { | ||
LOGGER.info("Skipping cleanup of SDK cache"); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By not deleting the cache, the local tests should go faster, by not having to download the sdk's all the time.
The problem was that the merging/overrides was done in an unintuitive manner.
Now, most of the merging code was moved to the
Extender.loadManifests()
function which is called at the start of the job.The issue at hand was that we needed to override (and exclude) some engine libraries (for the profiler), but the previous way of merging happened too late.
At later stages, the build steps may use the extension or app context to replace environment variables accordingly.