diff options
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Formula/dmd.rb | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/Library/Formula/dmd.rb b/Library/Formula/dmd.rb index 16a84ef1a..ebf53f68b 100644 --- a/Library/Formula/dmd.rb +++ b/Library/Formula/dmd.rb @@ -35,16 +35,16 @@ class Dmd < Formula prefix.install "samples" man.install Dir["docs/man/*"] - conf = etc/"dmd.conf" - - if conf.exist? - inreplace conf, /^DFLAGS=.+$/, "DFLAGS=-I#{include}/d2 -L-L#{lib}" - else - conf.write <<-EOS.undent + # A proper dmd.conf is required for later build steps: + conf = buildpath/"dmd.conf" + # Can't use opt_include or opt_lib here because dmd won't have been + # linked into opt by the time this build runs: + conf.write <<-EOS.undent [Environment] DFLAGS=-I#{include}/d2 -L-L#{lib} EOS - end + etc.install conf + install_new_dmd_conf make_args.unshift "DMD=#{bin}/dmd" @@ -65,6 +65,29 @@ class Dmd < Formula end end + # Previous versions of this formula may have left in place an incorrect + # dmd.conf. If it differs from the newly generated one, move it out of place + # and warn the user. + # This must be idempotent because it may run from both install() and + # post_install() if the user is running `brew install --build-from-source`. + def install_new_dmd_conf + conf = etc/"dmd.conf" + + # If the new file differs from conf, etc.install drops it here: + new_conf = etc/"dmd.conf.default" + # Else, we're already using the latest version: + return unless new_conf.exist? + + backup = etc/"dmd.conf.old" + opoo "An old dmd.conf was found and will be moved to #{backup}." + mv conf, backup + mv new_conf, conf + end + + def post_install + install_new_dmd_conf + end + test do system bin/"dmd", prefix/"samples/hello.d" system "./hello" |
