Skip to content

Commit 7f47fc1

Browse files
authored
Add a resolveEnvVars option to .zap package.pathRelativity (project-chip#891)
This allows variables like $CHIP_ROOT to be used, which is needed when the chip codebase is a submodule of the repository the zap file is in. Throw an error when any variable used fails resolving.
1 parent 33d2bae commit 7f47fc1

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src-electron/util/util.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,16 @@ function createAbsolutePath(relativePath, relativity, zapFilePath) {
444444
return path.join(os.homedir(), relativePath)
445445
case dbEnum.pathRelativity.relativeToZap:
446446
return path.join(path.dirname(zapFilePath), relativePath)
447+
case dbEnum.pathRelativity.resolveEnvVars:
448+
for (let key in process.env) {
449+
if (Object.prototype.hasOwnProperty.call(process.env, key)) {
450+
relativePath = relativePath.replaceAll('$' + key, process.env[key])
451+
relativePath = relativePath.replaceAll('${' + key + '}', process.env[key])
452+
}
453+
}
454+
if (relativePath.indexOf('$') !== -1) {
455+
throw new Error('resolveEnvVars: unable to resolve environment variables completely: ' + relativePath)
456+
}
447457
}
448458
return relativePath
449459
}

src-shared/db-enum.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ exports.pathRelativity = {
8484
relativeToZap: 'relativeToZap',
8585
relativeToUserHome: 'relativeToHome',
8686
absolute: 'absolute',
87+
resolveEnvVars: 'resolveEnvVars',
8788
}
8889

8990
exports.wsCategory = {

0 commit comments

Comments
 (0)