-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using consistence function for environment set and get to fix the gap between windows and unix. #1763
Conversation
e42c865
to
b96cbe0
Compare
Thanks @lygstate! We'll take a look at this for 1.8. |
21aada3
to
ffcfe24
Compare
dd568f4
to
4cafa84
Compare
); | ||
return env; | ||
} | ||
private _kitEnvironmentVariables: proc.EnvironmentVariables = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UPDATE: We just updated the coding guidelines. You don't have to follow the new guideline for this PR. We will start applying it for the upcoming PRs :)
....
the plan is not to use _
anymore, I know you didn't name this property, but as you are touching it, that would be good to rename it at the end.
That would be great to apply the new naming guidelines for the rest of the PR as well: https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I touched too much variable with leading _, I think it's better to apply the naming guidelines with a single short, maybe by the lint rules, otherwise it's would get the code hard to review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, it's easier if we start applying new guidelines in future PRs.
} | ||
|
||
/** | ||
* Get the environment variables that should be set at CMake-build time. | ||
*/ | ||
async getCMakeBuildCommandEnvironment(in_env: proc.EnvironmentVariables): Promise<proc.EnvironmentVariables> { | ||
let envs: proc.EnvironmentVariables; | ||
const envs_to_merge: (proc.EnvironmentVariables | undefined)[] = [in_env]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution.
Would you please provide some explanation on why mergeEnvironmentWithExpand
is needed here?
There is a mergeEnvironment
and splitEnvironmentVars
and computeExpandedEnvironment
, and it is a little confusing having another function. We can add more comments/samples like what you did for mergeEnvironmentWithExpand
to add some clarity, or choose some more clear names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/**
* mergeEnvironmentWithExpand will merge new env variable and
* expand it one by one, so that the environment like this
* will expand properly:
* config.environment
* { PATH:`${env.PATH};C:\\MinGW\\bin` }
* config.configureEnvironment
* { PATH:`${env.PATH};C:\\OtherPath\\bin` }
*
* @param intermediateExpand If this is the intermediate expanding
* procedure or the final expanding procedure, if it's the
* intermediate expanding procedure, the variable that not found
* won't not expaned, if it's the final expanding procedure, the variable
* that not found would expand to ''.
* @param envs The list of environment variables to expand
* @param opts Environment expand options
*
* NOTE: By mergeEnvironment one by one to enable expanding self
* containd variable such as PATH properly. If configureEnvironment
* and environment both configured different PATH, doing this will
* preserve them all
*/
export async function mergeEnvironmentWithExpand(
intermediateExpand: boolean,
envs: (EnvironmentVariables | undefined)[],
opts?: ExpansionOptions)
I've document it in mergeEnvironmentWithExpand, don't know if the function name is proper, looking for better name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate if you could add some comments/samples to mergeEnvironment
and splitEnvironmentVars
and computeExpandedEnvironment
, similar to what you did for mergeEnvironmentWithExpand
to add some clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't touch and use of splitEnvironmentVars, other functions are documented
c3eda93
to
f318283
Compare
gap between windows and unix. Directly use configureEnv, as now getConfigureEnvironment would not return environment with undefined/null value Also expand with environment variable when get effectiveKitEnvironment Fixes microsoft#1592 preset using the same environment variable merge strategy like kits does Using GeneralEnvironmentType Signed-off-by: Yonggang Luo <[email protected]>
ec0fe5e
to
a4dec6a
Compare
Hope this can be merged in 1.8, as it fixes a lot of issues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names of these new functions and the way we access the environment seem a little weird now. I wouldn't think to go to util
to get environment values. I think it would be better if we had an environment
or env
module that managed all of this.
Accessing the process.env
directly should be ok. process.env
looks up environment variables in a case-insensitive way on Windows which should be faster than the new function. The real problem is with the proc.EnvironmentVariables
type which does not do the same thing. There is also new expansion behavior added that seems it should be in a separate PR. I would prefer for this PR to scale back the changes and focus on the problem with accessing variables in proc.EnvironmentVariables
. I worry that the changes proposed are risky for 1.8 given that we want to release it soon.
* @param expectKey The environment key | ||
* @return [key, value] pair of the found environment item or undefined when not found | ||
*/ | ||
export function envGet( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comment for function signatures is to put all the arguments and return type on the same line if they fit comfortably. It looks inconsistent to put each argument and return type on its own line here.
export function envGet( | ||
env: GeneralEnvironmentType, | ||
expectKey: string | ||
): [string, string] | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer that you define an interface for this instead of using a pair. Interfaces let you name the fields which makes reading the code easier later on. Anyplace where you use [0]
I have to go back to the comment for this function and figure out what that means. Alternately, if it's .key
, then there is no confusion.
* @param expectKey The environment key | ||
* @return [key, value] pair of the found environment item or undefined when not found | ||
*/ | ||
export function envGet( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on what I see, this function does not need to be exported. It might also make sense to rename it envGetKeyValue
to disambiguate it better.
if (env instanceof Map) { | ||
return find(env.entries(), ([key, _val]) => envKeyEqualWin32(key, expectKey)); | ||
} else { | ||
for (const key of Object.keys(env)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels really inefficient to loop through all keys anytime you want to access a value. process.env
should accept the key in a case-insensitive way -- the problem seems to be with the EnvironmentVariables
type which is just an object. I think the better route is to make EnvironmentVariables
a class and normalize how variables are inserted so that lookup is trivial. That might be a more involved change though.
export async function computeExpandedEnvironment( | ||
in_env: EnvironmentVariables, | ||
expanded_env: EnvironmentVariables, | ||
intermediateExpand: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename intermediateExpand
to ignoreUnknownVars
? I think that better conveys the meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good name, thanks
It's OK to merge this in 1.9, I'll apply your suggestions |
I didn't finish this prototype -- it doesn't compile yet. But it's kind of what I was thinking for more consistent access to the environment. Draft PR: #2025 |
OK, would you implement this or I can reference your draft and re-implement this PR |
Because I manage a lot of projects, I don't always have time to work on it. If you would like to complete this, that would be the fastest path. |
Sorry, it's a accident close |
This appears to have been closed automatically because we deleted the 'develop' branch in favor of working directly in 'main'. Draft PR: #2025 has been retargeted to 'main'. |
Fixes
#1592
Signed-off-by: Yonggang Luo [email protected]