Skip to content

Prevent build scripts from letting random values through #35642

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

Merged
merged 9 commits into from
May 13, 2020
Merged

Prevent build scripts from letting random values through #35642

merged 9 commits into from
May 13, 2020

Conversation

ivdiazsa
Copy link
Contributor

Fixes #35222 and a few more things.

The runtime repo's build scripts, build.cmd and build.sh, were allowing random values through certain flags, such as --os, --arch, and --configuration. This caused certain tasks prior to building like restoring projects to trigger, giving the user a false sense of security that it would work. However, later on, the build would obviously fail. The error messages shown would be entirely unrelated and therefore the user couldn't know what went wrong. This was a common scenario due to typos.

With this PR, invalid values to these flags are immediately called out to the user, alongside a suggestion on which arguments are valid for the given flag. This in turn prevents loss of time waiting for the eventual build failure.

As a follow up to improve the experience with these scripts, the letter casing restrictions in the Linux script (build.sh) have been removed. Users can now type --os LINUX or --os linux for example, and it will work. The casing stuff is now managed internally. Also, --runtimeConfiguration and --librariesConfiguration were fixed as well.

@ghost
Copy link

ghost commented Apr 30, 2020

Tagging subscribers to this area: @ViktorHofer
Notify danmosemsft if you want to be subscribed.

passedConfig="$(echo "$2" | awk '{print tolower($0)}')"
case "$passedConfig" in
debug|release|checked)
val="$(tr '[:lower:]' '[:upper:]' <<< ${passedConfig:0:1})${passedConfig:1}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit - you can avoid this double transformation (once using awk and then using tr) by just keeping the original command and then passing the val to case and checking for Debug, Release and Checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean by converting all to lowercase and then the first one to uppercase in the same command? I ask this because the tr command in val changes the first letter to uppercase, but leaves the rest untouched. That's why I'm using awk beforehand to convert everything to lowercase beforehand, in order to allow input like "RELEASE" to be valid. I'm removing the casing restrictions on the Linux scripts, aside from fixing the problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, I've misread the tr command.

Copy link
Member

@trylek trylek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for making our scripts more robust!

arch=$2
passedArch="$(echo "$2" | awk '{print tolower($0)}')"
case "$passedArch" in
x64|x86|arm|armel|arm64|wasm)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional that armel is missing in build.ps1 above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is, as there is no armel flavor of Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I followed the help command when adding these validations. Thanks for the clarification Jan!

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@ivdiazsa ivdiazsa merged commit 7c66b6f into dotnet:master May 13, 2020
@ivdiazsa ivdiazsa deleted the build_gateways branch May 13, 2020 01:59
@ivdiazsa ivdiazsa restored the build_gateways branch May 13, 2020 01:59
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Runtime build.cmd lets random values through
3 participants