www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Using DMD's -v to build dependencies

reply Sergey Gromov <snake.scaly gmail.com> writes:
After some twitting ;) here's my Windows shell script (a .cmd file)
which can effectively replace bud/rebuild in some simple cases.  This
script makes use of GNU grep and sed.  Both are available from GnuWin32
or Cygwin or as separate ports.

file "sbd.cmd"
---8<-------------------
:: Build a D program including any dependencies
:: 2008, Sergey 'SnakE' Gromov <snake.scaly gmail.com>

 echo off
setlocal

if "%1" == "" (
  echo Build a D program with all dependencies
  echo Usage: %0 master [options]
  echo   master   master source, root of the import hierarchy
  echo   options  any options are forwarded to DMD
  exit /b 1
)

set DEP=dependencies.tmp

:: generate dependencies
dmd %* -c -o- -v | grep "^import" | grep -v "phobos\|tango\|\.di)" | sed
"s/^.*(\(.*\)).*$/\1/" > %DEP%

:: compile
dmd %*  %DEP% || goto error

:: cleanup
del %DEP%
exit /b 0

:error
del %DEP%
exit /b 1
---8<-------------------
Dec 12 2008
next sibling parent reply "Bill Baxter" <wbaxter gmail.com> writes:
So how fast is dmd -o-?  Does this pretty much double the compile time?
An option to reuse a previously generated .deps might be nice.

--bb

On Sat, Dec 13, 2008 at 7:18 AM, Sergey Gromov <snake.scaly gmail.com> wrote:
 After some twitting ;) here's my Windows shell script (a .cmd file)
 which can effectively replace bud/rebuild in some simple cases.  This
 script makes use of GNU grep and sed.  Both are available from GnuWin32
 or Cygwin or as separate ports.

 file "sbd.cmd"
 ---8<-------------------
 :: Build a D program including any dependencies
 :: 2008, Sergey 'SnakE' Gromov <snake.scaly gmail.com>

  echo off
 setlocal

 if "%1" == "" (
  echo Build a D program with all dependencies
  echo Usage: %0 master [options]
  echo   master   master source, root of the import hierarchy
  echo   options  any options are forwarded to DMD
  exit /b 1
 )

 set DEP=dependencies.tmp

 :: generate dependencies
 dmd %* -c -o- -v | grep "^import" | grep -v "phobos\|tango\|\.di)" | sed
"s/^.*(\(.*\)).*$/\1/" > %DEP%

 :: compile
 dmd %*  %DEP% || goto error

 :: cleanup
 del %DEP%
 exit /b 0

 :error
 del %DEP%
 exit /b 1
 ---8<-------------------

Dec 12 2008
parent Sergey Gromov <snake.scaly gmail.com> writes:
Sat, 13 Dec 2008 07:37:18 +0900, Bill Baxter wrote:

 So how fast is dmd -o-?  Does this pretty much double the compile time?
 An option to reuse a previously generated .deps might be nice.

Here's the benchmark. I'm compiling dwt-samples\examples\helloworld\HelloWorld5.d from dwt trunk rev. 119, without any pre-compilation. The system is a 1.83 GHz Core2 Duo notebook under Win XP. The compiler is DMD 1.033/Tango. The -c -o- -v stage takes 0.97 seconds (best of five, all files in memory, no swap). The result is a list of 202 files in win-dwt. That's more than a half of dwt (357 .d files). The actual build phase takes 3.27 seconds, best of five, etc. The result is a working 1.7 MB executable. So the -v phase is at least 3 times faster than the actual compilation. Also note that in -o- mode the compiler misses some semantic errors which means it doesn't do full analysis.
Dec 13 2008
prev sibling parent "Bill Baxter" <wbaxter gmail.com> writes:
Excellent, thanks for collecting and reporting that data, Sergey.

So it's not too bad, but still that says to me that caching
dependencies would be beneficial for bigger programs.  But anyway, you
it would certainly be hard to beat your script in terms of simplicity.

Cached dependencies can be left as an exercise for the reader.  :-)

--bb

On Sun, Dec 14, 2008 at 3:35 AM, Sergey Gromov <snake.scaly gmail.com> wrote:
 Sat, 13 Dec 2008 07:37:18 +0900, Bill Baxter wrote:

 So how fast is dmd -o-?  Does this pretty much double the compile time?
 An option to reuse a previously generated .deps might be nice.

Here's the benchmark. I'm compiling dwt-samples\examples\helloworld\HelloWorld5.d from dwt trunk rev. 119, without any pre-compilation. The system is a 1.83 GHz Core2 Duo notebook under Win XP. The compiler is DMD 1.033/Tango. The -c -o- -v stage takes 0.97 seconds (best of five, all files in memory, no swap). The result is a list of 202 files in win-dwt. That's more than a half of dwt (357 .d files). The actual build phase takes 3.27 seconds, best of five, etc. The result is a working 1.7 MB executable. So the -v phase is at least 3 times faster than the actual compilation. Also note that in -o- mode the compiler misses some semantic errors which means it doesn't do full analysis.

Dec 13 2008