Skip to content
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

Merged
merged 15 commits into from
Mar 8, 2023

Conversation

JCash
Copy link
Contributor

@JCash JCash commented Mar 6, 2023

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.

@@ -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[] {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from below

Comment on lines +193 to +203
// 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);
}
Copy link
Contributor Author

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

Comment on lines +206 to +215
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);
}
}
Copy link
Contributor Author

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

Comment on lines +217 to +227
// 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);
}
Copy link
Contributor Author

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);
Copy link
Contributor Author

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.

Comment on lines +586 to +589
public static PlatformConfig createPlatformConfig(AppManifestPlatformConfig appconfig) throws ExtenderException {
PlatformConfig config = new PlatformConfig();
config.context = mergeMaps(config.context, appconfig.context);
return config;
Copy link
Contributor Author

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.

Comment on lines +19 to +23
String result = Mustache.compiler().compile(template).execute(context);
while (!result.equals(template)) {
template = result;
result = Mustache.compiler().compile(template).execute(context);
}
Copy link
Contributor Author

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));
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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)

Comment on lines +215 to +218
if (!this.cacheClearOnExit) {
LOGGER.info("Skipping cleanup of SDK cache");
return;
}
Copy link
Contributor Author

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.

@JCash JCash requested a review from britzl March 8, 2023 08:27
@JCash JCash merged commit 8836ff0 into dev Mar 8, 2023
@JCash JCash deleted the exclude-variant-args-fix branch March 8, 2023 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants