Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Conversation

@Jerry-Shaw
Copy link
Contributor

When executing "cl.exe /? 2>&1" under some conditions, we may both get the output and a return value not to be 0.

For example: I install "VC++ 2017 v141 toolset (x86,x64)" and other necessary components without installing "VC++ 2015.3 v140 toolset for desktop (x86,x64)" in VS 2017, I will get an exception of "Couldn't execute cl.exe." when running "phpsdk_deps -u", because the return value is 2 somehow. But actually, the script gets the right output of the cl.exe version, which should keep it running.
Once "VC++ 2015.3 v140 toolset for desktop (x86,x64)" is installed, everything works fine.

Havn't tested it under more conditions, only mine.
My compiling environment is: Win10 Pro x64, VS 2017, no other software.
Installed components: Static analysis tools, Visual Studio C++ core features, VC++ 2017 v141 toolset (x86,x64), Windows Universal CRT SDK, Windows 8.1 SDK; with or without VC++ 2015.3 v140 toolset for desktop (x86,x64) makes it different.

When executing "cl.exe /? 2>&1" under some conditions, we may both get result and a return value not to be 0. 

For example: I install "VC++ 2017 v141 Tools(x86,x64)" and other simple and necessary components without installing "VC++ 2015.3 v140 Tools(x86,x64)" in VS 2017, I will get an exception of "Couldn't execute cl.exe." when running "phpsdk_deps -u", because the return value is 2 somehow. But actually, the script gets the right result of the cl.exe version, which should keep it running. Once "VC++ 2015.3 v140 Tools(x86,x64)" is installed, everything looks fine.
@chenruo
Copy link

chenruo commented Sep 1, 2017

good job

Copy link
Member

@weltling weltling left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. In general looks good to me, please check the comments yet.

Thanks.


exec("cl.exe /? 2>&1", $a, $status);
if ($status) {
throw new Exception("Couldn't execute cl.exe.");
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it would make sense to keep the exception here, but change the command to where cl.exe. In this case only the status matters. If this passed, one can proceed further and exec the actual cl.exe to parse the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm... yep, this could be much better. I will make some tests tomorrow.

} elseif(0 < preg_match(",x86,", $a[0])) {
self::setCurrentArchName("x86");
} else {
throw new Exception("Couldn't execute cl.exe.");
Copy link
Member

Choose a reason for hiding this comment

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

The message should be like "couldn't determine arch".

@Jerry-Shaw
Copy link
Contributor Author

Jerry-Shaw commented Sep 1, 2017

Code changed for simpler.
There might be no need to actually execute "cl.exe /?" to get the help output then parse, instead, we can get the information from the path when running under the SDK cmd using "where cl.exe". The last few string of the path can't be modified when installing VS.
Tested in my PC. Not sure what if "cl.exe" is broken or cannot be executed somehow (VS installation failed?).

@weltling
Copy link
Member

weltling commented Sep 1, 2017

I might have expressed myself not clear enough previously. Please don't change the parsing part. The flow I've suggested is as follows

  • where cl.exe, ignore output and only check status
  • if status != 0, exception "couldn't execute cl.exe"
  • cl /?, ignore status, parse output
  • if couldn't match, exception "couldn't determine arch"

The latest change doesn't seem to be reliable. Fe on earlier versions it is under amd64\cl.exe. There also might be discrepancy with the pure build tools, whatever other flavors and future VS internals changes. We use this approach also in the PHP build system. The previous approach tries to do both presence and arch check at once, which seems to be buggy as your report shows.

Thanks.

@Jerry-Shaw
Copy link
Contributor Author

Haha, I get what you mean now.

@Jerry-Shaw
Copy link
Contributor Author

Sorry, the IDE changed the code style
I'll make a new commit.

@Jerry-Shaw Jerry-Shaw closed this Sep 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants