diff --git a/cli/buildengine.ts b/cli/buildengine.ts index 7fa1ac0cc68a..c3b4182ad7a7 100644 --- a/cli/buildengine.ts +++ b/cli/buildengine.ts @@ -316,7 +316,7 @@ function msdDeployCoreAsync(res: ts.pxtc.CompileResult) { if (pxt.appTarget.serial && pxt.appTarget.serial.useHF2) { let f = res.outfiles[pxtc.BINARY_UF2] let blocks = pxtc.UF2.parseFile(U.stringToUint8Array(atob(f))) - return hid.hf2DeviceAsync() + return hid.initAsync() .then(dev => dev.flashAsync(blocks)) } diff --git a/cli/cli.ts b/cli/cli.ts index 638be8ec55f9..feab69093155 100644 --- a/cli/cli.ts +++ b/cli/cli.ts @@ -23,6 +23,7 @@ import * as commandParser from './commandparser'; import * as hid from './hid'; import * as serial from './serial'; import * as gdb from './gdb'; +import * as clidbg from './clidbg'; import * as pyconv from './pyconv'; const rimraf: (f: string, opts: any, cb: () => void) => void = require('rimraf'); @@ -1622,7 +1623,7 @@ function buildTargetCoreAsync() { .then(res => { cfg.bundledpkgs[path.basename(dirname)] = res }) - .then(testForBuildTargetAsync) + .then(() => testForBuildTargetAsync(isPrj)) .then((compileOpts) => { // For the projects, we need to save the base HEX file to the offline HEX cache if (isPrj && pxt.appTarget.compile.hasHex) { @@ -2604,7 +2605,7 @@ function testAssemblers(): Promise { } -function testForBuildTargetAsync(): Promise { +function testForBuildTargetAsync(useNative: boolean): Promise { let opts: pxtc.CompileOptions return mainPkg.loadAsync() .then(() => { @@ -2612,18 +2613,27 @@ function testForBuildTargetAsync(): Promise { let target = mainPkg.getTargetOptions() if (target.hasHex) target.isNative = true + if (!useNative) + target.isNative = false return mainPkg.getCompileOptionsAsync(target) }) .then(o => { opts = o opts.testMode = true opts.ast = true - return pxtc.compile(opts) + if (useNative) + return pxtc.compile(opts) + else { + pxt.log(" skip native build of non-project") + return null + } }) .then(res => { - reportDiagnostics(res.diagnostics); - if (!res.success) U.userError("Compiler test failed") - simulatorCoverage(res, opts) + if (res) { + reportDiagnostics(res.diagnostics); + if (!res.success) U.userError("Compiler test failed") + simulatorCoverage(res, opts) + } }) .then(() => opts); } @@ -3317,9 +3327,19 @@ function prepBuildOptionsAsync(mode: BuildOption, quick = false) { }) } +function dbgTestAsync() { + return buildCoreAsync({ + mode: BuildOption.JustBuild, + debug: true + }) + .then(clidbg.startAsync) +} + interface BuildCoreOptions { mode: BuildOption; + debug?: boolean; + // docs locs?: boolean; docs?: boolean; @@ -3327,16 +3347,22 @@ interface BuildCoreOptions { createOnly?: boolean; } -function buildCoreAsync(buildOpts: BuildCoreOptions): Promise { +function buildCoreAsync(buildOpts: BuildCoreOptions): Promise { let compileOptions: pxtc.CompileOptions; + let compileResult: pxtc.CompileResult; ensurePkgDir(); return prepBuildOptionsAsync(buildOpts.mode) .then((opts) => { compileOptions = opts; opts.breakpoints = buildOpts.mode === BuildOption.DebugSim; + if (buildOpts.debug) { + opts.breakpoints = true + opts.justMyCode = true + } return pxtc.compile(opts); }) .then((res): Promise => { + compileResult = res U.iterMap(res.outfiles, (fn, c) => { if (fn !== pxtc.BINARY_JS) { mainPkg.host().writeFile(mainPkg, "built/" + fn, c); @@ -3403,7 +3429,7 @@ function buildCoreAsync(buildOpts: BuildCoreOptions): Promise { - return compileOptions; + return compileResult; }); } @@ -4343,6 +4369,7 @@ function initCommands() { advancedCommand("testdir", "compile files in directory one by one", testDirAsync, ""); advancedCommand("testconv", "test TD->TS converter", testConverterAsync, ""); advancedCommand("testpkgconflicts", "tests package conflict detection logic", testPkgConflictsAsync); + advancedCommand("testdbg", "tests hardware debugger", dbgTestAsync); advancedCommand("buildtarget", "build pxtarget.json", buildTargetAsync); advancedCommand("uploadtrg", "upload target release", pc => uploadTargetAsync(pc.arguments[0]), "