Skip to content
Sönke Ludwig edited this page Jul 14, 2015 · 1 revision

Control flow directives

Introduction

In it's current form, DUB has two mechanisms to customize build settings based on external factors - using platform specifiers on each directive, or using the "platforms" directive within configurations. While this is able to capture many use cases, the expressibility is limited and in some cases requires repeating the same directives multiple times, at least in case of platform specifiers. This approach is also limited to make decisions based on the operating system, the architecture or the used compiler.

This DEP proposes a set of quasi-procedural directives that provide general means for these and more advanced use cases.

Synopsis

name "test-package"

if os="windows" compiler="dmd" {
    libs "winmm"
}
else {
    libs "jsw"
}

for "file" files="templates/*.tmpl" {
   preBuildCommand "process-template $file"
}

if dub-version="<0.9.24" {
    // add workaround for something
}

Open questions

Boolean logic

Combining multiple conditions within a single "if" directive can be trivially supported by performing a logical "and" operation between each of the condition attributes. Questionable is if there should be a way to specify logical "or" and "not" operations, too, or if there should even be support for sub terms in parenthesis. The options are practically limited by the SDL format, or a custom DSL within a single string would have to be used.

Comparison syntax

In the above snippet, relational operators are part of the comparison value (e.g. dub-version="<0.9.24"). This representation works fine for numerical values in the broader sense, but creates ambiguities for general string values. At the very least there would have to be some form of disambiguation syntax to account for that.

Another possibility would be to represent comparisons in a completely different way, for example:

  • if "dub-version" "<" "0.9.24"
  • if dub-version="<" "0.9.24"
  • if dub-version:less="0.9.24"
Clone this wiki locally