Skip to content

Commit

Permalink
Update the zcl and template packages during generation
Browse files Browse the repository at this point in the history
- Create a flag called --upgradeZapFile which can be passed during generation to update the package paths during generation. add this to apack.json
- During generation use the flag to determine if packages should be updated in the .zap file. If the .zap file does not already have the packages mentioned in generation(uc_generate) then the .zap file is updated with those packages and saved.
- JIRA: ZAPP-1456
  • Loading branch information
brdandu committed Oct 9, 2024
1 parent ce55106 commit 491187b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apack.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"cmd": "$(zap-cli) --version"
},
"uc_generate": {
"cmd": "$(zap-cli) generate --noUi --noServer -o ${generationOutput} --packageMatch fuzzy --zcl ${sdkRoot}/app/zcl/zcl-zap.json --zcl ${sdkRoot}/extension/matter_extension/src/app/zap-templates/zcl/zcl.json --generationTemplate ${sdkRoot}/protocol/zigbee/app/framework/gen-template/gen-templates.json --generationTemplate ${sdkRoot}/extension/matter_extension/src/app/zap-templates/app-templates.json --in ${contentFolder} --noLoadingFailure --appendGenerationSubdirectory"
"cmd": "$(zap-cli) generate --noUi --noServer -o ${generationOutput} --packageMatch fuzzy --zcl ${sdkRoot}/app/zcl/zcl-zap.json --zcl ${sdkRoot}/extension/matter_extension/src/app/zap-templates/zcl/zcl.json --generationTemplate ${sdkRoot}/protocol/zigbee/app/framework/gen-template/gen-templates.json --generationTemplate ${sdkRoot}/extension/matter_extension/src/app/zap-templates/app-templates.json --in ${contentFolder} --noLoadingFailure --appendGenerationSubdirectory --upgradeZapFile"
},
"uc_upgrade": {
"cmd": "$(zap-cli) upgrade --results ${results} -d ${tempContentFolder} --zcl ${sdkRoot}/app/zcl/zcl-zap.json --zcl ${sdkRoot}/extension/matter_extension/src/app/zap-templates/zcl/zcl.json --generationTemplate ${sdkRoot}/protocol/zigbee/app/framework/gen-template/gen-templates.json --generationTemplate ${sdkRoot}/extension/matter_extension/src/app/zap-templates/app-templates.json --noLoadingFailure"
Expand Down
71 changes: 70 additions & 1 deletion src-electron/main-process/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,55 @@ async function generateSingleFile(
let hrstart = process.hrtime.bigint()
let sessionId
let output
let upgradeZclPackages = []
let upgradeTemplatePackages = []
let isZapFileUpgradeNeeded = false

// Upgrade the .zap file with generation packages if the upgradeZapFile flag
// is passed during generation.
if (options.upgradeZapFile) {
let state = await importJs.readDataFromFile(zapFile)
let zapFileZclPackages = []
let zapFileTemplatePackages = []
for (let i = 0; i < state.package.length; i++) {
let zapFileDir = path.dirname(zapFile)
if (state.package[i].type == dbEnum.packageType.zclProperties) {
zapFileZclPackages.push(path.join(zapFileDir, state.package[i].path))
} else if (state.package[i].type == dbEnum.packageType.genTemplatesJson) {
zapFileTemplatePackages.push(
path.join(zapFileDir, state.package[i].path)
)
}
}
upgradeZclPackages = await getUpgradePackageMatch(
db,
options.zcl,
state.package,
dbEnum.packageType.zclProperties
)
upgradeTemplatePackages = await getUpgradePackageMatch(
db,
options.template,
state.package,
dbEnum.packageType.genTemplatesJson
)
for (let i = 0; i < upgradeZclPackages.length; i++) {
if (!zapFileZclPackages.includes(upgradeZclPackages[i].path)) {
isZapFileUpgradeNeeded = true
break
}
}
for (let i = 0; i < upgradeTemplatePackages.length; i++) {
if (!zapFileTemplatePackages.includes(upgradeTemplatePackages[i].path)) {
isZapFileUpgradeNeeded = true
break
}
}
if (isZapFileUpgradeNeeded) {
options.upgradeZclPackages = upgradeZclPackages
options.upgradeTemplatePackages = upgradeTemplatePackages
}
}
if (zapFile === BLANK_SESSION) {
options.logger(`👉 using empty configuration`)
sessionId = await querySession.createBlankSession(db)
Expand All @@ -754,7 +803,9 @@ async function generateSingleFile(
defaultZclMetafile: options.zcl,
postImportScript: options.postImportScript,
packageMatch: options.packageMatch,
defaultTemplateFile: options.template
defaultTemplateFile: options.template,
upgradeZclPackages: upgradeZclPackages,
upgradeTemplatePackages: upgradeTemplatePackages
})
sessionId = importResult.sessionId
output = outputFile(zapFile, outputPattern, index)
Expand Down Expand Up @@ -798,6 +849,23 @@ async function generateSingleFile(
genResults.push(genResult)
}

if (options.upgradeZapFile && isZapFileUpgradeNeeded) {
options.logger(
`🕐 Updating the zap file with the correct SDK meta data: ${zapFile}`
)
// Now we need to write the sessionKey for the file path
await querySession.updateSessionKeyValue(
db,
sessionId,
dbEnum.sessionKey.filePath,
zapFile
)

await exportJs.exportDataIntoFile(db, sessionId, zapFile, {
createBackup: true
})
}

return genResults
}

Expand Down Expand Up @@ -859,6 +927,7 @@ async function startGeneration(argv, options) {
options.appendGenerationSubdirectory = argv.appendGenerationSubdirectory
options.packageMatch = argv.packageMatch
options.generationLog = argv.generationLog
options.upgradeZapFile = argv.upgradeZapFile // Used to upgrade the zap file during generation.

let nsDuration = process.hrtime.bigint() - hrstart
options.logger(`🕐 Setup time: ${util.duration(nsDuration)} `)
Expand Down

0 comments on commit 491187b

Please sign in to comment.