Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
adds preserveEnvironment setting (#790)
Browse files Browse the repository at this point in the history
* adds `preserveEnvironment` setting
* Fix tests

Thanks @johnspackman !
  • Loading branch information
johnspackman authored Jan 18, 2021
1 parent ac88fe8 commit c204d0f
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"translation": "source/translation"
},
"requires": {
"@qooxdoo/framework": "^6.0.0-alpha",
"@qooxdoo/framework": "^6.0.0-beta",
"@qooxdoo/compiler": "^1.0.0-beta"
}
}
19 changes: 13 additions & 6 deletions bootstrap-compiler
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ const utils = require("./bin/tools/utils");
const fs = require("fs");

(async function() {
let version = process.argv[2];
if (!version) {
version = require("./package.json").version;
}
let upgradeFramework = false;
if (process.argv.length > 2) {
if (process.argv[2] == "--upgrade-framework") {
let version = null;
for (let i = 2; i < process.argv.length; i++) {
let arg = process.argv[i];
if (arg == "--upgrade-framework") {
upgradeFramework = true;
} else if (arg.startsWith("--")) {
console.error("Invalid argument " + arg);
} else {
version = arg;
}
}

if (!version) {
version = require("./package.json").version;
}

await utils.bootstrapCompiler(version, upgradeFramework);
process.exit(0);
})();
Expand Down
6 changes: 6 additions & 0 deletions source/class/qx/tool/cli/Cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ qx.Class.define("qx.tool.cli.Cli", {
default: false,
type: "boolean"
})
.option("debug", {
describe: "enables debug output",
default: false,
type: "boolean"
})
.option("quiet", {
alias: "q",
describe: "suppresses normal progress output to console",
Expand Down Expand Up @@ -126,6 +131,7 @@ Versions: @qooxdoo/compiler v${qx.tool.compiler.Version.VERSION}
let yargs = this.__createYargs()
.usage(title);
this.argv = yargs.argv;
qx.tool.cli.LogAppender.setMinLevel(this.argv.debug ? "debug" : "warn");
},

/**
Expand Down
3 changes: 0 additions & 3 deletions source/class/qx/tool/cli/commands/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ qx.Class.define("qx.tool.cli.commands.Command", {
construct: function(argv) {
this.base(arguments);
this.argv = argv;
if (argv.verbose) {
qx.tool.cli.LogAppender.setMinLevel("debug");
}
},

properties: {
Expand Down
3 changes: 3 additions & 0 deletions source/class/qx/tool/cli/commands/Compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,9 @@ Framework: v${await this.getUserQxVersion()} in ${await this.getUserQxPath()}`);
if (targetConfig.environment) {
target.setEnvironment(targetConfig.environment);
}
if (targetConfig.preserveEnvironment) {
target.setPreserveEnvironment(targetConfig.preserveEnvironment);
}

if (data["path-mappings"]) {
for (var from in data["path-mappings"]) {
Expand Down
25 changes: 18 additions & 7 deletions source/class/qx/tool/compiler/makers/AppMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ qx.Class.define("qx.tool.compiler.makers.AppMaker", {
*/
async make() {
var analyser = this.getAnalyser();
let target = this.getTarget();

await this.fireEventAsync("making");
this.setSuccess(null);
Expand All @@ -84,8 +85,17 @@ qx.Class.define("qx.tool.compiler.makers.AppMaker", {
"qx.compiler.version": qx.tool.compiler.Version.VERSION
},
this.getEnvironment(),
this.getTarget().getDefaultEnvironment(),
this.getTarget().getEnvironment());
target.getDefaultEnvironment(),
target.getEnvironment());

let preserve = target.getPreserveEnvironment();
if (preserve) {
let tmp = {};
preserve.forEach(key => tmp[key] = true);
preserve = tmp;
} else {
preserve = {};
}

let appEnvironments = {};
this.getApplications().forEach(app => {
Expand Down Expand Up @@ -113,7 +123,9 @@ qx.Class.define("qx.tool.compiler.makers.AppMaker", {
this.getApplications().forEach(app => {
let env = appEnvironments[app.toHashCode()];
Object.keys(allAppEnv).forEach(key => {
if (allAppEnv[key].same) {
if (preserve[key]) {
env[key] = compileEnv[key];
} else if (allAppEnv[key].same) {
delete env[key];
} else if (env[key] === undefined) {
env[key] = compileEnv[key];
Expand All @@ -123,7 +135,7 @@ qx.Class.define("qx.tool.compiler.makers.AppMaker", {

// Cleanup to remove env that have been moved to the app
Object.keys(allAppEnv).forEach(key => {
if (allAppEnv[key].same) {
if (!preserve[key] && allAppEnv[key].same) {
compileEnv[key] = allAppEnv[key].value;
} else {
delete compileEnv[key];
Expand All @@ -142,9 +154,9 @@ qx.Class.define("qx.tool.compiler.makers.AppMaker", {
await qx.tool.utils.Utils.promisifyThis(analyser.initialScan, analyser);
await analyser.updateEnvironmentData();

this.getTarget().setAnalyser(analyser);
target.setAnalyser(analyser);
this.__applications.forEach(app => app.setAnalyser(analyser));
await this.getTarget().open();
await target.open();

if (this.isOutputTypescript()) {
analyser.getLibraries().forEach(library => {
Expand All @@ -169,7 +181,6 @@ qx.Class.define("qx.tool.compiler.makers.AppMaker", {
await analyser.analyseClasses();

await analyser.saveDatabase();
var target = this.getTarget();
await this.fireEventAsync("writingApplications");

// Detect which applications need to be recompiled by looking for classes recently compiled
Expand Down
14 changes: 12 additions & 2 deletions source/class/qx/tool/compiler/targets/Target.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ qx.Class.define("qx.tool.compiler.targets.Target", {
inheritable: true,
nullable: true
},

/**
* List of environment keys to preserve in code, ie reserve for runtime detection
* and exclude from code elimination
*/
preserveEnvironment: {
init: null,
nullable: true,
check: "Array"
},

/**
* The analyser being generated
Expand Down Expand Up @@ -181,7 +191,7 @@ qx.Class.define("qx.tool.compiler.targets.Target", {

/** @type {qx.tool.compiler.targets.meta.ApplicationMeta} for the current application */
__appMeta: null,

/**
* Initialises the target, creating directories etc
*/
Expand All @@ -203,7 +213,7 @@ qx.Class.define("qx.tool.compiler.targets.Target", {
}
return value;
},

/**
* Returns the root for applications
*/
Expand Down
7 changes: 7 additions & 0 deletions source/resource/qx/tool/schema/compile-1-0-0.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@
"environment": {
"$ref": "#/properties/environment"
},
"preserveEnvironment": {
"description": "a list of environment settings that will be ignored for code elimination, ie settings which *must* be configured at runtime",
"type": "array",
"items": {
"type": "string"
}
},
"writeCompileInfo": {
"description": "if true, the target will write a compile-info.json and resources.json into the application's output directory, containing the data structures required to generate an application",
"type":"boolean"
Expand Down
5 changes: 4 additions & 1 deletion test/compiler/test-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ async function createMaker() {
environment: {
envVar1: "ONE",
envVar2: "TWO",
runtimeVar: "RUNTIMEVAR",
"test.overridden4": "target",
"test.overridden5": "target"
}
},
preserveEnvironment: [ "runtimeVar" ]
}),
locales: ["en"],
writeAllTranslations: true,
Expand Down Expand Up @@ -280,6 +282,7 @@ test("Checks dependencies and environment settings", assert => {
assert.ok(src.match(/var envVar2 = "222"/), "environment setting for envVar2");
assert.ok(src.match(/var envVar3 = qx.core.Environment.get\("envVar3"\)/), "environment setting for envVar3");
assert.ok(src.match(/var envVar4 = "four"/), "environment setting for envVar4");
assert.ok(src.match(/var runtimeVar = qx.core.Environment.get/), "environment setting for runtimeVar");
assert.ok(src.match(/var envTestOverriden3 = "global"/), "environment setting for envTestOverriden3");
assert.ok(src.match(/var envTestOverriden4 = "target"/), "environment setting for envTestOverriden4");
assert.ok(src.match(/var envTestOverriden5 = "application"/), "environment setting for envTestOverriden5");
Expand Down
1 change: 1 addition & 0 deletions test/compiler/testapp/source/class/testapp/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ qx.Class.define("testapp.Application", {
var envVar2 = qx.core.Environment.get("envVar2");
var envVar3 = qx.core.Environment.get("envVar3");
var envVar4 = qx.core.Environment.get("envVar4");
var runtimeVar = qx.core.Environment.get("runtimeVar");
var envTestOverriden3 = qx.core.Environment.get("test.overridden3");
var envTestOverriden4 = qx.core.Environment.get("test.overridden4");
var envTestOverriden5 = qx.core.Environment.get("test.overridden5");
Expand Down

0 comments on commit c204d0f

Please sign in to comment.