Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Natoandro committed Aug 22, 2024
1 parent db40575 commit a81dba4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 3 additions & 2 deletions examples/kitchen/ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ env("python")
ports.cpy_bs({ version: "3.8.18", releaseTag: "20240224" }),
ports.tar(),
ports.zstd(),
);
)
.mixin(pyEnv());

env("dev")
// we can inherit from many envs
Expand All @@ -123,4 +124,4 @@ env("dev")
}));

env("venv")
.mixin(pyEnv({ install: { version: "3.8.18", releaseTag: "20240224" } }));
.inherit(["python"]);
25 changes: 24 additions & 1 deletion files/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class Ghjkfile {
finalized: ReturnType<EnvFinalizer>;
installSetId?: string;
vars: Record<string, string>;
dynVars: Record<string, string>;
envHash: string;
}
> = {};
Expand Down Expand Up @@ -415,6 +416,7 @@ export class Ghjkfile {

#mergeEnvs(keys: string[], childName: string) {
const mergedVars = {} as Record<string, [string, string] | undefined>;
const mergedDynVars = {} as Record<string, [string, string] | undefined>;
let mergedInstalls = new Set<string>();
const mergedOnEnterHooks = [];
const mergedOnExitHooks = [];
Expand All @@ -423,7 +425,12 @@ export class Ghjkfile {
[string, string] | undefined
>;
for (const parentName of keys) {
const { vars, installSetId, finalized } = this.#finalizedEnvs[parentName];
const {
vars,
dynVars,
installSetId,
finalized,
} = this.#finalizedEnvs[parentName];
mergedOnEnterHooks.push(...finalized.onEnterHookTasks);
mergedOnExitHooks.push(...finalized.onExitHookTasks);
for (const [key, val] of Object.entries(vars)) {
Expand All @@ -443,6 +450,22 @@ export class Ghjkfile {
}
mergedVars[key] = [val, parentName];
}

for (const [key, val] of Object.entries(dynVars)) {
const conflict = mergedDynVars[key];
if (conflict && val !== conflict[0]) {
logger.warn(
"dynamic environment variable conflict on multiple env inheritance, parent2 was chosen",
{
child: childName,
parent1: conflict[1],
parent2: parentName,
variable: key,
},
);
}
mergedDynVars[key] = [val, parentName];
}
if (!installSetId) {
continue;
}
Expand Down

0 comments on commit a81dba4

Please sign in to comment.