Skip to content

bpo-30687: Fixes build scripts to find msbuild.exe and stop relying on vcvarsall.bat #2252

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 15 commits into from
Jun 19, 2017

Conversation

zooba
Copy link
Member

@zooba zooba commented Jun 16, 2017

Fixes build scripts to find msbuild.exe and stop relying on vcvarsall.bat
Also fixes bdist_wininst.vcxproj to use correct version in generated name.

@zooba zooba self-assigned this Jun 16, 2017
@zooba zooba requested a review from zware June 16, 2017 21:56
@mention-bot
Copy link

@zooba, thanks for your PR! By analyzing the history of the files in this pull request, we identified @zware and @briancurtin to be potential reviewers.

@zooba
Copy link
Member Author

zooba commented Jun 16, 2017

Decided this isn't really trivial, so I'll create an issue. Not a lot to discuss right now I don't think, but there could be when this all goes wrong :)

@zooba zooba changed the title Fixes build scripts to find msbuild.exe and stop relying on vcvarsall.bat bpo-30687: Fixes build scripts to find msbuild.exe and stop relying on vcvarsall.bat Jun 16, 2017
@zooba zooba requested a review from tjguk June 16, 2017 22:17
@zooba
Copy link
Member Author

zooba commented Jun 16, 2017

@tjguk This should fix up the trouble you were having earlier 👍

Copy link
Member

@zware zware left a comment

Choose a reason for hiding this comment

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

I like the idea. Haven't tested it yet, and have a few questions, below.

@@ -0,0 +1,27 @@
#! /usr/bin/env python3
#
# Fixes line endings of batch files to ensure they remain LF.
Copy link
Member

Choose a reason for hiding this comment

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

This isn't right, they should be CRLF :). Also, a del .git\index && git reset from a clean (no changes, no untracked or ignored files) checkout should give you proper line endings according to the rules in .gitattributes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, they weren't CRLF, because Mercurial (I'm using hggit on this machine) fixed them all and they all got changed.

I can fix them back, but then the review is going to be unreadable, so check it all out before I do it :)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. I just checked it out and got the right line endings even on your new find_msbuild.bat file. I think this file can just be removed and we hope .gitattributes makes Git do the right thing :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I needed the script to fix up the problems when hggit did the wrong thing. Maybe I just need to switch to git completely (though then I'm never going to backport anything, because it takes 10x as long)

Copy link
Member

Choose a reason for hiding this comment

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

Would Tools/scripts/crlf.py be enough for you?

@rem

@rem No arguments provided means do full search
@if '%1' EQU '' goto :begin_search
Copy link
Member

Choose a reason for hiding this comment

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

Does this work, or should these be double quotes? I've been bitten by trying to use single quotes in batch files a couple of times, but I'm not convinced that I actually understand the quoting rules.

Copy link
Member Author

Choose a reason for hiding this comment

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

The quoting rules are horrible here, because I want to handle where users have done:

set MSBUILD=C:\path to\MSBuild.exe
set MSBUILD="C:\path to\MSBuild.exe"

Which breaks in a whole lot of ridiculous ways. Using single quotes here at least handles the two sane cases without causing syntax errors.

@if exist "%MSBUILD%" set MSBUILD="%MSBUILD%" & (set _SOURCE=PATH) & goto :found

@rem VS 2017 sets exactly one install as the "main" install, so we may find MSBuild in there.
@for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32') DO @(
Copy link
Member

Choose a reason for hiding this comment

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

VS7?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. One of those names that stuck for back-compat reasons...

@@ -115,7 +115,8 @@ if exist "%GIT%" set GITProperty=/p:GIT="%GIT%"
if not exist "%GIT%" echo Cannot find Git on PATH & set GITProperty=

rem Setup the environment
call "%dir%env.bat" %vs_platf% >nul
Copy link
Member

Choose a reason for hiding this comment

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

Can vs_platf go away entirely now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, sure can!

Copy link
Member Author

Choose a reason for hiding this comment

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

But then I think the cross-compilation for PGO warning has to go away too... not sure of the full impact there yet, let me try it.

Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't; the vs_platf stuff just gets removed from around it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like there are some missing environment pieces, but I can add those into python.bat on build. Looks like that's how we launch for PGO build anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I see what you mean about keeping the warning in there. I'll bring that back

@zooba
Copy link
Member Author

zooba commented Jun 17, 2017

@ned-deily Can we consider this for 3.6.2? It has no impact on the resulting build, but will make the sdist (or forks) easier to use on Windows.

@ned-deily
Copy link
Member

I trust your judgement on the impact and importance. As you know, 3.6.2rc1 is already being "manufactured". Since this is more than a trivial change and presumably could have end-user impact, I don't think it would be appropriate to try to drop it into a 3.6.2final without exposure. There are a couple of options we can discuss off-line but, in any case, the change needs to first be merged into the normal 3.6 branch.

@zooba
Copy link
Member Author

zooba commented Jun 17, 2017

I'm just waiting on @zware to approve (and merge, if there are no changes needed). The backport to the 3.6 branch should be trivial, and probably 3.5 as well.

@tjguk
Copy link
Member

tjguk commented Jun 17, 2017 via email

@tjguk
Copy link
Member

tjguk commented Jun 17, 2017 via email

Copy link
Member

@zware zware left a comment

Choose a reason for hiding this comment

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

One change needed, one suggestion, one request, and one question.

if "%PROCESSOR_ARCHITEW6432%" NEQ "AMD64" if "%PROCESSOR_ARCHITECTURE%" NEQ "AMD64" (
echo.ERROR: Cannot cross-compile with PGO
echo. 32bit operating system detected, if this is incorrect,
echo. make sure the ProgramFiles(x86^) environment variable is set
Copy link
Member

Choose a reason for hiding this comment

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

Error message needs to be reworded, since we're no longer checking %ProgramFiles(x86)% (and %on_64_bit% should be removed from above :CheckOpts)

@@ -0,0 +1,27 @@
#! /usr/bin/env python3
#
# Fixes line endings of batch files to ensure they remain LF.
Copy link
Member

Choose a reason for hiding this comment

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

Would Tools/scripts/crlf.py be enough for you?

@if exist "%MSBUILD%" set MSBUILD="%MSBUILD%" & (set _SOURCE=PATH) & goto :found

@rem VS 2017 sets exactly one install as the "main" install, so we may find MSBuild in there.
@for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32') DO @(
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's here that I get ERROR: The system was unable to find the specified registry key or value. on a machine without VS 2017. Can that be suppressed without too much hardship? Probably the same below, but that key was actually found on my machine.


:found
@echo Using %MSBUILD% (found in the %_SOURCE%)
@set _SOURCE=
Copy link
Member

Choose a reason for hiding this comment

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

Since the idea is to mutate the enclosing environment, _SOURCE should probably be something even less likely to conflict, like _Py_MSBuild_Source.

@zooba
Copy link
Member Author

zooba commented Jun 19, 2017

Made the requested changes, now just working on dealing with line endings...

@zooba
Copy link
Member Author

zooba commented Jun 19, 2017

I think the line endings problem is that .hgeol converts on update/checkout but not commit, while git converts everything to LF on commits and back on checkout. So the actual files in the repo are LF and become CRLF on checkout, but hggit puts them back into git as CRLF instead of LF and we get stupid diffs.

Once we get a backport bot I'll have less need to use something sensible (i.e. hg) for backporting and can use git for more development. Until then, guess I'll just keep doing these extra commits - luckily they'll squash out.

@zware
Copy link
Member

zware commented Jun 19, 2017

What kind of behavior do you get if you just remove .hgeol?

@zooba
Copy link
Member Author

zooba commented Jun 19, 2017

remove .hgeol

Then all my .bat files have LF endings. I'm on Win10 everywhere, so that's less of an issue for me - I think it's only Win7 and earlier that don't like them.

@tjguk
Copy link
Member

tjguk commented Jun 19, 2017 via email

@zooba
Copy link
Member Author

zooba commented Jun 19, 2017

Makes it harder to review within GH though

Yep, that's why I have about 8 "Fix line endings" commits, to get around that problem :)

@tjguk
Copy link
Member

tjguk commented Jun 19, 2017 via email

@zooba zooba merged commit 40a23e8 into python:master Jun 19, 2017
@zooba zooba deleted the msbuild-finder branch June 19, 2017 17:34
zooba added a commit to zooba/cpython that referenced this pull request Jun 19, 2017
…n vcvarsall.bat (python#2252)

* Fixes build scripts to find msbuild.exe and stop relying on vcvarsall.bat
Also fixes bdist_wininst.vcxproj to use correct version in generated name.
zooba added a commit to zooba/cpython that referenced this pull request Jun 19, 2017
…n vcvarsall.bat (python#2252)

* Fixes build scripts to find msbuild.exe and stop relying on vcvarsall.bat
Also fixes bdist_wininst.vcxproj to use correct version in generated name.
zooba added a commit that referenced this pull request Jun 19, 2017
…n vcvarsall.bat (#2252) (#2280)

* Fixes build scripts to find msbuild.exe and stop relying on vcvarsall.bat
Also fixes bdist_wininst.vcxproj to use correct version in generated name.
zooba added a commit that referenced this pull request Jun 19, 2017
…n vcvarsall.bat (#2252) (#2281)

* Fixes build scripts to find msbuild.exe and stop relying on vcvarsall.bat
Also fixes bdist_wininst.vcxproj to use correct version in generated name.
ned-deily pushed a commit to ned-deily/cpython that referenced this pull request Jul 7, 2017
…n vcvarsall.bat (python#2252) (python#2280)

* Fixes build scripts to find msbuild.exe and stop relying on vcvarsall.bat
Also fixes bdist_wininst.vcxproj to use correct version in generated name.

(cherry picked from commit 06d6e3d)
zware pushed a commit to zware/cpython that referenced this pull request Sep 4, 2017
…n vcvarsall.bat (python#2252)

* Fixes build scripts to find msbuild.exe and stop relying on vcvarsall.bat
Also fixes bdist_wininst.vcxproj to use correct version in generated name.

(cherry-picked from parts of 40a23e8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants