Skip to content

Commit

Permalink
Allow for pxt.json:codal.libraries (#7402)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal authored Aug 25, 2020
1 parent b04c9dc commit 3180b0e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
5 changes: 5 additions & 0 deletions localtypings/pxtpackage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ declare namespace pxt {
paletteNames?: string[];
screenSize?: Size;
yotta?: YottaConfig;
codal?: CodalConfig;
npmDependencies?: Map<string>;
card?: CodeCard;
additionalFilePath?: string;
Expand Down Expand Up @@ -107,6 +108,10 @@ declare namespace pxt {
config: any;
}

interface CodalConfig {
libraries?: string[];
}

interface YottaConfig {
dependencies?: Map<string>;
config?: any;
Expand Down
30 changes: 28 additions & 2 deletions pxtlib/cpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,17 +830,35 @@ namespace pxt.cpp {
const currSettings: Map<any> = U.clone(compileService.yottaConfig || {})
const optSettings: Map<any> = {}
const settingSrc: Map<Package> = {}
const codalLibraries: pxt.Map<github.ParsedRepo> = {}

function parseJson(pkg: Package) {
let j0 = pkg.config.platformio
const j0 = pkg.config.platformio
if (j0 && j0.dependencies) {
U.jsonCopyFrom(res.platformio.dependencies, j0.dependencies)
}

if (res.npmDependencies && pkg.config.npmDependencies)
U.jsonCopyFrom(res.npmDependencies, pkg.config.npmDependencies)

let json = pkg.config.yotta
const codal = pkg.config.codal
if (isCodal && codal) {
for (const lib of codal.libraries || []) {
const repo = github.parseRepoId(lib)
if (!repo)
U.userError(lf("codal library {0} doesn't look like github repo", lib))
const canonical = github.stringifyRepo(repo)
const existing = U.lookup(codalLibraries, repo.project)
if (existing) {
if (github.stringifyRepo(existing) != canonical)
U.userError(lf("conflict between codal libraries: {0} and {1}", github.stringifyRepo(existing), canonical))
} else {
codalLibraries[repo.project] = repo
}
}
}

const json = pkg.config.yotta
if (!json) return;

// TODO check for conflicts
Expand Down Expand Up @@ -989,7 +1007,15 @@ namespace pxt.cpp {
// include these, because we use hash of this file to see if anything changed
"pxt_gitrepo": cs.githubCorePackage,
"pxt_gittag": cs.gittag,
"libraries": U.values(codalLibraries).map(r => ({
"name": r.project,
"url": "https://github.com/" + r.fullName,
"branch": r.tag || "master",
"type": "git"
}))
}
if (codalJson.libraries.length == 0)
delete codalJson.libraries
U.iterMap(U.jsonFlatten(configJson), (k, v) => {
k = k.replace(/^codal\./, "device.").toUpperCase().replace(/\./g, "_")
cfg[k] = v
Expand Down
2 changes: 1 addition & 1 deletion pxtlib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ namespace pxt.github {
export interface ParsedRepo {
owner?: string;
project?: string;
// owner/name
// owner/project (aka slug)
fullName: string;
tag?: string;
fileName?: string;
Expand Down

0 comments on commit 3180b0e

Please sign in to comment.