Using Git on Windows

From D Wiki
Revision as of 13:35, 1 December 2012 by Drey08 (talk | contribs) (Add note on building DMD)
Jump to: navigation, search

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 (lack of easy copy and paste functionality, tiny fonts, limited window size, etc..).

By using Console2 you can improve your workflow with Git.

Requirements

Download Console2 and extract it somewhere.

Download MSYS and install it.

Setting up Console2

Set up a Git Tab

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/D-Programming-Language/dmd
cd..

git clone git@github.com:<YourUserName>/druntime.git
cd druntime
git remote add upstream https://github.com/D-Programming-Language/druntime
cd..

git clone git@github.com:<YourUserName>/phobos.git
cd phobos
git remote add upstream https://github.com/D-Programming-Language/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"
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.

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
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.

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.