Skip to content

Commit a3a9dba

Browse files
authored
Do not inject targetversion when using "pxt build" (microsoft#4367)
* removing emitting targetversion * inject version in default project * more logging when writing files in build * removed unused code * hide being flag / fix debug output * tweak logging * revert targetversion override
1 parent d02966b commit a3a9dba

7 files changed

Lines changed: 99 additions & 77 deletions

File tree

.vscode/launch.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,26 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "DebugBuild",
5+
"name": "DebugBuildTarget",
6+
"type": "node",
7+
"request": "launch",
8+
"program": "${workspaceRoot}/built/pxt.js",
9+
"stopOnEntry": false,
10+
"args": ["buildtarget"],
11+
"cwd": "${workspaceRoot}/../pxt-adafruit",
12+
"runtimeExecutable": null,
13+
"runtimeArgs": [
14+
"--nolazy"
15+
],
16+
"env": {
17+
"NODE_ENV": "development"
18+
},
19+
"console": "integratedTerminal",
20+
"sourceMaps": false,
21+
"outFiles": []
22+
},
23+
{
24+
"name": "DebugBuildPackage",
625
"type": "node",
726
"request": "launch",
827
"program": "${workspaceRoot}/built/pxt.js",

cli/buildengine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export function buildHexAsync(buildEngine: BuildEngine, mainPkg: pxt.MainPackage
203203
if (fs.existsSync(fn))
204204
existing = fs.readFileSync(fn, "utf8")
205205
if (existing !== v)
206-
fs.writeFileSync(fn, v)
206+
nodeutil.writeFileSync(fn, v)
207207
})
208208
}
209209

cli/cli.ts

Lines changed: 54 additions & 61 deletions
Large diffs are not rendered by default.

cli/commandparser.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export class CommandParser {
9696

9797
for (let i = 1; i < args.length; i++) {
9898
const match = argRegex.exec(args[i]);
99-
10099
if (!match) {
101100
continue;
102101
}
@@ -107,15 +106,16 @@ export class CommandParser {
107106
}
108107

109108
const flagName = command._aliasMap[match[2]];
110-
111-
if (!flagName) {
112-
if (match[2] == "debug" || match[2] == "d") {
113-
pxt.options.debug = true;
114-
pxt.debug = console.log;
109+
const debugFlag = flagName || match[2];
110+
if (debugFlag == "debug" || debugFlag == "d" || debugFlag == "dbg") {
111+
pxt.options.debug = true;
112+
pxt.debug = console.log;
113+
pxt.log(`debug mode`);
114+
if (!flagName)
115115
continue;
116-
}
117-
throw new Error(`Unrecognized flag '${match[2]}' for command '${command.name}'`)
118116
}
117+
if (!flagName)
118+
throw new Error(`Unrecognized flag '${match[2]}' for command '${command.name}'`)
119119

120120
const flagDefinition = command.flags[flagName];
121121

cli/nodeutil.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ export function readPkgConfig(dir: string) {
276276
}
277277
}
278278
}
279-
if (!js.targetVersions) js.targetVersions = pxt.appTarget.versions;
279+
// don't inject version number
280+
// as they get serialized later on
281+
// if (!js.targetVersions) js.targetVersions = pxt.appTarget.versions;
280282
return js
281283
}
282284

@@ -355,6 +357,14 @@ export function existsDirSync(name: string): boolean {
355357
}
356358
}
357359

360+
export function writeFileSync(path: string, data: any, options?: { encoding?: string | null; mode?: number | string; flag?: string; } | string | null) {
361+
fs.writeFileSync(path, data, options);
362+
if (pxt.options.debug) {
363+
const stats = fs.statSync(path);
364+
pxt.log(` + ${path} ${stats.size > 1000000 ? (stats.size / 1000000).toFixed(2) + ' m' : stats.size > 1000 ? (stats.size / 1000).toFixed(2) + 'k' : stats.size}b`)
365+
}
366+
}
367+
358368
export function openUrl(startUrl: string, browser: string) {
359369
if (!/^[a-z0-9A-Z#=\.\-\\\/%:\?_&]+$/.test(startUrl)) {
360370
console.error("invalid URL to open: " + startUrl)

cli/pyconv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ export function convertAsync(fns: string[]) {
19551955
.then(buf => {
19561956
pxt.debug(`analyzing python AST (${buf.length} bytes)`)
19571957
let js = JSON.parse(buf.toString("utf8"))
1958-
fs.writeFileSync("pyast.json", JSON.stringify(js, null, 2), { encoding: "utf8" })
1958+
nodeutil.writeFileSync("pyast.json", JSON.stringify(js, null, 2), { encoding: "utf8" })
19591959
const rec = (v: any): any => {
19601960
if (Array.isArray(v)) {
19611961
for (let i = 0; i < v.length; ++i)

pxtlib/package.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,12 @@ namespace pxt {
412412
if (isInstall)
413413
initPromise = initPromise.then(() => this.downloadAsync())
414414

415-
initPromise = initPromise.then(() => {
416-
if (this.level == 0) {
415+
if (isInstall && this.level == 0)
416+
initPromise = initPromise.then(() => {
417417
pxt.debug(`upgrading files, target version ${this.targetVersion()}`)
418418
this.getFiles().filter(fn => /\.ts$/.test(fn))
419419
.forEach(file => this.upgradeFile(file, this.readFile(file)));
420-
}
421-
})
420+
})
422421

423422
if (appTarget.simulator && appTarget.simulator.dynamicBoardDefinition) {
424423
if (this.level == 0)
@@ -759,6 +758,7 @@ namespace pxt {
759758
let cfg = U.clone(this.config)
760759
delete cfg.installedVersion
761760
delete cfg.additionalFilePath
761+
if (!cfg.targetVersions) cfg.targetVersions = pxt.appTarget.versions;
762762
U.iterMap(cfg.dependencies, (k, v) => {
763763
if (!v || /^file:/.test(v) || /^workspace:/.test(v)) {
764764
cfg.dependencies[k] = "*"

0 commit comments

Comments
 (0)