-*- mode: org -*-
#+TITLE:       configuration dub
#+DESCRIPTION: documents - structuring, various output representations & search
#+FILETAGS:    :spine:hub:
#+AUTHOR:      Ralph Amissah
#+EMAIL:       [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]]
#+COPYRIGHT:   Copyright (C) 2015 - 2022 Ralph Amissah
#+LANGUAGE:    en
#+STARTUP:     content hideblocks hidestars noindent entitiespretty
#+OPTIONS:     H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t
#+PROPERTY:    header-args  :exports code
#+PROPERTY:    header-args+ :noweb yes
#+PROPERTY:    header-args+ :eval no
#+PROPERTY:    header-args+ :results no
#+PROPERTY:    header-args+ :cache no
#+PROPERTY:    header-args+ :padline no
#+PROPERTY:    header-args+ :mkdirp yes

** spine version SET VERSION :version:set:project:

#+NAME: spine_version_set
#+BEGIN_SRC sh
0.11.3
#+END_SRC

** dub
*** dub.settings.json :dub:config:json:

#+HEADER: :NO-tangle ../dub.settings.json
#+BEGIN_SRC json
{
  "defaultArchitecture": "x86_64",
  "defaultCompiler":     "ldc"
}
#+END_SRC

*** dub.json :dub:config:json:
**** dub.json
***** file-system download external dependencies

- d2sqlite3
- dyaml
  - tinyendian
- imageformats

#+HEADER:  :tangle ../dub.json
#+BEGIN_SRC json
{
  "authors": [
                               "Ralph Amissah"
  ],
  "copyright":                 "Copyright © 2015 - 2022 Ralph Amissah",
  "name":                      "spine",
  "version":                   "<<spine_version_set>>",
  "description":               "a sisu like document parser",
  "homepage":                  "https://sisudoc.org",
  "license":                   "AGPL-3.0+",
  "targetPath":                "./bin",
  "sourcePaths":               [ "./src/doc_reform" ],
  "stringImportPaths":         [ "./views" ],
  "buildRequirements":         [ "allowWarnings" ],
  "targetType":                "executable",
  "platforms":                 [ "posix" ],
  "buildTypes": {
    "dmd": {
      "dflags":                [ "-J=views", "-I=src/doc_reform" ],
      "buildOptions":          [ "verbose", "inline" ],
      "buildRequirements":     [ "allowWarnings" ]
    },
    "ldc": {
      "dflags":                [ "-O2", "-J=views", "-I=src/doc_reform" ],
      "buildOptions":          [ "verbose", "optimize", "inline" ],
      "buildRequirements":     [ "allowWarnings" ]
    }
  },
  "dependencies": {
    "spine:d2sqlite3":         "*",
    "spine:imageformats":      "*",
    "spine:dyaml":             "*"
  },
  "subPackages": [
    {
      "name":        "d2sqlite3",
      "description": "A thin wrapper around SQLite 3",
      "homepage":  "https://github.com/dlang-community/d2sqlite3",
      "authors":    [ "Nicolas Sicard", "Other contributors: see Github repo" ],
      "copyright":   "Copyright 2011-18 Nicolas Sicard",
      "license":     "BSL-1.0",
      "sourcePaths": [ "./src/ext_depends/d2sqlite3/source" ],
      "importPaths": [ "./src/ext_depends/d2sqlite3/source" ],
      "configurations": [
        {
          "name":                "d2sqlite3",
          "d2sqlite3":           "with-lib",
          "targetType":          "library",
          "systemDependencies":  "SQLite version >= 3.8.7",
          "libs":                [ "sqlite3" ],
          "excludedSourceFiles": [ "source/tests.d" ]
        }
      ]
    },
    {
      "name":        "imageformats",
      "description": "Decoders for PNG, TGA, BMP, JPEG and encoders for PNG, TGA, BMP.",
      "authors":     [ "Tero Hänninen" ],
      "license":     "BSL-1.0",
      "sourcePaths": [ "./src/ext_depends/imageformats" ],
      "importPaths": [ "./src/ext_depends/imageformats" ]
    },
    {
      "name": "dyaml",
      "description": "YAML parser and emitter",
      "authors": [
        "Ferdinand Majerech",
        "Cameron \"Herringway\" Ross"
      ],
      "license": "BSL-1.0",
      "homepage": "https://github.com/dlang-community/D-YAML",
      "copyright": "Copyright © 2011-2018, Ferdinand Majerech",
      "sourcePaths": [
        "./src/ext_depends/D-YAML/source",
        "./src/ext_depends/tinyendian/source"
      ],
      "importPaths": [
        "./src/ext_depends/D-YAML/source",
        "./src/ext_depends/tinyendian/source"
      ],
      "preGenerateCommands": [
        "rm -rf ./src/ext_depends/D-YAML/examples",
        "rm -rf ./src/ext_depends/D-YAML/testsuite"
      ]
    }
  ],
  "configurations": [
    {
      "name":                  "default",
      "targetName":            "spine"
    },
    {
      "name":                  "ldc",
      "targetName":            "spine-ldc"
    },
    {
      "name":                  "dmd",
      "targetName":            "spine-dmd"
    }
  ]
}
#+END_SRC

***** git (interim)

#+BEGIN_SRC json
{
  "authors": [
                               "Ralph Amissah"
  ],
  "copyright":                 "Copyright © 2015 - 2022 Ralph Amissah",
  "name":                      "spine",
  "version":                   "<<spine_version_set>>",
  "description":               "a sisu like document parser",
  "homepage":                  "https://sisudoc.org",
  "license":                   "AGPL-3.0+",
  "targetPath":                "./bin",
  "sourcePaths":               [ "./src/doc_reform" ],
  "stringImportPaths":         [ "./views" ],
  "buildRequirements":         [ "allowWarnings" ],
  "targetType":                "executable",
  "platforms":                 [ "posix" ],
  "buildTypes": {
    "dmd": {
      "dflags":                [ "-J=views", "-I=src/doc_reform" ],
      "buildOptions":          [ "verbose", "inline" ],
      "buildRequirements":     [ "allowWarnings" ]
    },
    "ldc": {
      "dflags":                [ "-O2", "-J=views", "-I=src/doc_reform" ],
      "buildOptions":          [ "verbose", "optimize", "inline" ],
      "buildRequirements":     [ "allowWarnings" ]
    }
  },
  "dependencies": {
    "spine:d2sqlite3":         "*",
    "spine:imageformats":      "*",
    "spine:dyaml":             "*"
  },
  "subPackages": [
    {
      "name":        "d2sqlite3",
      "description": "A thin wrapper around SQLite 3",
      "homepage":  "https://github.com/dlang-community/d2sqlite3",
      "authors":    [ "Nicolas Sicard", "Other contributors: see Github repo" ],
      "copyright":   "Copyright 2011-18 Nicolas Sicard",
      "license":     "BSL-1.0",
      "sourcePaths": [ "./src/ext_depends/d2sqlite3/source" ],
      "importPaths": [ "./src/ext_depends/d2sqlite3/source" ],
      "configurations": [
        {
          "name": "with-lib",
          "targetType": "library",
          "systemDependencies": "SQLite version >= 3.8.7",
          "libs": [ "sqlite3" ],
          "excludedSourceFiles": [ "source/tests.d" ]
        }
      ]
    },
    {
      "name":        "imageformats",
      "description": "Decoders for PNG, TGA, BMP, JPEG and encoders for PNG, TGA, BMP.",
      "authors": [ "Tero Hänninen" ],
      "license": "BSL-1.0",
      "sourcePaths": [ "./src/ext_depends/imageformats" ],
      "importPaths": [ "./src/ext_depends/imageformats" ]
    },
    {
      "name": "dyaml",
      "description": "YAML parser and emitter",
      "authors": [
        "Ferdinand Majerech",
        "Cameron \"Herringway\" Ross"
      ],
      "license": "BSL-1.0",
      "homepage": "https://github.com/dlang-community/D-YAML",
      "copyright": "Copyright © 2011-2018, Ferdinand Majerech",
      "sourcePaths": [ "./src/ext_depends/D-YAML/source" ],
      "importPaths": [
        "./src/ext_depends/D-YAML/source",
        "./src/ext_depends/tinyendian/source"
      ],
      "dependencies": {
        "tinyendian" :  "~>0.2.0"
      },
      "preGenerateCommands": [
        "rm -rf ./src/ext_depends/D-YAML/examples",
        "rm -rf ./src/ext_depends/D-YAML/testsuite"
      ]
    },
    {
      "name": "tinyendian",
      "description": "Lightweight endianness handling library",
      "authors": [ "Ferdinand Majerech" ],
      "license": "Boost 1.0",
      "copyright": "Copyright © 2014, Ferdinand Majerech",
      "homepage": "https://github.com/kiith-sa/tinyendian",
      "sourcePaths": [ "./src/ext_depends/tinyendian/source" ],
      "importPaths": [ "./src/ext_depends/tinyendian/source" ]
    }
  ],
  "configurations": [
    {
      "name":                  "default",
      "targetName":            "spine"
    },
    {
      "name":                  "ldc",
      "targetName":            "spine-ldc"
    },
    {
      "name":                  "dmd",
      "targetName":            "spine-dmd"
    }
  ]
}
#+END_SRC

***** git fetched remote external dependencies (used previously)

#+BEGIN_SRC json
{
  "authors": [
                               "Ralph Amissah"
  ],
  "copyright":                 "Copyright © 2015 - 2022 Ralph Amissah",
  "name":                      "spine",
  "version":                   "<<spine_version_set>>",
  "description":               "a sisu like document parser",
  "homepage":                  "https://sisudoc.org",
  "license":                   "AGPL-3.0+",
  "targetPath":                "./bin",
  "sourcePaths":               [ "./src/doc_reform" ],
  "stringImportPaths":         [ "./views" ],
  "buildRequirements":         [ "allowWarnings" ],
  "targetType":                "executable",
  "platforms":                 [ "posix" ],
  "buildTypes": {
    "dmd": {
      "dflags":                [ "-J=views", "-I=src/doc_reform" ],
      "buildOptions":          [ "verbose", "inline" ],
      "buildRequirements":     [ "allowWarnings" ]
    },
    "ldc": {
      "dflags":                [ "-O2", "-J=views", "-I=src/doc_reform" ],
      "buildOptions":          [ "verbose", "optimize", "inline" ],
      "buildRequirements":     [ "allowWarnings" ]
    }
  },
  "dependencies": {
    "d2sqlite3":               "~><<version_d2sqlite3>>",
    "imageformats":            "~><<version_imageformats>>",
    "dyaml":                   "~><<version_dyaml>>",
    "tinyendian":              "~><<version_tinyendian>>"
  },
  "configurations": [
    {
      "name":                  "default",
      "targetName":            "spine"
    },
    {
      "name":                  "ldc",
      "targetName":            "spine-ldc"
    },
    {
      "name":                  "dmd",
      "targetName":            "spine-dmd"
    }
  ]
}
#+END_SRC

**** +check dub.json+

#+HEADER: :NO-tangle ../dub.json
#+BEGIN_SRC sh
{
  "authors": [
                               "Ralph Amissah"
  ],
  "copyright":                 "Copyright © 2015 - 2022 Ralph Amissah",
  "name":                      "spine",
  "description":               "a sisu like document parser",
  "homepage":                  "https://sisudoc.org",
  "license":                   "AGPL-3.0+",
  "targetPath":                "./bin",
  "sourcePaths":               [ "./src/doc_reform" ],
  "stringImportPaths":         [ "./views" ],
  "buildRequirements":         [ "allowWarnings" ],
  "targetType":                "executable",
  "platforms":                 [ "posix" ],
  "dependencies": {
    "d2sqlite3":               "~><<version_d2sqlite3>>",
    "imageformats":            "~><<version_imageformats>>",
    "dyaml":                   "~><<version_dyaml>>",
    "tinyendian":              "~><<version_tinyendian>>"
  },
  "subConfigurations": {
    "d2sqlite3":               "all-included"
  },
  "configurations": [
    {
      "name":                  "default",
      "targetName":            "spine"
    },
    {
      "name":                  "ldc",
      "targetName":            "spine-ldc"
    },
    {
      "name":                  "dmd",
      "targetName":            "spine-dmd"
    }
  ],
  "buildTypes": {
    "dmd": {
      "dflags":                [ "-J=views", "-I=src/doc_reform" ],
      "buildOptions":          [ "verbose", "inline" ],
      "buildRequirements":     [ "allowWarnings" ]
    },
    "ldc": {
      "dflags":                [ "-O2", "-J=views", "-I=src/doc_reform" ],
      "buildOptions":          [ "verbose", "optimize", "inline" ],
      "buildRequirements":     [ "allowWarnings" ]
    }
  }
}
#+END_SRC

*** dub.sdl REFERENCE UNUSED:dub:config:sdl:
Every DUB package should contain a [[https://code.dlang.org/package-format?lang=json][dub.json]] (or [[https://code.dlang.org/package-format?lang=sdl][dub.sdl]])

not configured here, using dub.json for the moment

**** header (including dependencies) :header:

#+HEADER: :NO-tangle ../dub.sdl
#+HEADER: :tangle-mode (identity #o755)
#+HEADER: :shebang #!/usr/bin/env dub
#+BEGIN_SRC sh
name                "spine"
description         "sisu document parser"
homepage            "https://sisudoc.org"
authors             "Ralph Amissah"
copyright           "Copyright (C) 2016 - 2022 Ralph Amissah"
license             "AGPL-3.0+"
targetPath          "./bin"
#sourcePath          "./src/doc_reform"
stringImportPaths   "./views"
buildRequirements   "allowWarnings"
targetType          "executable"
platforms           "posix"
dependency          "d2sqlite3"      version="~><<version_d2sqlite3>>"     # https://code.dlang.org/packages/d2sqlite3     https://github.com/dlang-community/d2sqlite3
  subconfiguration  "d2sqlite3"      "all-included"
dependency          "imageformats"   version="~><<version_imageformats>>"  # https://code.dlang.org/packages/imageformats  https://github.com/lgvz/imageformats
dependency          "dyaml"          version="~><<version_dyaml>>"         # https://code.dlang.org/packages/dyaml         https://github.com/dlang-community/D-YAML
dependency          "tinyendian"     version="~><<version_tinyendian>>"    # https://code.dlang.org/packages/tinyendian    https://github.com/dlang-community/tinyendian // dyaml dependency
#+END_SRC

**** default

time (dub --compiler=dmd --build=release)
time (dub --compiler=ldc2 --build=release)
time (dub --compiler=gdc --build=release)

#+HEADER: :NO-tangle ../dub.sdl
#+BEGIN_SRC sh
configuration "default" {
  targetName           "spine"
  postGenerateCommands "notify-send -t 0 'D executable ready' 'spine'"
}
#+END_SRC

**** dmd :dmd:

time (dub --compiler=dmd -color --config=dmd --build=dmd)
time (dub --compiler=dmd -color --config=dmd --build=dmd-release)

#+HEADER: :NO-tangle ../dub.sdl
#+BEGIN_SRC sh
configuration "dmd" {
  targetName           "spine-dmd"
  postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-dmd'"
}
buildType     "dmd" {
  dflags               "-J=views" "-I=src/doc_reform"
  buildOptions         "verbose" "inline"
  buildRequirements    "allowWarnings"
}
buildType     "dmd-release" {
  dflags               "-J=views" "-I=src/doc_reform"
  buildOptions         "verbose" "releaseMode" "optimize" "inline"
}
configuration "dmd-version" {
  dflags               "-J=views" "-I=src/doc_reform"
  buildOptions         "verbose" "optimize"
  targetName           "spine-dmd-ver"
  postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-dmd-ver'"
}
#+END_SRC

  buildOptions         "verbose" "optimize"                        // ok works quick compile
  buildOptions         "verbose" "optimize" "inline"               // ok works takes ages to compile
  buildOptions         "verbose" "releaseMode" "optimize" "inline" // broken, runtime errors

**** ldc :ldc:

time (dub --compiler=ldc2 -color --config=ldc --build=ldc)
time (dub --compiler=ldc2 -color --config=ldc --build=ldc-release)

#+HEADER: :NO-tangle ../dub.sdl
#+BEGIN_SRC sh
configuration "ldc" {
  targetName           "spine-ldc"
  postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-ldc'"
}
buildType     "ldc" {
  dflags            "-O2" "-J=views" "-I=src/doc_reform"
  buildOptions      "verbose" "optimize" "inline"
  buildRequirements "allowWarnings"
}
buildType     "ldc-local" {
  dflags            "-O2" "-J=views" "-I=src/doc_reform" "-mcpu=native"
  buildOptions      "verbose" "optimize" "inline"
  buildRequirements "allowWarnings"
}
buildType     "ldc-release" {
  dflags               "-O2" "-J=views" "-I=src/doc_reform"
  buildOptions         "verbose" "optimize" "inline" "releaseMode"
}
configuration "ldc-version" {
  dflags               "-O2" "-J=views" "-I=src/doc_reform"
  buildOptions         "verbose" "optimize" "inline" "releaseMode"
  targetName           "spine-ldc-ver"
  postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-ldc-ver'"
}
#+END_SRC

**** gdc :gdc:

time (dub --compiler=gdc --config=gdc --build=gdc)
time (dub --compiler=gdc --config=gdc --build=gdc-release)

#+HEADER: :NO-tangle ../dub.sdl
#+BEGIN_SRC sh
configuration "gdc" {
  targetName           "spine-gdc"
  postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-gdc'"
}
buildType     "gdc" {
  dflags               "-O" "-J=views" "-I=src/doc_reform"
  lflags               "-lz"
  buildOptions         "inline"
  buildRequirements    "allowWarnings"
}
buildType     "gdc-release" {
  dflags               "-O2" "-J=views" "-I=src/doc_reform"
  lflags               "-lz"
  buildOptions         "verbose" "optimize" "inline" "releaseMode"
}
configuration "gdc-version" {
  dflags               "-O2" "-J=views" "-I=src/doc_reform"
  lflags               "-lz"
  buildOptions         "verbose" "optimize" "inline" "releaseMode"
  targetName           "spine-gdc-ver"
  postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-gdc-ver'"
}
#+END_SRC

***** generic :generic:
****** build (sdp) :release:

#+BEGIN_SRC sh
configuration "build" {
  name                 "build"
  targetType           "executable"
  platforms            "posix"
  targetName           "bin/spine"
  dflags               "-J=views" "-I=src/doc_reform"
  buildOptions         "verbose" "releaseMode" "optimize" "inline"
  postGenerateCommands "notify-send -t 0 'D release executable ready' 'spine'"
}
#+END_SRC

** spine search cgi (in ./sundry)
*** dub.json

#+HEADER: :tangle "../sundry/spine_search_cgi/dub.json"
#+BEGIN_SRC json
{
  "authors": [
                               "Ralph Amissah"
  ],
  "copyright":                 "Copyright © 2015 - 2022 Ralph Amissah",
  "name":                      "spine_search",
  "version":                   "<<spine_version_set>>",
  "description":               "cgi search for spine, a sisu like document parser",
  "homepage":                  "https://sisudoc.org",
  "license":                   "AGPL-3.0+",
  "targetPath":                "./cgi-bin",
  "sourcePaths":               [ "./src" ],
  "stringImportPaths":         [ "./views" ],
  "buildRequirements":         [ "allowWarnings" ],
  "targetType":                "executable",
  "platforms":                 [ "posix" ],
  "buildTypes": {
    "dmd": {
      "dflags":                [ "-J=views", "-I=src" ],
      "buildOptions":          [ "verbose", "inline" ],
      "buildRequirements":     [ "allowWarnings" ]
    },
    "ldc": {
      "dflags":                [ "-O2", "-J=views", "-I=src" ],
      "buildOptions":          [ "verbose", "optimize", "inline" ],
      "buildRequirements":     [ "allowWarnings" ]
    }
  },
  "dependencies": {
    "spine_search:arsd.cgi":         "*",
    "spine_search:d2sqlite3":    "*"
  },
  "subPackages": [
    {
      "name":           "arsd.cgi",
      "description":    "cgi",
      "homepage":       "https://code.dlang.org/packages/arsd-official",
      "authors":        [ "Adam Ruppee" ],
      "copyright":      "Copyright 2011-18 Adam Ruppee",
      "license":        "BSL-1.0",
      "sourcePaths":    [ "./src/ext_depends_cgi/arsd" ],
      "importPaths":    [ "./src/ext_depends_cgi/arsd" ],
      "configurations": [
        {
          "name":                "cgi",
          "cgi":                 "with-lib",
          "targetType":          "library",
          "systemDependencies":  "Arsd version >= 0.8.7"
        }
      ]
    },
    {
      "name":           "d2sqlite3",
      "description":    "A thin wrapper around SQLite 3",
      "homepage":       "https://github.com/dlang-community/d2sqlite3",
      "authors":        [ "Nicolas Sicard", "Other contributors: see Github repo" ],
      "copyright":      "Copyright 2011-18 Nicolas Sicard",
      "license":        "BSL-1.0",
      "sourcePaths":    [ "./src/ext_depends_cgi/d2sqlite3/source" ],
      "importPaths":    [ "./src/ext_depends_cgi/d2sqlite3/source" ],
      "configurations": [
        {
          "name":                "d2sqlite3",
          "d2sqlite3":           "with-lib",
          "targetType":          "library",
          "systemDependencies":  "SQLite version >= 3.8.7",
          "libs":                [ "sqlite3" ],
          "excludedSourceFiles": [ "source/tests.d" ]
        }
      ]
    }
  ],
  "configurations": [
    {
      "name":                  "default",
      "targetName":            "spine_search"
    },
    {
      "name":                  "ldc",
      "targetName":            "spine-search-ldc.cgi"
    },
    {
      "name":                  "dmd",
      "targetName":            "spine-search-dmd.cgi"
    }
  ]
}
#+END_SRC

** dub :dub:

https://github.com/dlang/dub/
https://code.dlang.org/getting_started
https://code.dlang.org/docs/commandline

*** setup
**** dub json or sdlang

Every DUB package should contain a [[https://code.dlang.org/package-format?lang=json][dub.json]] or [[https://code.dlang.org/package-format?lang=sdl][dub.sdl]]
https://code.dlang.org/package-format?lang=sdl
https://code.dlang.org/packages/sdlang-d
https://github.com/Abscissa/SDLang-D/blob/master/HOWTO.md

https://code.dlang.org/docs/commandline

**** dub dependencies

dub list
dub upgrade
dub fetch taggedalgebraic
dub fetch libinputvisitor
dub fetch unit-threaded ?

sdp ~master: /home/ralph/grotto/repo/git.repo/utils/spine-x/
/home/ralph/.dub/packages/*

*** build
**** debug flags

#+BEGIN_SRC sh
biblio
biblio_sorted
bibliosorted
block
bookindex
bookindexmatch
bookindexraw
check
checkdoc
code
comment
dumpdoc                    write out document contents, with object type and ocn
endnotes
endnotes_build
footnotes
footnotesdone
group
header
header_and_content
header1
headerjson
headermakejson
headermetadatajson
heading
headings
headingsfound
insert
io
munge
node
objectrelated1
objectrelated2
objects
ocnoff
para
parabullet
parabulletindent
paraindent
paraindenthang
parent
poem
quote
raw
source
srclines
structattrib
summary
table
toc
#+END_SRC

** dub REFERENCE
*** SET version

#+NAME: dub_version_set
#+BEGIN_SRC nix
<<dub_version_next>>
#+END_SRC

#+NAME: nix_sha_dub
#+BEGIN_SRC nix
<<nix_sha_dub_next>>
#+END_SRC

*** SELECT version
**** dub 1.24.0

#+NAME: dub_version_next
#+BEGIN_SRC nix
1.24.0
#+END_SRC

#+NAME: nix_sha_dub_next
#+BEGIN_SRC nix
0wirm6msz8kw2a7v2ax9ab6i48cmfv6qjwpfrl9vrr4k4xdg3vn6
#+END_SRC

**** dub 1.23.0

#+NAME: dub_version_current
#+BEGIN_SRC nix
1.23.0
#+END_SRC

#+NAME: nix_sha_dub_current
#+BEGIN_SRC nix
06a4whsl1m600k096nwif83n7za3vr7pj1xwapncy5fcad1gmady
#+END_SRC

*** dub (using ldc rather than dmd) overlay REFERENCE :overlay:

#+HEADER: :NO-tangle ~/nixpkgs/pkgs/development/tools/build-managers/dub/default.nix
#+BEGIN_SRC nix
{ lib, stdenv, fetchFromGitHub, curl, libevent, rsync, ldc, dcompiler ? ldc }:

assert dcompiler != null;

stdenv.mkDerivation rec {
  pname = "dub";
  version = "<<dub_version_set>>";

  enableParallelBuilding = true;

  src = fetchFromGitHub {
    owner = "dlang";
    repo = "dub";
    rev = "v${version}";
    sha256 = "<<nix_sha_dub>>";
  };

  postUnpack = ''
      patchShebangs .
  '';

  # Can be removed with https://github.com/dlang/dub/pull/1368
  dubvar = "\\$DUB";
  postPatch = ''
      substituteInPlace test/fetchzip.sh \
          --replace "dub remove" "\"${dubvar}\" remove"
  '';

  nativeBuildInputs = [ dcompiler libevent rsync ];
  buildInputs = [ curl ];

  buildPhase = ''
    for dc_ in dmd ldmd2 gdmd; do
      echo "... check for D compiler $dc_ ..."
      dc=$(type -P $dc_ || echo "")
      if [ ! "$dc" == "" ]; then
        break
      fi
    done
    if [ "$dc" == "" ]; then
      exit "Error: could not find D compiler"
    fi
    export DC_NAME=$dc_
    echo "$dc_ found and used as D compiler to build $pname"
    $dc ./build.d
    ./build
  '';

  doCheck = !stdenv.isDarwin;

  checkPhase = ''
    export DUB=$NIX_BUILD_TOP/source/bin/dub
    export PATH=$PATH:$NIX_BUILD_TOP/source/bin/
    export DC=${dcompiler.out}/bin/$DC_NAME
    echo "DC out --> $DC"
    export HOME=$TMP

    <<build_dub_tests>>

    ./test/run-unittest.sh
  '';

  installPhase = ''
    mkdir -p $out/bin
    cp bin/dub $out/bin
  '';

  meta = with lib; {
    description = "Package and build manager for D applications and libraries";
    homepage = "https://code.dlang.org/";
    license = licenses.mit;
    maintainers = with maintainers; [ ThomasMader ];
    platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" ];
  };
}
#+END_SRC

***** removed failing tests

#+NAME: build_dub_tests
#+BEGIN_SRC nix
rm test/0-init-multi.sh
rm test/0-init-multi-json.sh
rm test/5-convert-stdout.sh
rm test/dc-env.sh
rm test/ddox.sh
rm test/feat663-search.sh
rm test/fetchzip.sh
rm test/interactive-remove.sh
rm test/issue672-upgrade-optional.sh
rm test/issue674-concurrent-dub.sh
rm test/issue820-extra-fields-after-convert.sh
rm test/issue877-auto-fetch-package-on-run.sh
rm test/issue990-download-optional-selected.sh
rm test/issue1003-check-empty-ld-flags.sh
rm test/issue1037-better-dependency-messages.sh
rm test/issue1040-run-with-ver.sh
rm test/issue1091-bogus-rebuild.sh
rm test/issue1180-local-cache-broken.sh
rm test/issue1194-warn-wrong-subconfig.sh
rm test/issue1277.sh
rm test/issue1372-ignore-files-in-hidden-dirs.sh
rm test/issue1416-maven-repo-pkg-supplier.sh
rm test/issue1447-build-settings-vars.sh
rm test/issue1574-addcommand.sh
rm test/issue1524-maven-upgrade-dependency-tree.sh
rm test/issue1773-lint.sh
rm test/removed-dub-obj.sh
rm test/version-spec.sh
rm -r test/git-dependency
rm -r test/issue502-root-import
#+END_SRC