Difference between revisions of "Using Git on Windows/v2"

From D Wiki
Jump to: navigation, search
m (Working with git-head and release versions of DMD, Druntime and Phobos: bash -> batch)
 
Line 183: Line 183:
 
= Common Issues =
 
= Common Issues =
 
See [[Building DMD#Common_Windows_issues|Building DMD]]
 
See [[Building DMD#Common_Windows_issues|Building DMD]]
 +
 +
[[Category:Windows]]

Latest revision as of 04:56, 27 March 2018

Preamble

On Windows Git runs via an MSYS shell which is installed with Git. But to run the DMD test-suite, you need to have an MSYS installation that has some tools which are missing from the Git MSYS system. Therefore, you need a separate MSYS install. Additionally, using the MSYS shell from a Windows command prompt is difficult, as the standard Windows terminal emulator doesn't have the same usability improvements as some third-party ones.

This page describes:

  • Installing git
  • Installing a separate msys installation
  • Installing ConEmu, an open-source console emulator for Windows.

Requirements

  • A Windows machine, without a pre-existing Git install or any POSIX-like environments. (Verify by running "git', "sh" or "ls" in a command prompt - you should get error messages.)


Download MSYS and install it.

Setting up ConEmu

Set up a Git Tab


Unfinished below this line

Run Console2, open the Edit->Settings menu, and select the Tabs tree on the left. Click on the Add button and then set a Title (e.g. Git). Set the Shell to C:\Program Files\Git\bin\sh.exe --login -i (or wherever you've installed Git). You can set the Startup dir so you're always ready to cd to a project and start using Git.

You can now use CTRL+F1 to open this tab (configurable in settings).

Set up an MSYS Tab

Click the Add button again, and set the Title to e.g. msys. Set the Shell to C:\msys\1.0\bin\sh.exe --login -i (or wherever you've installed MSYS). Note that using the Startup Dir may not work, but there's a workaround.

Working with git-head and release versions of DMD, Druntime and Phobos

A simple way to work with both an existing D installation and git-head is to have two DMD folders, both of which are in the PATH environment variable, e.g.:

C:\dmd2    # A release version of DMD
C:\dmd-git # the src subdir inside contains git-head of dmd, druntime and phobos

To create and fully prepare the dmd-git folder you can take these steps:

  1. Fork DMD/Druntime/Phobos on Github (fork the ones you intend working on, or all if you want to)
  2. Copy the existing dmd2 dir and rename it to dmd-git
  3. Delete everything in the dmd-git\src directory
  4. Open the Git Tab (CTRL+F1), enter the src directory and clone your forks (replace YourUserName accordingly):
cd /c/dmd-git/src

git clone git@github.com:<YourUserName>/dmd.git
cd dmd
git remote add upstream https://github.com/dlang/dmd
cd..

git clone git@github.com:<YourUserName>/druntime.git
cd druntime
git remote add upstream https://github.com/dlang/druntime
cd..

git clone git@github.com:<YourUserName>/phobos.git
cd phobos
git remote add upstream https://github.com/dlang/phobos
cd..

Then set C:\dmd2\windows\bin and C:\dmd-git\windows\bin so they're both in PATH. You can put the release version in PATH before the git version so it overrides it. When you work on the git-head version rename the release version (e.g. dmd2 to dmd2_) so the git-head version is picked up over the release version when running dmd from a console window.

Set up the MSYS startup dir and aliases

You should have a profile file in the C:\msys\1.0\etc folder. Open it in a text editor and change cd $HOME$ to the test subdir of wherever you're keeping a local clone of DMD, e.g.:

cd /c/dmd-git/src/dmd/test

You can also add some aliases to simplify running the DMD test-suite:

alias tclean="make clean"
alias tall="make DMD=/c/dmd-git/windows/bin/dmd"
alias tfail="make DMD=/c/dmd-git/windows/bin/dmd run_fail_compilation_tests"
alias tcomp="make DMD=/c/dmd-git/windows/bin/dmd run_compilable_tests"
alias trun="make DMD=/c/dmd-git/windows/bin/dmd run_runnable_tests"

Now when you open the MSYS Tab (e.g. CTRL+F2) you can immediately begin running the test-suite by entering tall.

Set up a 3rd party diff tool with Git

As an example, to use BeyondCompare as your diff editor on command you can edit your .bashrc file (usually located in your Documents and Settings\YourName folder) and add some aliases:

# diff all changes in the dir, optionally followed by an argument
alias bdiff='git difftool --dir-diff'

# diff only cached changes (staging area)
alias bcdiff='git difftool --dir-diff --cached'

# diff the head commit with the previous commit
alias bhdiff='git difftool --dir-diff head~1'

The first command allows you to diff between specific revisions, e.g. bdiff head 8f9ee7b11. The others are there just for convenience.

Additionally you will have to add these lines to your .gitconfig file (located in the same dir as .bashrc):

[diff]
	tool = bc3
[difftool "bc3"]
	path = c:/program files/beyond compare 3/BCompare.exe

Ensure you set the right path to BCompare.exe. Note that you need to use BCompare.exe rather than BComp.exe, since the latter will not block Git while viewing the diff and will make git delete the temporary diff files before you can view them.

Checking out pull requests

If you want to test other people's pull requests you can define a function in your .bashrc file (usually located in your Documents and Settings\YourName folder):

# note: the function opening brace must be followed by a newline and indentation
# fetch a pull request
function getpull() {
    git fetch upstream pull/$1/head:pull$1
}

This will allow you to quickly fetch a pull request by calling getpull 1234. (replacing 1234 with the pull request number). And then you can test the pull locally by checking it out via git checkout pull1234.

Building DMD git-head

Once you have your C:\dmd-git\src\dmd clone prepared, you can add a build script to simplify building DMD and copying it to the windows\bin directory. Add this build.bat file to C:\dmd-git\src\dmd\src:

@echo off
:: Uncomment this to clean out the dir to force rebuilding entire DMD (typically required when you have linking errors)
:: make -f win32.mak clean > nul 2>&1
make -f win32.mak > log.txt && copy dmd.exe C:\dmd-git\windows\bin\dmd.exe /Y > nul
if errorlevel 1 GOTO ERROR
goto :CONTINUE

:ERROR
type log.txt
goto :EOF

:CONTINUE
:: These are examples of automatically running DMD (e.g. when developing and testing some code):

:: Run dmd on a test-file
cd C:\dfiles\ && dmd Fix2171.d

:: Run dmd from the windbg debugger (useful during an access violation or assert(0))
:: Tip: use F5 in windbg to run DMD, use "k" to show the stack trace
:: Tip: In newer versions of windbg you need to use "g" before "k" to show the proper stacktrace
cd C:\dfiles\ && windbg dmd Fix2171.d

:: When testing ddoc you probably want to generate an html file
cd C:\dfiles\ && dmd -D -w -o- -c ddoc1000.d

You also need to add this file (and the log file) to your local exclude file. Open the C:\dmd-git\src\dmd\.git\info\exclude file, and add these lines:

src/build.bat
src/log.txt

To build DMD run build.bat, this will copy DMD to your windows\bin directory or print out an error.

Note that you typically need a fresh version of Phobos in order to use the new DMD.

Building Phobos git-head

Building Phobos requires building Druntime first. The workflow is typically:

cd C:\dmd-git\src\druntime
make -f win32.mak

cd ..\phobos
make -f win32.mak && copy phobos.lib C:\dmd-git\windows\lib\phobos.lib /Y > nul

When you build Phobos, Druntime is included into the phobos.lib library.

Editing Environment Variables

You can use the freeware Rapid Environment Editor to edit the PATH and other environment variables. Remember that after editing the environment variables you may need to re-login so the system can pick up the new changes.

Common Issues

See Building DMD