standardize-build-settings.dhover×419 errorall
#!/usr/bin/env dub
/+ dub.sdl:
    name "standardize_build_settings"
    targetPath "build"
    dependency "sparkles:build-primitives" path="../../.."
    dependency "sparkles:wired" path="../../.."
    dependency "sparkles:wired-sdl-select" path="../../.."
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
+/
/**
Canonical build types for every tracked dub.sdl, including standalone roots.
Run from the repository root with `dub run --single
apps/ci/tools/standardize-build-settings.d -- --check` (omit --check to update).
Package configurations own dependencies and source selection, not test/benchmark
link policy. Platform/compiler-specific flags never leak into other toolchains.
*/
module 
(module) standardize_build_settings

Canonical build types for every tracked dub.sdl, including standalone roots. Run from the repository root with dub run --single apps/ci/tools/standardize-build-settings.d -- --check (omit --check to update). Package configurations own dependencies and source selection, not test/benchmark link policy. Platform/compiler-specific flags never leak into other toolchains.

standardize_build_settings
;
import
(package) std
std
.
(module) std.algorithm

This package implements generic algorithms oriented towards the processing of sequences. Sequences processed by these functions define range-based interfaces. See also Reference on ranges and tutorial on ranges.

Algorithms are categorized into the following submodules:

Submodule Functions

| Searching | all any balancedParens boyerMooreFinder canFind commonPrefix count countUntil endsWith find findAdjacent findAmong findSkip findSplit findSplitAfter findSplitBefore minCount maxCount minElement maxElement minIndex maxIndex minPos maxPos skipOver startsWith until |

| Comparison | among castSwitch clamp cmp either equal isPermutation isSameLength levenshteinDistance levenshteinDistanceAndPath max min mismatch predSwitch |

| Iteration | cache cacheBidirectional chunkBy cumulativeFold each filter filterBidirectional fold group joiner map mean permutations reduce splitWhen splitter substitute sum uniq |

| Sorting | completeSort isPartitioned isSorted isStrictlyMonotonic ordered strictlyOrdered makeIndex merge multiSort nextEvenPermutation nextPermutation nthPermutation partialSort partition partition3 schwartzSort sort topN topNCopy topNIndex |

| Set operations (setops) | cartesianProduct largestPartialIntersection largestPartialIntersectionWeighted multiwayMerge multiwayUnion setDifference setIntersection setSymmetricDifference |

| Mutation | bringToFront copy fill initializeAll move moveAll moveSome moveEmplace moveEmplaceAll moveEmplaceSome remove reverse strip stripLeft stripRight swap swapRanges uninitializedFill |

Many functions in this package are parameterized with a predicate. The predicate may be any suitable callable type (a function, a delegate, a functor, or a lambda), or a compile-time string. The string may consist of any legal D expression that uses the symbol a (for unary functions) or the symbols a and b (for binary functions). These names will NOT interfere with other homonym symbols in user code because they are evaluated in a different context. The default for all binary comparison predicates is "a == b" for unordered operations and "a < b" for ordered operations.

Example

int[] a = ...;
static bool greater(int a, int b)
{
    return a > b;
}
sort!greater(a);           // predicate as alias
sort!((a, b) => a > b)(a); // predicate as a lambda.
sort!"a > b"(a);           // predicate as string
                           // (no ambiguity with array name)
sort(a);                   // no predicate, "a < b" is implicit

Source

std/algorithm/package.d

@copyrightAndrei Alexandrescu 2008-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu
algorithm
:
(alias template) standardize_build_settings.canFind = std.algorithm.searching.canFind(alias pred = "a == b")

Convenience function. Like find, but only returns whether or not the search was successful.

For more information about pred see find.

@seeamong for checking a value against multiple arguments.
canFind
,
(alias template) standardize_build_settings.endsWith = std.algorithm.searching.endsWith(alias pred = "a == b", Range, Needles...)(Range doesThisEnd, Needles withOneOfThese) if (isBidirectionalRange!Range && (Needles.length > 1) && allSatisfy!(canTestStartsWith!(pred, Range), Needles))

Checks if the given range ends with (one of) the given needle(s). The reciprocal of startsWith.

@parampred The predicate to use for comparing elements between the range and the needle(s).@paramdoesThisEnd The bidirectional range to check.@paramwithOneOfThese The needles to check against, which may be single elements, or bidirectional ranges of elements.@paramwithThis The single element to check.@returns

0 if the needle(s) do not occur at the end of the given range; otherwise the position of the matching needle, that is, 1 if the range ends with withOneOfThese[0], 2 if it ends with withOneOfThese[1], and so on.

In the case when no needle parameters are given, return true iff back of doesThisStart fulfils predicate pred.

endsWith
,
(alias template) standardize_build_settings.filter = std.algorithm.iteration.filter(alias predicate) if (is(typeof(unaryFun!predicate)))

``filter!(predicate)(range) returns a new range containing only elements x in range for which predicate(x) returns true.

The predicate is passed to unaryFun, and can be either a string, or any callable that can be executed via pred(element).

@parampredicate Function to apply to each element of range@returnsAn input range that contains the filtered elements. If range is at least a forward range, the return value of filter will also be a forward range.@seeFilter (higher-order function), filterBidirectional
filter
,
(alias template) standardize_build_settings.map = std.algorithm.iteration.map(fun...) if (fun.length >= 1)

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call ``map!(fun)(range) returns a range of which elements are obtained by applying fun(a) left to right for all elements a in range. The original ranges are not changed. Evaluation is done lazily.

@paramfun one or more transformation functions@seeMap (higher-order function)
map
,
(alias template) standardize_build_settings.startsWith = std.algorithm.searching.startsWith(alias pred = (a, b) => a == b, Range, Needles...)(Range doesThisStart, Needles withOneOfThese) if (isInputRange!Range && (Needles.length > 1) && allSatisfy!(canTestStartsWith!(pred, Range), Needles))

Checks whether the given input range starts with (one of) the given needle(s) or, if no needles are given, if its front element fulfils predicate pred.

For more information about pred see find.

@parampred Predicate to use in comparing the elements of the haystack and the needle(s). Mandatory if no needles are given.@paramdoesThisStart The input range to check.@paramwithOneOfThese The needles against which the range is to be checked, which may be individual elements or input ranges of elements.@paramwithThis The single needle to check, which may be either a single element or an input range of elements.@returns

0 if the needle(s) do not occur at the beginning of the given range; otherwise the position of the matching needle, that is, 1 if the range starts with withOneOfThese[0], 2 if it starts with withOneOfThese[1], and so on.

In the case where doesThisStart starts with multiple of the ranges or elements in withOneOfThese, then the shortest one matches (if there are two which match which are of the same length (e.g. "a" and 'a'), then the left-most of them in the argument list matches).

In the case when no needle parameters are given, return true iff front of doesThisStart fulfils predicate pred.

startsWith
;
import
(package) std
std
.
(module) std.array

Functions and types that manipulate built-in arrays and associative arrays.

This module provides all kinds of functions to create, manipulate or convert arrays:

Function Name Description

| array | Returns a copy of the input in a newly allocated dynamic array. | | appender | Returns a new Appender or RefAppender initialized with a given array. | | assocArray | Returns a newly allocated associative array from a range/ranges of keys and values. | | byPair | Construct a range iterating over an associative array by key/value tuples. | | insertInPlace | Inserts into an existing array at a given position. | | join | Concatenates a range of ranges into one array. | | minimallyInitializedArray | Returns a new array of type T. | | replace | Returns a new array with all occurrences of a certain subrange replaced. | | replaceFirst | Returns a new array with the first occurrence of a certain subrange replaced. | | replaceInPlace | Replaces all occurrences of a certain subrange and puts the result into a given array. | | replaceInto | Replaces all occurrences of a certain subrange and puts the result into an output range. | | replaceLast | Returns a new array with the last occurrence of a certain subrange replaced. | | replaceSlice | Returns a new array with a given slice replaced. | | replicate | Creates a new array out of several copies of an input array or range. | | sameHead | Checks if the initial segments of two arrays refer to the same place in memory. | | sameTail | Checks if the final segments of two arrays refer to the same place in memory. | | split | Eagerly split a range or string into an array. | | staticArray | Creates a new static array from given data. | | uninitializedArray | Returns a new array of type T without initializing its elements. |

Source

std/array.d

@copyrightCopyright Andrei Alexandrescu 2008- and Jonathan M Davis 2011-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu and Jonathan M Davis
array
:
(alias template) standardize_build_settings.join = std.array.join(RoR, R)(RoR ror, R sep) if (isInputRange!RoR && isInputRange!(Unqual!(ElementType!RoR)) && isInputRange!R && (is(immutable(ElementType!(ElementType!RoR)) == immutable(ElementType!R)) || isSomeChar!(ElementType!(ElementType!RoR)) && isSomeChar!(ElementType!R)))

Eagerly concatenates all of the ranges in ror together (with the GC) into one array using sep as the separator if present.

@paramror An input range of input ranges@paramsep An input range, or a single element, to join the ranges on@returnsAn array of elements@seeFor a lazy version, see joiner
join
;
import
(package) std
std
.
(package) std.experimental
experimental
.
(package) std.experimental.allocator
allocator
.
(module) std.experimental.allocator.mallocator

The C heap allocator.

Source

std/experimental/allocator/mallocator.d

mallocator
:
(struct) std.experimental.allocator.mallocator.Mallocator

The C heap allocator.

Examples

auto buffer = Mallocator.instance.allocate(1024 * 1024 * 4);
scope(exit) Mallocator.instance.deallocate(buffer);
//...
Mallocator
;
import
(package) std
std
.
(module) std.file

Utilities for manipulating files and scanning directories. Functions in this module handle files as a unit, e.g., read or write one file at a time. For opening files and manipulating them via handles refer to module std.stdio.

Category Functions
General exists isDir isFile isSymlink rename thisExePath
Directories chdir dirEntries getcwd mkdir mkdirRecurse rmdir rmdirRecurse tempDir
Files append copy read readText remove slurp write
Symlinks symlink readLink
Attributes attrIsDir attrIsFile attrIsSymlink getAttributes getLinkAttributes getSize setAttributes
Timestamp getTimes getTimesWin setTimes timeLastModified timeLastAccessed timeStatusChanged
Other DirEntry FileException PreserveAttributes SpanMode getAvailableDiskSpace

Source

std/file.d

@copyrightCopyright The D Language Foundation 2007 - 2011.@seeThe official tutorial for an introduction to working with files in D, module std.stdio for opening files and manipulating them via handles, and module std.path for manipulating path strings.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Jonathan M Davis
file
:
(alias template) standardize_build_settings.readText = std.file.readText(S = string, R)(auto ref R name) if (isSomeString!S && (isSomeFiniteCharInputRange!R || is(StringTypeOf!R)))

Reads and validates (using validate) a text file. S can be an array of any character type. However, no width or endian conversions are performed. So, if the width or endianness of the characters in the given file differ from the width or endianness of the element type of S, then validation will fail.

@paramS the string type of the file@paramname string or range of characters representing the file name@returnsArray of characters read.@throwsFileException if there is an error reading the file, UTFException on UTF decoding error.@seeread for reading a binary file.
readText
,
(alias template) standardize_build_settings.write = std.file.write(R)(R name, const void[] buffer) if ((isSomeFiniteCharInputRange!R || isSomeString!R) && !isConvertibleToString!R)

Write buffer to file name.

Creates the file if it does not already exist.

@paramname string or range of characters representing the file name@parambuffer data to be written to file@throwsFileException on error.@seetoFile
write
;
import
(package) std
std
.
(module) std.stdio
Category Symbols
File handles _popen File isFileHandle openNetwork stderr stdin stdout
Reading chunks lines readf readfln readln
Writing toFile write writef writefln writeln
Misc KeepTerminator LockType StdioException

Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio is publically imported when importing std.stdio.

There are three layers of I/O:

  1. The lowest layer is the operating system layer. The two main schemes are Windows and Posix.

  2. C's stdio.h which unifies the two operating system schemes.

  3. std.stdio, this module, unifies the various stdio.h implementations into a high level package for D programs.

Source

std/stdio.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Alex Rønne Petersen
stdio
: stderr,
(alias template) standardize_build_settings.writeln = std.stdio.writeln(T...)(T args)

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
import
(package) std
std
.
(module) std.string

String handling functions.

Category Functions
Searching
column
indexOf
indexOfAny
indexOfNeither
lastIndexOf
lastIndexOfAny
lastIndexOfNeither
Comparison
isNumeric
Mutation
capitalize
Pruning and Filling
center
chomp
chompPrefix
chop
detabber
detab
entab
entabber
leftJustify
outdent
rightJustify
strip
stripLeft
stripRight
wrap
Substitution
abbrev
soundex
soundexer
succ
tr
translate
Miscellaneous
assumeUTF
fromStringz
lineSplitter
representation
splitLines
toStringz
Objects of types string, wstring, and dstring are value types
and cannot be mutated element-by-element. For using mutation during building
strings, use char[], wchar[], or dchar[]. The xxxstring
types are preferable because they don't exhibit undesired aliasing, thus
making code more robust.

The following functions are publicly imported:

Module Functions
Publicly imported functions
std.algorithm
cmp, std,algorithm,comparison
count, std,algorithm,searching
endsWith, std,algorithm,searching
startsWith, std,algorithm,searching
std.array
join, std,array
replace, std,array
replaceInPlace, std,array
split, std,array
empty, std,array
std.format
format, std,format
sformat, std,format
std.uni
icmp, std,uni
toLower, std,uni
toLowerInPlace, std,uni
toUpper, std,uni
toUpperInPlace, std,uni
There is a rich set of functions for string handling defined in other modules.
Functions related to Unicode and ASCII are found in std.uni
and std.ascii, respectively. Other functions that have a
wider generality than just strings can be found in std.algorithm
and std.range.

Source

std/string.d

@seestd.algorithm and std.range for generic range algorithms , std.ascii for functions that work with ASCII strings , std.uni for functions that work with unicode strings@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis
string
:
(alias template) standardize_build_settings.lineSplitter = std.string.lineSplitter(Flag keepTerm = No.keepTerminator, Range)(Range r) if (hasSlicing!Range && hasLength!Range && isSomeChar!(ElementType!Range) && !isSomeString!Range)

Split an array or slicable range of characters into a range of lines using '\r', '\n', '\v', '\f', "\r\n", lineSep, paraSep and '\u0085' (NEL) as delimiters. If keepTerm is set to Yes.keepTerminator, then the delimiter is included in the slices returned.

Does not throw on invalid UTF; such is simply passed unchanged to the output.

Adheres to Unicode 7.0.

Does not allocate memory.

@paramr array of chars, wchars, or dchars or a slicable range@paramkeepTerm whether delimiter is included or not in the results@returnsrange of slices of the input range r@seesplitLines splitter splitter
lineSplitter
,
(alias template) standardize_build_settings.strip = std.string.strip(Range)(Range str) if (isSomeString!Range || isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && !isConvertibleToString!Range && isSomeChar!(ElementEncodingType!Range))

Strips both leading and trailing whitespace (as defined by isWhite) or as specified in the second argument.

@paramstr string or random access range of characters@paramchars string of characters to be stripped@paramleftChars string of leading characters to be stripped@paramrightChars string of trailing characters to be stripped@returnsslice of str stripped of leading and trailing whitespace or characters as specified in the second argument.@seeGeneric stripping on ranges: strip
strip
;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(module) sparkles.base.buffer

A @nogc container with Small Buffer Optimization (SBO).

Provides an append-only buffer that stores small amounts of data inline (avoiding heap allocation) and automatically switches to heap storage when capacity is exceeded.

Primary use case: appending elements in a temporary scope where GC allocation is not desired.

buffer
:
(alias template) standardize_build_settings.UniqueBuffer = sparkles.base.buffer.UniqueBuffer(T, ulong N = max(size_t(1), (T[]).sizeof / T.sizeof))

Small-buffer optimization with a sole owner: inline while the elements fit, heap when they do not, and copying is disabled.

Disabling copies is what removes the reference count from the grow path — there is no second owner to consult. Hand a finished one to the shared world with toShared, which consumes it and transfers any heap block without reallocating.

UniqueBuffer
;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(package) sparkles.base.text
text
.
(module) sparkles.base.text.span

Canonical 8-byte text byte range primitive.

TextSpan records an inclusive start byte offset and an exclusive end byte offset [startOffset, endOffset) into a source text. Stored as two 32-bit unsigned integers (uint), it fits in a single 64-bit CPU register and is passed by value with zero heap overhead.

The sentinel value uint.max represents an invalid or uninitialized span.

Pair with LineIndex to project line and column numbers on demand in O(log N) time without inflating data structures.

span
:
(struct) sparkles.base.text.span.TextSpan

An 8-byte byte range [startOffset, endOffset) into a source text.

TextSpan
;
import
(package) sparkles
sparkles
.
(package) sparkles.build_primitives
build_primitives
.
(module) sparkles.build_primitives.git_env

The environment a git child process needs when the caller names the repository it means, instead of inheriting one.

Git exports GIT_DIR — and the rest of repositoryLocationVars — to every process it spawns: a rebase --exec step, a hook, bisect run, a ! alias. A git command that inherits one of those operates on that repository whatever directory it was pointed at, because neither git -C <dir> nor a child working directory overrides them.

That is not hypothetical. A test fixture running git init -q <tmpdir> under an inherited GIT_DIR re-initialises the inherited repository rather than creating a new one; and when the inherited GIT_DIR is a linked worktree's (.git/worktrees/<name>, which does not end in /.git), git guesses that repository is bare and writes core.bare = true into the shared config. Every linked worktree keeps working, so nothing looks broken — only the main checkout dies, with fatal: this operation must be run in a work tree. This repository lost a day to exactly that, twice, before the cause was found.

So a git call that names its repository — through -C <dir>, a working directory, or a path argument — goes through runGit, or carries gitChildEnvironment itself when it needs a pipe.

The converse is equally deliberate: a program that means "whatever repository invoked me" must keep inheriting. ci running as a pre-commit hook and release acting on the checkout it was started in are both in that second category, and neither belongs here.

git_env
:
(alias) standardize_build_settings.runGit = auto sparkles.build_primitives.git_env.runGit(scope const(string)[] args, scope const(char)[] workDir = null) @safe

Run git on a repository the caller names, never an inherited one.

@paramargs the arguments after the program name (["-C", dir, "status"]).@paramworkDir the child's working directory; null inherits the caller's.@returnsstd.process.execute's result — status and combined output.@throwsWhatever execute throws when git cannot be spawned at all. Callers that treat a missing git as a skip rather than a failure keep catching it; this function deliberately does not decide that for them.
runGit
;
import
(package) sparkles
sparkles
.
(package) sparkles.wired
wired
.
(module) sparkles.wired.sdl

SDL backend for sparkles:wired — public surface.

sdl
:
(alias template) standardize_build_settings.parseSdlDocument = sparkles.wired.sdl.reader.parseSdlDocument(SdlParserConfig config = sdlFull, Allocator = Mallocator)(scope const(char)[] text, scope const(char)[] sourceName = null) if (stateSize!Allocator == 0)

Parses SDL into exact allocator-owned arenas.

The input and sourceName are borrowed only for the call. The successful document owns all names, decoded strings, binary bytes, zones, and source name.

parseSdlDocument
,
(alias constant) standardize_build_settings.sdlDubRecipe = sparkles.wired.sdl.config.SdlParserConfig sparkles.wired.sdl.config.sdlDubRecipe = SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u)

DUB recipe dialect with only string and boolean semantic scalar kernels.

sdlDubRecipe
,
(alias template) standardize_build_settings.sdlEditor = sparkles.wired.sdl.editor.sdlEditor(SdlParserConfig config = sdlFull, DocumentAllocator)(ref return scope const SdlDocument!DocumentAllocator document, return scope const(char)[] host)

Constructs an editor for document, parsed under config, over host.

sdlEditor
,
(struct) sparkles.wired.sdl.document.SdlNode

Copyable borrowed view of one SDL node: its run — the core's flatRun for a flat document — and its cell, 16 bytes (editing §10.1). A read is one load, plus the run's shift for a span; the run reaches the core.

dip1000 tracks every view, range, and payload slice back to the owning document: a view cannot outlive the SdlDocument it was reached through.

SdlNode
,
(struct) sparkles.wired.sdl.document.SdlSpan

Half-open byte range of a document's source.

``SdlSpan.init is invalid: the span of a value that came from no source, such as a standalone scalar or an encoded document. Offsets fit in a uint; the parser rejects longer sources with allocationFailed.

SdlSpan
;
import
(package) sparkles
sparkles
.
(package) sparkles.wired
wired
.
(package) sparkles.wired.sdl
sdl
.
(module) sparkles.wired.sdl.select

Path selection over a parsed SDL document (editing §3.2, SDS1–SDS6).

A path in the DQL path grammar (configuration.dependency, configuration[1].dependency) selects nodes by name-and-index child steps; read as an attribute selection, its last segment names attributes instead (dependency.path). A leading .. lets the first step match at any depth (..dependency). An optional DQL filter narrows the selection, evaluated by DQL's own evaluator with each selected node as its subject through SdlNodeResolver:

auto selector = SdlSelector.parse("dependency.path", "path == `../..`").value;
foreach (attribute; selector.attributes(document.root))
    editor.replaceAttribute(attribute, name, SdlScalar(root));

SdlPath borrows a path and selects without a filter or any allocation; SdlSelector shares one parsed path, DQL engine and filter among its copies, reference-counted off the collected heap.

select
:
(struct) sparkles.wired.sdl.select.SdlSelector

A selection path and an optional DQL filter (SDS3). Its state, the path, the DQL engine and the filter that lives in it, is parsed once into one reference-counted block off the collected heap: copies of a selector are owners of the same block, freed with the last of them, so a selector binds like any value (auto s = SdlSelector.parse(…).value;). The ranges it returns are owners too, so a range outlives the selector it came from: foreach (n; SdlSelector.parse(…).value.nodes(root)) iterates after the temporary selector is gone. The count is not atomic, so copies and ranges are for one thread.

SdlSelector
;
// Linux uses lld; Nix must supply wrapped-lld.nix, not the raw ELF linker. // Template linkage stays package-scoped: forcing it onto mir-ion crashes LDC. enum
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
= q"SDL
// BEGIN managed build types — apps/ci/tools/standardize-build-settings.d dflags "--linker=lld" platform="linux-ldc" dflags "-L-fuse-ld=lld" platform="linux-dmd" buildType "unittest" { buildOptions "unittests" "debugMode" "debugInfo" dflags "--gline-tables-only" platform="ldc" dflags "-defaultlib=libphobos2.so" platform="linux-dmd" dflags "--link-defaultlib-shared" platform="linux-ldc" lflags "--export-dynamic" platform="linux-ldc" } buildType "unittest-debug" { buildOptions "unittests" "debugMode" "debugInfo" dflags "-defaultlib=libphobos2.so" platform="linux-dmd" dflags "--link-defaultlib-shared" platform="linux-ldc" lflags "--export-dynamic" platform="linux-ldc" } buildType "unittest-cov" { buildOptions "unittests" "coverage" "debugMode" "debugInfo" dflags "--gline-tables-only" platform="ldc" dflags "-defaultlib=libphobos2.so" platform="linux-dmd" dflags "--link-defaultlib-shared" platform="linux-ldc" lflags "--export-dynamic" platform="linux-ldc" } buildType "unittest-cov-ctfe" { buildOptions "unittests" "coverageCTFE" "debugMode" "debugInfo" dflags "--gline-tables-only" platform="ldc" dflags "-defaultlib=libphobos2.so" platform="linux-dmd" dflags "--link-defaultlib-shared" platform="linux-ldc" lflags "--export-dynamic" platform="linux-ldc" } buildType "checked" { buildOptions "optimize" "inline" "debugInfo" } buildType "bench" { buildOptions "unittests" "optimize" "inline" dflags "-mcpu=native" "-O3" "-allinst" platform="ldc" dflags "-defaultlib=libphobos2.so" platform="linux-dmd" dflags "--link-defaultlib-shared" platform="linux-ldc" lflags "--export-dynamic" platform="linux-ldc" } buildType "bench-unchecked" { buildOptions "unittests" "releaseMode" "optimize" "inline" dflags "-mcpu=native" "-O3" "-allinst" platform="ldc" dflags "-defaultlib=libphobos2.so" platform="linux-dmd" dflags "--link-defaultlib-shared" platform="linux-ldc" lflags "--export-dynamic" platform="linux-ldc" } buildType "bench-static" { buildOptions "unittests" "releaseMode" "optimize" "inline" dflags "-mcpu=native" "-O3" "-allinst" platform="ldc" dflags "--link-defaultlib-shared=false" platform="linux-ldc" dflags "-defaultlib=libphobos2.a" platform="linux-dmd" lflags "--export-dynamic" platform="linux-ldc" } // END managed build types SDL"; /// Managed build types; outside the managed region a block of one of these /// names is a stale copy. private immutable
(alias) object.string = string
string
[]
(immutable global) immutable(string[]) standardize_build_settings.managedBuildTypes

Managed build types; outside the managed region a block of one of these names is a stale copy.

managedBuildTypes
= ["unittest", "unittest-debug",
"unittest-cov", "unittest-cov-ctfe", "checked", "bench", "bench-unchecked", "bench-static"]; /// The DQL filter that keeps a node named by one managed build type. private enum
(constant) string standardize_build_settings.managedBuildTypeFilter = "values[1] == null && (values[0] == \"unittest\" || values[0] == \"unittest-debug\" || values[0] == \"unittest-cov\" || values[0] == \"unittest-cov-ctfe\" || values[0] == \"checked\" || values[0] == \"bench\" || values[0] == \"bench-unchecked\" || values[0] == \"bench-static\")"

The DQL filter that keeps a node named by one managed build type.

managedBuildTypeFilter
= "values[1] == null && ("
~
(immutable global) immutable(string[]) standardize_build_settings.managedBuildTypes

Managed build types; outside the managed region a block of one of these names is a stale copy.

managedBuildTypes
.
std.algorithm.iteration.MapResult!(__lambda_L102_C30, immutable(string)[]) std.algorithm.iteration.map!((name) => "values[0] == \"" ~ name ~ "\"").map!(immutable(string)[])(immutable(string)[] r) pure nothrow @nogc @safe

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call ``map!(fun)(range) returns a range of which elements are obtained by applying fun(a) left to right for all elements a in range. The original ranges are not changed. Evaluation is done lazily.

Examples

import std.algorithm.comparison : equal;
import std.range : chain, only;
auto squares =
    chain(only(1, 2, 3, 4), only(5, 6)).map!(a => a * a);
assert(equal(squares, only(1, 4, 9, 16, 25, 36)));

Multiple functions can be passed to map. In that case, the element type of map is a tuple containing one element for each function.

auto sums = [2, 4, 6, 8];
auto products = [1, 4, 9, 16];

size_t i = 0;
foreach (result; [ 1, 2, 3, 4 ].map!("a + a", "a * a"))
{
    assert(result[0] == sums[i]);
    assert(result[1] == products[i]);
    ++i;
}

You may alias map with some function(s) to a symbol and use it separately:

import std.algorithm.comparison : equal;
import std.conv : to;

alias stringize = map!(to!string);
assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "2", "3", "4" ]));
@paramfun one or more transformation functions@seeMap (higher-order function)@paramr an input range@returnsA range with each fun applied to all the elements. If there is more than one fun, the element type will be Tuple containing one element for each fun.
map
!(name => `values[0] == "` ~ name ~ `"`).
string std.array.join!(std.algorithm.iteration.MapResult!(__lambda_L102_C30, immutable(string)[]), string)(std.algorithm.iteration.MapResult!(__lambda_L102_C30, immutable(string)[]) ror, string sep) pure nothrow @safe

Eagerly concatenates all of the ranges in ror together (with the GC) into one array using sep as the separator if present.

@paramror An input range of input ranges@paramsep An input range, or a single element, to join the ranges on@returnsAn array of elements@seeFor a lazy version, see joiner
join
(" || ") ~ ")";
/// A setting by content: its name, its string values in order, and its one /// `platform` attribute. private struct
(struct) standardize_build_settings.Setting

A setting by content: its name, its string values in order, and its one platform attribute.

Setting
{
(alias) object.string = string
string
(field) string standardize_build_settings.Setting.name
name
;
(alias) object.string = string
string
[]
(field) string[] standardize_build_settings.Setting.values
values
;
(alias) object.string = string
string
(field) string standardize_build_settings.Setting.platform
platform
;
} /// Link settings an earlier policy put in configurations, now in build types. private immutable
(struct) standardize_build_settings.Setting

A setting by content: its name, its string values in order, and its one platform attribute.

Setting
[]
(immutable global) immutable(standardize_build_settings.Setting[]) standardize_build_settings.legacySettings

Link settings an earlier policy put in configurations, now in build types.

legacySettings
= [
(struct) standardize_build_settings.Setting

A setting by content: its name, its string values in order, and its one platform attribute.

Setting
("dflags", ["--link-defaultlib-shared", "-linkonce-templates"], "ldc"),
(struct) standardize_build_settings.Setting

A setting by content: its name, its string values in order, and its one platform attribute.

Setting
("dflags", ["-defaultlib=libphobos2.so", "-L-fuse-ld=gold"], "linux-dmd"),
(struct) standardize_build_settings.Setting

A setting by content: its name, its string values in order, and its one platform attribute.

Setting
("dflags", ["--link-defaultlib-shared", "--linker=gold"], "linux-ldc"),
(struct) standardize_build_settings.Setting

A setting by content: its name, its string values in order, and its one platform attribute.

Setting
("lflags", ["--export-dynamic"], "linux-ldc"),
]; /// Whether `node` is `setting`: the same name, string values and platform, /// and nothing else — no namespace, other attribute or children. private bool
bool standardize_build_settings.isSetting(scope sparkles.wired.sdl.document.SdlNode node, in standardize_build_settings.Setting setting) pure nothrow @nogc @safe

Whether node is setting: the same name, string values and platform, and nothing else — no namespace, other attribute or children.

isSetting
(scope
(struct) sparkles.wired.sdl.document.SdlNode

Copyable borrowed view of one SDL node: its run — the core's flatRun for a flat document — and its cell, 16 bytes (editing §10.1). A read is one load, plus the run's shift for a span; the run reaches the core.

dip1000 tracks every view, range, and payload slice back to the owning document: a view cannot outlive the SdlDocument it was reached through.

SdlNode
(parameter) sparkles.wired.sdl.document.SdlNode node
node
, in
(struct) standardize_build_settings.Setting

A setting by content: its name, its string values in order, and its one platform attribute.

Setting
(parameter) const(standardize_build_settings.Setting) setting
setting
) @safe pure nothrow @nogc
{ import
(package) std
std
.
(package) std.algorithm
algorithm
.
(module) std.algorithm.comparison

This is a submodule of std.algorithm. It contains generic comparison algorithms.

Function Name Description
among Checks if a value is among a set of values, e.g. if (v.among(1, 2, 3)) // v is 1, 2 or 3
castSwitch (new A()).castSwitch((A a)=>1,(B b)=>2) returns 1.
clamp clamp(1, 3, 6) returns 3. clamp(4, 3, 6) returns 4.
cmp cmp("abc", "abcd") is -1, cmp("abc", "aba") is 1, and cmp("abc", "abc") is 0.
either Return first parameter p that passes an if (p) test, e.g. either(0, 42, 43) returns 42.
equal Compares ranges for element-by-element equality, e.g. equal([1, 2, 3], [1.0, 2.0, 3.0]) returns true.
isPermutation isPermutation([1, 2], [2, 1]) returns true.
isSameLength isSameLength([1, 2, 3], [4, 5, 6]) returns true.
levenshteinDistance levenshteinDistance("kitten", "sitting") returns 3 by using the Levenshtein distance algorithm.
levenshteinDistanceAndPath levenshteinDistanceAndPath("kitten", "sitting") returns tuple(3, "snnnsni") by using the Levenshtein distance algorithm.
max max(3, 4, 2) returns 4.
min min(3, 4, 2) returns 2.
mismatch mismatch("oh hi", "ohayo") returns tuple(" hi", "ayo").
predSwitch 2.predSwitch(1, "one", 2, "two", 3, "three") returns "two".

Source

std/algorithm/comparison.d

@copyrightAndrei Alexandrescu 2008-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu
comparison
:
(alias template) equal = std.algorithm.comparison.equal(alias pred = "a == b")

Compares two or more ranges for equality, as defined by predicate pred (which is == by default).

equal
;
import
(package) std
std
.
(package) std.algorithm
algorithm
.
(module) std.algorithm.iteration

This is a submodule of std.algorithm. It contains generic iteration algorithms.

Function Name Description
cache Eagerly evaluates and caches another range's front.
lazyCache Lazily evaluates and caches another range's front, unlike cache.
cacheBidirectional As above, but also provides back and popBack.
chunkBy chunkBy!((a,b) => a[1] == b[1])([[1, 1], [1, 2], [2, 2], [2, 1]]) returns a range containing 3 subranges: the first with just [1, 1]; the second with the elements [1, 2] and [2, 2]; and the third with just [2, 1].
cumulativeFold cumulativeFold!((a, b) => a + b)([1, 2, 3, 4]) returns a lazily-evaluated range containing the successive reduced values 1, 3, 6, 10.
each each!writeln([1, 2, 3]) eagerly prints the numbers 1, 2 and 3 on their own lines.
filter filter!(a => a > 0)([1, -1, 2, 0, -3]) iterates over elements 1 and 2.
filterBidirectional Similar to filter, but also provides back and popBack at a small increase in cost.
fold fold!((a, b) => a + b)([1, 2, 3, 4]) returns 10.
group group([5, 2, 2, 3, 3]) returns a range containing the tuples tuple(5, 1), tuple(2, 2), and tuple(3, 2).
joiner joiner(["hello", "world!"], "; ") returns a range that iterates over the characters "hello; world!". No new string is created - the existing inputs are iterated.
map map!(a => a * 2)([1, 2, 3]) lazily returns a range with the numbers 2, 4, 6.
mean Colloquially known as the average, mean([1, 2, 3]) returns 2.
permutations Lazily computes all permutations using Heap's algorithm.
reduce reduce!((a, b) => a + b)([1, 2, 3, 4]) returns 10. This is the old implementation of fold.
splitWhen Lazily splits a range by comparing adjacent elements.
splitter Lazily splits a range by a separator, element predicate or whitespace.
substitute [1, 2].substitute(1, 0.1) returns [0.1, 2].
sum Same as fold, but specialized for accurate summation.
uniq Iterates over the unique elements in a range, which is assumed sorted.

Source

std/algorithm/iteration.d

@copyrightAndrei Alexandrescu 2008-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu
iteration
:
(alias template) map = std.algorithm.iteration.map(fun...) if (fun.length >= 1)

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call map!(fun)(range) returns a range of which elements are obtained by applying fun(a) left to right for all elements a in range. The original ranges are not changed. Evaluation is done lazily.

Params: fun = one or more transformation functions

See_Also: $(HTTP en.wikipedia.org/wiki/Map_(higher-order_function), Map (higher-order function))

map
;
import
(package) sparkles
sparkles
.
(package) sparkles.wired
wired
.
(module) sparkles.wired.sdl

SDL backend for sparkles:wired — public surface.

sdl
:
(enum) sparkles.wired.sdl.document.SdlScalarKind

Exact semantic kind retained for every SDL scalar.

SdlScalarKind
;
if (
(parameter) sparkles.wired.sdl.document.SdlNode node
node
.
sparkles.wired.sdl.document.SdlQualifiedName sparkles.wired.sdl.document.SdlNode.qualifiedName() const pure nothrow @nogc return scope @safe

Full stored name. The synthetic root returns the empty/default name.

qualifiedName
.
(field) const(char)[] sparkles.wired.sdl.document.SdlQualifiedName.namespace_

Namespace prefix; empty for an unnamespaced name.

namespace_
.
(field) ulong const(char)[].length
length
||
(parameter) sparkles.wired.sdl.document.SdlNode node
node
.
sparkles.wired.sdl.document.SdlQualifiedName sparkles.wired.sdl.document.SdlNode.qualifiedName() const pure nothrow @nogc return scope @safe

Full stored name. The synthetic root returns the empty/default name.

qualifiedName
.
(field) const(char)[] sparkles.wired.sdl.document.SdlQualifiedName.localName

Name after the prefix.

localName
!=
(parameter) const(standardize_build_settings.Setting) setting
setting
.
(field) string standardize_build_settings.Setting.name
name
||
(parameter) sparkles.wired.sdl.document.SdlNode node
node
.
ulong sparkles.wired.sdl.document.SdlNode.childCount() const pure nothrow @nogc scope @safe

Number of direct children, including repeated names.

childCount
||
(parameter) sparkles.wired.sdl.document.SdlNode node
node
.
ulong sparkles.wired.sdl.document.SdlNode.attributeCount() const pure nothrow @nogc scope @safe

Number of attributes, including duplicates.

attributeCount
!= 1 ||
(parameter) sparkles.wired.sdl.document.SdlNode node
node
.
ulong sparkles.wired.sdl.document.SdlNode.valueCount() const pure nothrow @nogc scope @safe

Number of positional scalar values.

valueCount
!=
(parameter) const(standardize_build_settings.Setting) setting
setting
.
(field) string[] standardize_build_settings.Setting.values
values
.
(field) ulong const(string[]).length
length
)
return false; foreach (
(local variable) sparkles.wired.sdl.document.SdlScalar value
value
;
(parameter) sparkles.wired.sdl.document.SdlNode node
node
.
sparkles.wired.sdl.document.SdlValueRange sparkles.wired.sdl.document.SdlNode.byValue() const pure nothrow @nogc return scope @safe

Forward range over positional values in source order.

byValue
)
if (
(local variable) sparkles.wired.sdl.document.SdlScalar value
value
.
sparkles.wired.sdl.document.SdlScalarKind sparkles.wired.sdl.document.SdlScalar.kind() const pure nothrow @nogc scope @safe

The active payload kind.

kind
!=
(enum) sparkles.wired.sdl.document.SdlScalarKind

Exact semantic kind retained for every SDL scalar.

SdlScalarKind
.
(enum value) sparkles.wired.sdl.document.SdlScalarKind.string_ = 3

Decoded UTF-8 text.

string_
)
return false; const
(local variable) const(sparkles.wired.sdl.document.SdlAttributeView) platform
platform
=
(parameter) sparkles.wired.sdl.document.SdlNode node
node
.
sparkles.wired.sdl.document.SdlAttributeRange sparkles.wired.sdl.document.SdlNode.byAttribute() const pure nothrow @nogc return scope @safe

Forward range over every attribute in source order.

byAttribute
.
sparkles.wired.sdl.document.SdlAttributeView sparkles.wired.sdl.document.SdlAttributeRange.front() const pure nothrow @nogc return scope @safe

Forward-range primitives.

front
;
return
(local variable) const(sparkles.wired.sdl.document.SdlAttributeView) platform
platform
.
sparkles.wired.sdl.document.SdlQualifiedName sparkles.wired.sdl.document.SdlAttributeView.qualifiedName() const pure nothrow @nogc return scope @safe

Full stored attribute name.

qualifiedName
.
(field) const(char)[] sparkles.wired.sdl.document.SdlQualifiedName.namespace_

Namespace prefix; empty for an unnamespaced name.

namespace_
.
(field) ulong const(char)[].length
length
== 0
&&
(local variable) const(sparkles.wired.sdl.document.SdlAttributeView) platform
platform
.
sparkles.wired.sdl.document.SdlQualifiedName sparkles.wired.sdl.document.SdlAttributeView.qualifiedName() const pure nothrow @nogc return scope @safe

Full stored attribute name.

qualifiedName
.
(field) const(char)[] sparkles.wired.sdl.document.SdlQualifiedName.localName

Name after the prefix.

localName
== "platform"
&&
(local variable) const(sparkles.wired.sdl.document.SdlAttributeView) platform
platform
.
sparkles.wired.sdl.document.SdlScalar sparkles.wired.sdl.document.SdlAttributeView.value() const pure nothrow @nogc return scope @safe

Borrowed scalar value and its exact token span.

value
.
sparkles.wired.sdl.document.SdlScalarKind sparkles.wired.sdl.document.SdlScalar.kind() const pure nothrow @nogc scope @safe

The active payload kind.

kind
==
(enum) sparkles.wired.sdl.document.SdlScalarKind

Exact semantic kind retained for every SDL scalar.

SdlScalarKind
.
(enum value) sparkles.wired.sdl.document.SdlScalarKind.string_ = 3

Decoded UTF-8 text.

string_
&&
(local variable) const(sparkles.wired.sdl.document.SdlAttributeView) platform
platform
.
sparkles.wired.sdl.document.SdlScalar sparkles.wired.sdl.document.SdlAttributeView.value() const pure nothrow @nogc return scope @safe

Borrowed scalar value and its exact token span.

value
.
const(char)[] sparkles.wired.sdl.document.SdlScalar.stringValue() const pure nothrow @nogc return scope @safe

Active string payload.

stringValue
==
(parameter) const(standardize_build_settings.Setting) setting
setting
.
(field) string standardize_build_settings.Setting.platform
platform
&&
(parameter) sparkles.wired.sdl.document.SdlNode node
node
.
sparkles.wired.sdl.document.SdlValueRange sparkles.wired.sdl.document.SdlNode.byValue() const pure nothrow @nogc return scope @safe

Forward range over positional values in source order.

byValue
.
standardize_build_settings.isSetting.MapResult!(__lambda_L140_C30, SdlValueRange) standardize_build_settings.isSetting.map!(sparkles.wired.sdl.document.SdlValueRange)(sparkles.wired.sdl.document.SdlValueRange r) pure nothrow @nogc @safe

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call ``map!(fun)(range) returns a range of which elements are obtained by applying fun(a) left to right for all elements a in range. The original ranges are not changed. Evaluation is done lazily.

Examples

import std.algorithm.comparison : equal;
import std.range : chain, only;
auto squares =
    chain(only(1, 2, 3, 4), only(5, 6)).map!(a => a * a);
assert(equal(squares, only(1, 4, 9, 16, 25, 36)));

Multiple functions can be passed to map. In that case, the element type of map is a tuple containing one element for each function.

auto sums = [2, 4, 6, 8];
auto products = [1, 4, 9, 16];

size_t i = 0;
foreach (result; [ 1, 2, 3, 4 ].map!("a + a", "a * a"))
{
    assert(result[0] == sums[i]);
    assert(result[1] == products[i]);
    ++i;
}

You may alias map with some function(s) to a symbol and use it separately:

import std.algorithm.comparison : equal;
import std.conv : to;

alias stringize = map!(to!string);
assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "2", "3", "4" ]));
@paramfun one or more transformation functions@seeMap (higher-order function)@paramr an input range@returnsA range with each fun applied to all the elements. If there is more than one fun, the element type will be Tuple containing one element for each fun.
map
!(v => v.stringValue).
bool std.algorithm.comparison.equal!().equal!(standardize_build_settings.isSetting.MapResult!(__lambda_L140_C30, SdlValueRange), const(string)[])(standardize_build_settings.isSetting.MapResult!(__lambda_L140_C30, SdlValueRange) __param_0, const(string)[] __param_1) pure nothrow @nogc @safe

Compares two or more ranges for equality, as defined by predicate pred (which is == by default).

Compares two or more ranges for equality. The ranges may have different element types, as long as all are comparable by means of the pred. Performs O(min(rs[0].length, rs[1].length, ...)) evaluations of pred. However, if equal is invoked with the default predicate, the implementation may take the liberty to use faster implementations that have the theoretical worst-case O(max(rs[0].length, rs[1].length, ...)).

At least one of the ranges must be finite. If one range involved is infinite, the result is (statically known to be) false.

If the ranges have different kinds of UTF code unit (char, wchar, or dchar), then they are compared using UTF decoding to avoid accidentally integer-promoting units.

Examples

import std.algorithm.comparison : equal;
import std.math.operations : isClose;

int[4] a = [ 1, 2, 4, 3 ];
assert(!equal(a[], a[1..$]));
assert(equal(a[], a[]));
assert(equal!((a, b) => a == b)(a[], a[]));

// different types
double[4] b = [ 1.0, 2, 4, 3];
assert(!equal(a[], b[1..$]));
assert(equal(a[], b[]));

// predicated: ensure that two vectors are approximately equal
double[4] c = [ 1.0000000005, 2, 4, 3];
assert(equal!isClose(b[], c[]));

Tip

equal can itself be used as a predicate to other functions. This can be very useful when the element type of a range is itself a range. In particular, equal can be its own predicate, allowing range of range (of range...) comparisons.

import std.algorithm.comparison : equal;
import std.range : iota, chunks;
assert(equal!(equal!equal)(
    [[[0, 1], [2, 3]], [[4, 5], [6, 7]]],
    iota(0, 8).chunks(2).chunks(2)
));
@paramrs The ranges to be compared.@returnstrue if and only if all ranges compare equal element for element, according to binary predicate pred.
equal
(
(parameter) const(standardize_build_settings.Setting) setting
setting
.
(field) string[] standardize_build_settings.Setting.values
values
);
} /// The comment an earlier generator wrote above its `checked` build type; /// only this exact text is its, so a reworded copy is the author's. private enum
(constant) string standardize_build_settings.legacyComment = "// Optimised, assertions live, `debug {}` blocks out \xe2\x80\x94 the build every nix\n// artifact uses. Neither `debug` (which compiles those blocks in) nor\n// `release` (which deletes assert *expressions*, side effects included).\n"

The comment an earlier generator wrote above its checked build type; only this exact text is its, so a reworded copy is the author's.

legacyComment
= "// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
~ "// artifact uses. Neither `debug` (which compiles those blocks in) nor\n" ~ "// `release` (which deletes assert *expressions*, side effects included).\n"; /** Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept. */
(alias) object.string = string
string
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(alias) object.string = string
string
(parameter) string source
source
) @safe
{ auto
(local variable) sparkles.wired.sdl.reader.SdlParseResult!(Mallocator) parsed
parsed
=
sparkles.wired.sdl.reader.SdlParseResult!(Mallocator) sparkles.wired.sdl.reader.parseSdlDocument!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), std.experimental.allocator.mallocator.Mallocator)(scope const(char)[] text, scope const(char)[] sourceName = null) pure @nogc @safe

Parses SDL into exact allocator-owned arenas.

The input and sourceName are borrowed only for the call. The successful document owns all names, decoded strings, binary bytes, zones, and source name.

parseSdlDocument
!
(constant) sparkles.wired.sdl.config.SdlParserConfig sparkles.wired.sdl.config.sdlDubRecipe = SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u)

DUB recipe dialect with only string and boolean semantic scalar kernels.

sdlDubRecipe
(
(parameter) string source
source
);
if (
(local variable) sparkles.wired.sdl.reader.SdlParseResult!(Mallocator) parsed
parsed
.
bool sparkles.wired.sdl.reader.SdlParseResult!(std.experimental.allocator.mallocator.Mallocator).hasError() const pure nothrow @nogc @safe

Whether the parse succeeded, as on Expected.

hasError
)
return
(parameter) string source
source
; // not ours to repair; `dub` reports it
auto
(local variable) sparkles.wired.sdl.document.SdlNode root
root
=
(local variable) sparkles.wired.sdl.reader.SdlParseResult!(Mallocator) parsed
parsed
.
(field) sparkles.wired.sdl.document.SdlDocument!(Mallocator) sparkles.wired.sdl.reader.SdlParseResult!(std.experimental.allocator.mallocator.Mallocator).document

valid iff hasValue

document
.
sparkles.wired.sdl.document.SdlNode sparkles.wired.sdl.document.SdlDocument!(std.experimental.allocator.mallocator.Mallocator).root() const pure nothrow @nogc return scope @safe

Borrowed synthetic root view, valid only while this document is.

scope return binds the view to the document object rather than to its core, so no view outlives the owner that frees it. Narrow trust: the core pointer is a field of a scope this, which dip1000 would only let escape under return scope, the weaker arena-lifetime binding.

root
;
auto
(local variable) sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), Mallocator) editor
editor
=
sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), Mallocator) sparkles.wired.sdl.editor.sdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), std.experimental.allocator.mallocator.Mallocator)(ref return scope const(sparkles.wired.sdl.document.SdlDocument!(Mallocator)) document, return scope const(char)[] host) pure @nogc @safe

Constructs an editor for document, parsed under config, over host.

sdlEditor
!
(constant) sparkles.wired.sdl.config.SdlParserConfig sparkles.wired.sdl.config.sdlDubRecipe = SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u)

DUB recipe dialect with only string and boolean semantic scalar kernels.

sdlDubRecipe
(
(local variable) sparkles.wired.sdl.reader.SdlParseResult!(Mallocator) parsed
parsed
.
(field) sparkles.wired.sdl.document.SdlDocument!(Mallocator) sparkles.wired.sdl.reader.SdlParseResult!(std.experimental.allocator.mallocator.Mallocator).document

valid iff hasValue

document
,
(parameter) string source
source
);
// The lines of `[start, end)`: from the start of `start`'s line through // the newline that ends `end`'s line.
(struct) sparkles.base.text.span.TextSpan

An 8-byte byte range [startOffset, endOffset) into a source text.

TextSpan
sparkles.base.text.span.TextSpan standardize_build_settings.normalize.wholeLines(ulong start, ulong end) pure nothrow @nogc @safe
wholeLines
(
(alias) object.size_t = ulong
size_t
(parameter) ulong start
start
,
(alias) object.size_t = ulong
size_t
(parameter) ulong end
end
)
{ while (
(parameter) ulong start
start
> 0 &&
(parameter) string source
source
[
(parameter) ulong start
start
- 1] != '\n')
(parameter) ulong start
start
--;
while (
(parameter) ulong end
end
<
(parameter) string source
source
.
(field) ulong string.length
length
&&
(parameter) string source
source
[
(parameter) ulong end
end
] != '\n')
(parameter) ulong end
end
++;
return
(struct) sparkles.base.text.span.TextSpan

An 8-byte byte range [startOffset, endOffset) into a source text.

TextSpan
(cast(uint)
(parameter) ulong start
start
, cast(uint)(
(parameter) ulong end
end
<
(parameter) string source
source
.
(field) ulong string.length
length
?
(parameter) ulong end
end
+ 1 :
(parameter) ulong end
end
));
}
(struct) sparkles.wired.sdl.document.SdlSpan

Half-open byte range of a document's source.

``SdlSpan.init is invalid: the span of a value that came from no source, such as a standalone scalar or an encoded document. Offsets fit in a uint; the parser rejects longer sources with allocationFailed.

SdlSpan
(local variable) sparkles.wired.sdl.document.SdlSpan begin
begin
,
(local variable) sparkles.wired.sdl.document.SdlSpan end
end
,
(local variable) sparkles.wired.sdl.document.SdlSpan legacy
legacy
;
foreach (
(local variable) sparkles.wired.sdl.document.SdlComment comment
comment
;
(local variable) sparkles.wired.sdl.reader.SdlParseResult!(Mallocator) parsed
parsed
.
(field) sparkles.wired.sdl.document.SdlDocument!(Mallocator) sparkles.wired.sdl.reader.SdlParseResult!(std.experimental.allocator.mallocator.Mallocator).document

valid iff hasValue

document
.
sparkles.wired.sdl.document.SdlCommentRange sparkles.wired.sdl.document.SdlDocument!(std.experimental.allocator.mallocator.Mallocator).comments() const pure nothrow @nogc return scope @safe

Every comment in the source, in source order (editing SDE6).

comments
)
{ const
(local variable) const(char[]) text
text
=
(local variable) sparkles.wired.sdl.document.SdlComment comment
comment
.
(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.span

The comment's bytes, delimiters included, newline excluded.

span
.
const(char)[] sparkles.wired.sdl.document.SdlSpan.sliceOf(return scope const(char)[] text) const pure nothrow @nogc @safe

The covered bytes of text, the source the span was made from.

sliceOf
(
(parameter) string source
source
);
if (
(local variable) const(char[]) text
text
.
bool std.algorithm.searching.startsWith!("a == b", const(char)[], string)(const(char)[] doesThisStart, string withThis) pure nothrow @nogc @safe

Checks whether the given input range starts with (one of) the given needle(s) or, if no needles are given, if its front element fulfils predicate pred.

For more information about pred see find.

@parampred Predicate to use in comparing the elements of the haystack and the needle(s). Mandatory if no needles are given.@paramdoesThisStart The input range to check.@paramwithOneOfThese The needles against which the range is to be checked, which may be individual elements or input ranges of elements.@paramwithThis The single needle to check, which may be either a single element or an input range of elements.@returns

0 if the needle(s) do not occur at the beginning of the given range; otherwise the position of the matching needle, that is, 1 if the range starts with withOneOfThese[0], 2 if it starts with withOneOfThese[1], and so on.

In the case where doesThisStart starts with multiple of the ranges or elements in withOneOfThese, then the shortest one matches (if there are two which match which are of the same length (e.g. "a" and 'a'), then the left-most of them in the argument list matches).

In the case when no needle parameters are given, return true iff front of doesThisStart fulfils predicate pred.

startsWith
("// BEGIN managed build types"))
(local variable) sparkles.wired.sdl.document.SdlSpan begin
begin
=
(local variable) sparkles.wired.sdl.document.SdlComment comment
comment
.
(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.span

The comment's bytes, delimiters included, newline excluded.

span
;
else if (
(local variable) const(char[]) text
text
.
bool std.algorithm.searching.startsWith!("a == b", const(char)[], string)(const(char)[] doesThisStart, string withThis) pure nothrow @nogc @safe

Checks whether the given input range starts with (one of) the given needle(s) or, if no needles are given, if its front element fulfils predicate pred.

For more information about pred see find.

@parampred Predicate to use in comparing the elements of the haystack and the needle(s). Mandatory if no needles are given.@paramdoesThisStart The input range to check.@paramwithOneOfThese The needles against which the range is to be checked, which may be individual elements or input ranges of elements.@paramwithThis The single needle to check, which may be either a single element or an input range of elements.@returns

0 if the needle(s) do not occur at the beginning of the given range; otherwise the position of the matching needle, that is, 1 if the range starts with withOneOfThese[0], 2 if it starts with withOneOfThese[1], and so on.

In the case where doesThisStart starts with multiple of the ranges or elements in withOneOfThese, then the shortest one matches (if there are two which match which are of the same length (e.g. "a" and 'a'), then the left-most of them in the argument list matches).

In the case when no needle parameters are given, return true iff front of doesThisStart fulfils predicate pred.

startsWith
("// END managed build types"))
(local variable) sparkles.wired.sdl.document.SdlSpan end
end
=
(local variable) sparkles.wired.sdl.document.SdlComment comment
comment
.
(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.span

The comment's bytes, delimiters included, newline excluded.

span
;
else if (
(local variable) sparkles.wired.sdl.document.SdlComment comment
comment
.
(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.span

The comment's bytes, delimiters included, newline excluded.

span
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
+
(constant) string standardize_build_settings.legacyComment = "// Optimised, assertions live, `debug {}` blocks out \xe2\x80\x94 the build every nix\n// artifact uses. Neither `debug` (which compiles those blocks in) nor\n// `release` (which deletes assert *expressions*, side effects included).\n"

The comment an earlier generator wrote above its checked build type; only this exact text is its, so a reworded copy is the author's.

legacyComment
.
(constant) ulong "// Optimised, assertions live, `debug {}` blocks out \xe2\x80\x94 the build every nix\n// artifact uses. Neither `debug` (which compiles those blocks in) nor\n// `release` (which deletes assert *expressions*, side effects included).\n".length = 222LU
length
<=
(parameter) string source
source
.
(field) ulong string.length
length
&&
(parameter) string source
source
[
(local variable) sparkles.wired.sdl.document.SdlComment comment
comment
.
(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.span

The comment's bytes, delimiters included, newline excluded.

span
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
..
(local variable) sparkles.wired.sdl.document.SdlComment comment
comment
.
(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.span

The comment's bytes, delimiters included, newline excluded.

span
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
+
(constant) string standardize_build_settings.legacyComment = "// Optimised, assertions live, `debug {}` blocks out \xe2\x80\x94 the build every nix\n// artifact uses. Neither `debug` (which compiles those blocks in) nor\n// `release` (which deletes assert *expressions*, side effects included).\n"

The comment an earlier generator wrote above its checked build type; only this exact text is its, so a reworded copy is the author's.

legacyComment
.
(constant) ulong "// Optimised, assertions live, `debug {}` blocks out \xe2\x80\x94 the build every nix\n// artifact uses. Neither `debug` (which compiles those blocks in) nor\n// `release` (which deletes assert *expressions*, side effects included).\n".length = 222LU
length
]
==
(constant) string standardize_build_settings.legacyComment = "// Optimised, assertions live, `debug {}` blocks out \xe2\x80\x94 the build every nix\n// artifact uses. Neither `debug` (which compiles those blocks in) nor\n// `release` (which deletes assert *expressions*, side effects included).\n"

The comment an earlier generator wrote above its checked build type; only this exact text is its, so a reworded copy is the author's.

legacyComment
)
(local variable) sparkles.wired.sdl.document.SdlSpan legacy
legacy
=
(local variable) sparkles.wired.sdl.document.SdlComment comment
comment
.
(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.span

The comment's bytes, delimiters included, newline excluded.

span
;
} const
(local variable) const(bool) hasRegion
hasRegion
=
(local variable) sparkles.wired.sdl.document.SdlSpan begin
begin
.
bool sparkles.wired.sdl.document.SdlSpan.isValid() const pure nothrow @nogc @safe

Whether the span names source bytes at all.

isValid
&&
(local variable) sparkles.wired.sdl.document.SdlSpan end
end
.
bool sparkles.wired.sdl.document.SdlSpan.isValid() const pure nothrow @nogc @safe

Whether the span names source bytes at all.

isValid
&&
(local variable) sparkles.wired.sdl.document.SdlSpan begin
begin
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
<
(local variable) sparkles.wired.sdl.document.SdlSpan end
end
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
;
const
(local variable) const(sparkles.base.text.span.TextSpan) region
region
=
(local variable) const(bool) hasRegion
hasRegion
?
sparkles.base.text.span.TextSpan standardize_build_settings.normalize.wholeLines(ulong start, ulong end) pure nothrow @nogc @safe
wholeLines
(
(local variable) sparkles.wired.sdl.document.SdlSpan begin
begin
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
,
(local variable) sparkles.wired.sdl.document.SdlSpan end
end
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
) :
(struct) sparkles.base.text.span.TextSpan

An 8-byte byte range [startOffset, endOffset) into a source text.

TextSpan
.
(constant) sparkles.base.text.span.TextSpan sparkles.base.text.span.TextSpan.init = TextSpan(4294967295u, 4294967295u)
init
;
bool
bool standardize_build_settings.normalize.inRegion(scope sparkles.wired.sdl.document.SdlNode node) pure nothrow @nogc @safe
inRegion
(scope
(struct) sparkles.wired.sdl.document.SdlNode

Copyable borrowed view of one SDL node: its run — the core's flatRun for a flat document — and its cell, 16 bytes (editing §10.1). A read is one load, plus the run's shift for a span; the run reaches the core.

dip1000 tracks every view, range, and payload slice back to the owning document: a view cannot outlive the SdlDocument it was reached through.

SdlNode
(parameter) sparkles.wired.sdl.document.SdlNode node
node
)
=>
(local variable) const(bool) hasRegion
hasRegion
&&
(parameter) sparkles.wired.sdl.document.SdlNode node
node
.
sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlNode.span() const pure nothrow @nogc scope @safe

Complete declaration span, from the name through the terminator.

span
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
>=
(local variable) const(sparkles.base.text.span.TextSpan) region
region
.
(field) uint sparkles.base.text.span.TextSpan.startOffset
startOffset
&&
(parameter) sparkles.wired.sdl.document.SdlNode node
node
.
sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlNode.span() const pure nothrow @nogc scope @safe

Complete declaration span, from the name through the terminator.

span
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
<
(local variable) const(sparkles.base.text.span.TextSpan) region
region
.
(field) uint sparkles.base.text.span.TextSpan.endOffset
endOffset
;
if (
(local variable) sparkles.wired.sdl.document.SdlSpan legacy
legacy
.
bool sparkles.wired.sdl.document.SdlSpan.isValid() const pure nothrow @nogc @safe

Whether the span names source bytes at all.

isValid
)
{ const
(local variable) const(uint) start
start
=
sparkles.base.text.span.TextSpan standardize_build_settings.normalize.wholeLines(ulong start, ulong end) pure nothrow @nogc @safe
wholeLines
(
(local variable) sparkles.wired.sdl.document.SdlSpan legacy
legacy
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
,
(local variable) sparkles.wired.sdl.document.SdlSpan legacy
legacy
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
).
(field) uint sparkles.base.text.span.TextSpan.startOffset
startOffset
;
(local variable) sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), Mallocator) editor
editor
.
void sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), std.experimental.allocator.mallocator.Mallocator).replaceRegion(sparkles.base.text.span.TextSpan region, scope const(char)[] text)

Replaces region — a span of the content the caller derived from the document, such as the lines between two marker comments — with text.

replaceRegion
(
(struct) sparkles.base.text.span.TextSpan

An 8-byte byte range [startOffset, endOffset) into a source text.

TextSpan
(
(local variable) const(uint) start
start
, cast(uint)(
(local variable) sparkles.wired.sdl.document.SdlSpan legacy
legacy
.
uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safe

First byte offset inside the range.

startOffset
+
(constant) string standardize_build_settings.legacyComment = "// Optimised, assertions live, `debug {}` blocks out \xe2\x80\x94 the build every nix\n// artifact uses. Neither `debug` (which compiles those blocks in) nor\n// `release` (which deletes assert *expressions*, side effects included).\n"

The comment an earlier generator wrote above its checked build type; only this exact text is its, so a reworded copy is the author's.

legacyComment
.
(constant) ulong "// Optimised, assertions live, `debug {}` blocks out \xe2\x80\x94 the build every nix\n// artifact uses. Neither `debug` (which compiles those blocks in) nor\n// `release` (which deletes assert *expressions*, side effects included).\n".length = 222LU
length
)), "");
} void
void standardize_build_settings.normalize.removeLegacySettings(scope sparkles.wired.sdl.document.SdlNode parent) pure nothrow @nogc @safe
removeLegacySettings
(scope
(struct) sparkles.wired.sdl.document.SdlNode

Copyable borrowed view of one SDL node: its run — the core's flatRun for a flat document — and its cell, 16 bytes (editing §10.1). A read is one load, plus the run's shift for a span; the run reaches the core.

dip1000 tracks every view, range, and payload slice back to the owning document: a view cannot outlive the SdlDocument it was reached through.

SdlNode
(parameter) sparkles.wired.sdl.document.SdlNode parent
parent
)
{
(local variable) sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), Mallocator) editor
editor
.
void sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), std.experimental.allocator.mallocator.Mallocator).remove(scope sparkles.wired.sdl.document.SdlNode node, sparkles.wired.sdl.editor.SdlAttachedComments comments = SdlAttachedComments.keep)

Removes node: its extent, its attached comments when asked, and the blank line or newline SDE5 names.

remove
(
(parameter) sparkles.wired.sdl.document.SdlNode parent
parent
.
sparkles.wired.sdl.document.SdlChildRange sparkles.wired.sdl.document.SdlNode.byChild() const pure nothrow @nogc return scope @safe

Forward range over direct children in source order.

byChild
.
standardize_build_settings.normalize.removeLegacySettings.FilterResult!(__lambda_L201_C46, SdlChildRange) standardize_build_settings.normalize.removeLegacySettings.filter!(sparkles.wired.sdl.document.SdlChildRange)(sparkles.wired.sdl.document.SdlChildRange range) pure nothrow @nogc @safe

filter`!(predicate)(`range`)` returns a new `range` containing only elements `x` in range`` for which predicate(x) returns true.

The predicate is passed to unaryFun, and can be either a string, or any callable that can be executed via pred(element).

Examples

import std.algorithm.comparison : equal;
import std.math.operations : isClose;
import std.range;

int[] arr = [ 1, 2, 3, 4, 5 ];

// Filter below 3
auto small = filter!(a => a < 3)(arr);
assert(equal(small, [ 1, 2 ]));

// Filter again, but with Uniform Function Call Syntax (UFCS)
auto sum = arr.filter!(a => a < 3);
assert(equal(sum, [ 1, 2 ]));

// In combination with chain() to span multiple ranges
int[] a = [ 3, -2, 400 ];
int[] b = [ 100, -101, 102 ];
auto r = chain(a, b).filter!(a => a > 0);
assert(equal(r, [ 3, 400, 100, 102 ]));

// Mixing convertible types is fair game, too
double[] c = [ 2.5, 3.0 ];
auto r1 = chain(c, a, b).filter!(a => cast(int) a != a);
assert(isClose(r1, [ 2.5 ]));
@parampredicate Function to apply to each element of range@returnsAn input range that contains the filtered elements. If range is at least a forward range, the return value of filter will also be a forward range.@seeFilter (higher-order function), filterBidirectional@paramrange An input range of elements@returnsA range containing only elements x in range for which predicate(x) returns true.
filter
!(node => !inRegion(node)
&& legacySettings.canFind!((s, n) => isSetting(n, s))(node))); }
void standardize_build_settings.normalize.removeLegacySettings(scope sparkles.wired.sdl.document.SdlNode parent) pure nothrow @nogc @safe
removeLegacySettings
(
(local variable) sparkles.wired.sdl.document.SdlNode root
root
);
// Outside the region, a configuration other than `offline` may hold // legacy settings, and a managed build type is a stale copy. auto
(local variable) sparkles.wired.sdl.select.SdlSelector configurations
configurations
=
(struct) sparkles.wired.sdl.select.SdlSelector

A selection path and an optional DQL filter (SDS3). Its state, the path, the DQL engine and the filter that lives in it, is parsed once into one reference-counted block off the collected heap: copies of a selector are owners of the same block, freed with the last of them, so a selector binds like any value (auto s = SdlSelector.parse(…).value;). The ranges it returns are owners too, so a range outlives the selector it came from: foreach (n; SdlSelector.parse(…).value.nodes(root)) iterates after the temporary selector is gone. The count is not atomic, so copies and ranges are for one thread.

SdlSelector
.
sparkles.base.expected.Expected!(SdlSelector, SdlSelectorError, Abort) sparkles.wired.sdl.select.SdlSelector.parse(scope const(char)[] path, scope const(char)[] filter = null) @safe

Validates path and parses filter, which may be empty to keep every node; a fault names its part and its offset there.

parse
("configuration",
`values[1] == null && values[0] != "offline"`).
inout(sparkles.wired.sdl.select.SdlSelector) sparkles.base.expected.Expected!(sparkles.wired.sdl.select.SdlSelector, sparkles.wired.sdl.select.SdlSelectorError, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
;
foreach (
(local variable) sparkles.wired.sdl.document.SdlNode configuration
configuration
;
(local variable) sparkles.wired.sdl.select.SdlSelector configurations
configurations
.
sparkles.wired.sdl.select.SdlSelectedNodes sparkles.wired.sdl.select.SdlSelector.nodes(return scope sparkles.wired.sdl.document.SdlNode start) @safe

The nodes the path selects below start that pass the filter.

nodes
(
(local variable) sparkles.wired.sdl.document.SdlNode root
root
))
if (!
bool standardize_build_settings.normalize.inRegion(scope sparkles.wired.sdl.document.SdlNode node) pure nothrow @nogc @safe
inRegion
(
(local variable) sparkles.wired.sdl.document.SdlNode configuration
configuration
))
void standardize_build_settings.normalize.removeLegacySettings(scope sparkles.wired.sdl.document.SdlNode parent) pure nothrow @nogc @safe
removeLegacySettings
(
(local variable) sparkles.wired.sdl.document.SdlNode configuration
configuration
);
auto
(local variable) sparkles.wired.sdl.select.SdlSelector staleBuildTypes
staleBuildTypes
=
(struct) sparkles.wired.sdl.select.SdlSelector

A selection path and an optional DQL filter (SDS3). Its state, the path, the DQL engine and the filter that lives in it, is parsed once into one reference-counted block off the collected heap: copies of a selector are owners of the same block, freed with the last of them, so a selector binds like any value (auto s = SdlSelector.parse(…).value;). The ranges it returns are owners too, so a range outlives the selector it came from: foreach (n; SdlSelector.parse(…).value.nodes(root)) iterates after the temporary selector is gone. The count is not atomic, so copies and ranges are for one thread.

SdlSelector
.
sparkles.base.expected.Expected!(SdlSelector, SdlSelectorError, Abort) sparkles.wired.sdl.select.SdlSelector.parse(scope const(char)[] path, scope const(char)[] filter = null) @safe

Validates path and parses filter, which may be empty to keep every node; a fault names its part and its offset there.

parse
("buildType",
(constant) string standardize_build_settings.managedBuildTypeFilter = "values[1] == null && (values[0] == \"unittest\" || values[0] == \"unittest-debug\" || values[0] == \"unittest-cov\" || values[0] == \"unittest-cov-ctfe\" || values[0] == \"checked\" || values[0] == \"bench\" || values[0] == \"bench-unchecked\" || values[0] == \"bench-static\")"

The DQL filter that keeps a node named by one managed build type.

managedBuildTypeFilter
).
inout(sparkles.wired.sdl.select.SdlSelector) sparkles.base.expected.Expected!(sparkles.wired.sdl.select.SdlSelector, sparkles.wired.sdl.select.SdlSelectorError, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
;
(local variable) sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), Mallocator) editor
editor
.
editor.remove
remove
(
(local variable) sparkles.wired.sdl.select.SdlSelector staleBuildTypes
staleBuildTypes
.
sparkles.wired.sdl.select.SdlSelectedNodes sparkles.wired.sdl.select.SdlSelector.nodes(return scope sparkles.wired.sdl.document.SdlNode start) @safe

The nodes the path selects below start that pass the filter.

nodes
(
(local variable) sparkles.wired.sdl.document.SdlNode root
root
).filter!(node => !inRegion(node)));
assigning scope variable `root` to non-scope parameter `range` calling `filter` is not allowed in a `@safe` function `range` is not `scope` because of `(FilterResult(SdlSelectedNodes(null, SdlNodeSelection(nul...` `root` inferred `scope` because of `root = parsed.document.root()`
if (
(local variable) const(bool) hasRegion
hasRegion
)
{ if (
(local variable) const(sparkles.base.text.span.TextSpan) region
region
.
const(char)[] sparkles.base.text.span.TextSpan.sliceOf(return scope const(char)[] text) const pure nothrow @nogc @safe

Slices text by this span.

sliceOf
(
(parameter) string source
source
) !=
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
)
(local variable) sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), Mallocator) editor
editor
.
void sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), std.experimental.allocator.mallocator.Mallocator).replaceRegion(sparkles.base.text.span.TextSpan region, scope const(char)[] text)

Replaces region — a span of the content the caller derived from the document, such as the lines between two marker comments — with text.

replaceRegion
(
(local variable) const(sparkles.base.text.span.TextSpan) region
region
,
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
);
} else
(local variable) sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), Mallocator) editor
editor
.
void sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), std.experimental.allocator.mallocator.Mallocator).append(scope sparkles.wired.sdl.document.SdlNode parent, scope const(char)[] fragment)

Appends the nodes of fragment as parent's last children: before its } line, at the end of the content for the root, or in a new block after its last value, attribute or name.

append
(
(local variable) sparkles.wired.sdl.document.SdlNode root
root
, (
(parameter) string source
source
.
bool std.algorithm.searching.endsWith!("a == b", string, string)(string doesThisEnd, string withThis) pure nothrow @nogc @safe

Checks if the given range ends with (one of) the given needle(s). The reciprocal of startsWith.

@parampred The predicate to use for comparing elements between the range and the needle(s).@paramdoesThisEnd The bidirectional range to check.@paramwithOneOfThese The needles to check against, which may be single elements, or bidirectional ranges of elements.@paramwithThis The single element to check.@returns

0 if the needle(s) do not occur at the end of the given range; otherwise the position of the matching needle, that is, 1 if the range ends with withOneOfThese[0], 2 if it ends with withOneOfThese[1], and so on.

In the case when no needle parameters are given, return true iff back of doesThisStart fulfils predicate pred.

endsWith
("\n\n") ||
(parameter) string source
source
.
(field) ulong string.length
length
== 0 ? "" : "\n") ~
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
);
(alias) sparkles.base.buffer.UniqueBuffer!(char, 16LU) = sparkles.base.buffer.Buffer!(char, 16LU, cast(Storage)cast(ubyte)7u)

Small-buffer optimization with a sole owner: inline while the elements fit, heap when they do not, and copying is disabled.

Disabling copies is what removes the reference count from the grow path — there is no second owner to consult. Hand a finished one to the shared world with toShared, which consumes it and transfers any heap block without reallocating.

UniqueBuffer
!char
(local variable) sparkles.base.buffer.Buffer!(char, 16LU, cast(Storage)cast(ubyte)7u) output
output
;
(struct) std.experimental.allocator.mallocator.Mallocator

The C heap allocator.

Examples

auto buffer = Mallocator.instance.allocate(1024 * 1024 * 4);
scope(exit) Mallocator.instance.deallocate(buffer);
//...
Mallocator
(local variable) std.experimental.allocator.mallocator.Mallocator allocator
allocator
;
const
(local variable) const(_error_) written
written
=
(local variable) sparkles.wired.sdl.editor.SdlEditor!(SdlParserConfig(SdlScalarFeatures(false, true, true, false, false, false, false, false, false, false, false, false, false, false), SdlSyntaxFeatures(true, true, true, true, true, true, true, true, true, true, true), SdlSyntaxCompatibility.dub5efed360, true, 1024u), Mallocator) editor
editor
.
(void) void
write
(
(local variable) sparkles.base.buffer.Buffer!(char, 16LU, cast(Storage)cast(ubyte)7u) output
output
,
(local variable) std.experimental.allocator.mallocator.Mallocator allocator
allocator
);
assert(!written.
(field) _error_ written.hasError
hasError
, written.
written.hasError
hasError
? written.error.toString : "");
return
(local variable) sparkles.base.buffer.Buffer!(char, 16LU, cast(Storage)cast(ubyte)7u) output
output
[].
string object.idup!char(char[] a) pure nothrow @property @safe

Provide the .idup array property, which creates an immutable duplicate.

idup
;
} /// Regeneration is idempotent and preserves special codegen configurations. @("buildSettings.normalize.idempotent") @safe
void standardize_build_settings.__unittest_L233_C7() @safe

Regeneration is idempotent and preserves special codegen configurations.

Examples

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
unittest
{ const
(local variable) const(string) source
source
= "name \"sample\"\nconfiguration \"library-inline\" {\n"
~ " dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n"; const
(local variable) const(string) normalized
normalized
=
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) source
source
);
assert(
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) normalized
normalized
) ==
(local variable) const(string) normalized
normalized
);
assert(
(local variable) const(string) normalized
normalized
.
bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safe

Convenience function. Like find, but only returns whether or not the search was successful.

For more information about pred see find.

Examples

const arr = [0, 1, 2, 3];
assert(canFind(arr, 2));
assert(!canFind(arr, 4));

// find one of several needles
assert(arr.canFind(3, 2));
assert(arr.canFind(3, 2) == 2); // second needle found
assert(arr.canFind([1, 3], 2) == 2);

assert(canFind(arr, [1, 2], [2, 3]));
assert(canFind(arr, [1, 2], [2, 3]) == 1);
assert(canFind(arr, [1, 7], [2, 3]));
assert(canFind(arr, [1, 7], [2, 3]) == 2);
assert(!canFind(arr, [1, 3], [2, 4]));
assert(canFind(arr, [1, 3], [2, 4]) == 0);

Example using a custom predicate. Note that the needle appears as the second argument of the predicate.

auto words = [
    "apple",
    "beeswax",
    "cardboard"
];
assert(!canFind(words, "bees"));
assert( canFind!((string elem, string needle) => elem.startsWith(needle))(words, "bees"));

Search for multiple items in an array of items (search for needles in an array of haystacks)

string s1 = "aaa111aaa";
string s2 = "aaa222aaa";
string s3 = "aaa333aaa";
string s4 = "aaa444aaa";
const hay = [s1, s2, s3, s4];
assert(hay.canFind!(e => e.canFind("111", "222")));
@see

among for checking a value against multiple arguments.

Returns true if and only if needle can be found in range. Performs O(haystack.length) evaluations of pred.

canFind
(`"-enable-cross-module-inlining" "-linkonce-templates"`));
} /// Old test-link settings move out of configuration scope into the build type. @("buildSettings.normalize.scopesLinkPolicy") @safe
void standardize_build_settings.__unittest_L244_C7() @safe

Old test-link settings move out of configuration scope into the build type.

Examples

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
unittest
{ const
(local variable) const(string) source
source
= "name \"sample\"\nconfiguration \"unittest\" {\n"
~ " dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n"; const
(local variable) const(string) normalized
normalized
=
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) source
source
);
assert(!
(local variable) const(string) normalized
normalized
[0 .. $ -
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
.
(constant) ulong "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n".length = 2393LU
length
].
bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safe

Convenience function. Like find, but only returns whether or not the search was successful.

For more information about pred see find.

Examples

const arr = [0, 1, 2, 3];
assert(canFind(arr, 2));
assert(!canFind(arr, 4));

// find one of several needles
assert(arr.canFind(3, 2));
assert(arr.canFind(3, 2) == 2); // second needle found
assert(arr.canFind([1, 3], 2) == 2);

assert(canFind(arr, [1, 2], [2, 3]));
assert(canFind(arr, [1, 2], [2, 3]) == 1);
assert(canFind(arr, [1, 7], [2, 3]));
assert(canFind(arr, [1, 7], [2, 3]) == 2);
assert(!canFind(arr, [1, 3], [2, 4]));
assert(canFind(arr, [1, 3], [2, 4]) == 0);

Example using a custom predicate. Note that the needle appears as the second argument of the predicate.

auto words = [
    "apple",
    "beeswax",
    "cardboard"
];
assert(!canFind(words, "bees"));
assert( canFind!((string elem, string needle) => elem.startsWith(needle))(words, "bees"));

Search for multiple items in an array of items (search for needles in an array of haystacks)

string s1 = "aaa111aaa";
string s2 = "aaa222aaa";
string s3 = "aaa333aaa";
string s4 = "aaa444aaa";
const hay = [s1, s2, s3, s4];
assert(hay.canFind!(e => e.canFind("111", "222")));
@see

among for checking a value against multiple arguments.

Returns true if and only if needle can be found in range. Performs O(haystack.length) evaluations of pred.

canFind
("--linker=gold"));
assert(
(local variable) const(string) normalized
normalized
.
bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safe

Convenience function. Like find, but only returns whether or not the search was successful.

For more information about pred see find.

Examples

const arr = [0, 1, 2, 3];
assert(canFind(arr, 2));
assert(!canFind(arr, 4));

// find one of several needles
assert(arr.canFind(3, 2));
assert(arr.canFind(3, 2) == 2); // second needle found
assert(arr.canFind([1, 3], 2) == 2);

assert(canFind(arr, [1, 2], [2, 3]));
assert(canFind(arr, [1, 2], [2, 3]) == 1);
assert(canFind(arr, [1, 7], [2, 3]));
assert(canFind(arr, [1, 7], [2, 3]) == 2);
assert(!canFind(arr, [1, 3], [2, 4]));
assert(canFind(arr, [1, 3], [2, 4]) == 0);

Example using a custom predicate. Note that the needle appears as the second argument of the predicate.

auto words = [
    "apple",
    "beeswax",
    "cardboard"
];
assert(!canFind(words, "bees"));
assert( canFind!((string elem, string needle) => elem.startsWith(needle))(words, "bees"));

Search for multiple items in an array of items (search for needles in an array of haystacks)

string s1 = "aaa111aaa";
string s2 = "aaa222aaa";
string s3 = "aaa333aaa";
string s4 = "aaa444aaa";
const hay = [s1, s2, s3, s4];
assert(hay.canFind!(e => e.canFind("111", "222")));
@see

among for checking a value against multiple arguments.

Returns true if and only if needle can be found in range. Performs O(haystack.length) evaluations of pred.

canFind
("configuration \"unittest\" {\n}"));
assert(
(local variable) const(string) normalized
normalized
.
bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safe

Convenience function. Like find, but only returns whether or not the search was successful.

For more information about pred see find.

Examples

const arr = [0, 1, 2, 3];
assert(canFind(arr, 2));
assert(!canFind(arr, 4));

// find one of several needles
assert(arr.canFind(3, 2));
assert(arr.canFind(3, 2) == 2); // second needle found
assert(arr.canFind([1, 3], 2) == 2);

assert(canFind(arr, [1, 2], [2, 3]));
assert(canFind(arr, [1, 2], [2, 3]) == 1);
assert(canFind(arr, [1, 7], [2, 3]));
assert(canFind(arr, [1, 7], [2, 3]) == 2);
assert(!canFind(arr, [1, 3], [2, 4]));
assert(canFind(arr, [1, 3], [2, 4]) == 0);

Example using a custom predicate. Note that the needle appears as the second argument of the predicate.

auto words = [
    "apple",
    "beeswax",
    "cardboard"
];
assert(!canFind(words, "bees"));
assert( canFind!((string elem, string needle) => elem.startsWith(needle))(words, "bees"));

Search for multiple items in an array of items (search for needles in an array of haystacks)

string s1 = "aaa111aaa";
string s2 = "aaa222aaa";
string s3 = "aaa333aaa";
string s4 = "aaa444aaa";
const hay = [s1, s2, s3, s4];
assert(hay.canFind!(e => e.canFind("111", "222")));
@see

among for checking a value against multiple arguments.

Returns true if and only if needle can be found in range. Performs O(haystack.length) evaluations of pred.

canFind
(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(
(local variable) const(string) normalized
normalized
.
bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safe

Convenience function. Like find, but only returns whether or not the search was successful.

For more information about pred see find.

Examples

const arr = [0, 1, 2, 3];
assert(canFind(arr, 2));
assert(!canFind(arr, 4));

// find one of several needles
assert(arr.canFind(3, 2));
assert(arr.canFind(3, 2) == 2); // second needle found
assert(arr.canFind([1, 3], 2) == 2);

assert(canFind(arr, [1, 2], [2, 3]));
assert(canFind(arr, [1, 2], [2, 3]) == 1);
assert(canFind(arr, [1, 7], [2, 3]));
assert(canFind(arr, [1, 7], [2, 3]) == 2);
assert(!canFind(arr, [1, 3], [2, 4]));
assert(canFind(arr, [1, 3], [2, 4]) == 0);

Example using a custom predicate. Note that the needle appears as the second argument of the predicate.

auto words = [
    "apple",
    "beeswax",
    "cardboard"
];
assert(!canFind(words, "bees"));
assert( canFind!((string elem, string needle) => elem.startsWith(needle))(words, "bees"));

Search for multiple items in an array of items (search for needles in an array of haystacks)

string s1 = "aaa111aaa";
string s2 = "aaa222aaa";
string s3 = "aaa333aaa";
string s4 = "aaa444aaa";
const hay = [s1, s2, s3, s4];
assert(hay.canFind!(e => e.canFind("111", "222")));
@see

among for checking a value against multiple arguments.

Returns true if and only if needle can be found in range. Performs O(haystack.length) evaluations of pred.

canFind
(`dflags "--linker=lld" platform="linux-ldc"`));
assert(
(local variable) const(string) normalized
normalized
.
bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safe

Convenience function. Like find, but only returns whether or not the search was successful.

For more information about pred see find.

Examples

const arr = [0, 1, 2, 3];
assert(canFind(arr, 2));
assert(!canFind(arr, 4));

// find one of several needles
assert(arr.canFind(3, 2));
assert(arr.canFind(3, 2) == 2); // second needle found
assert(arr.canFind([1, 3], 2) == 2);

assert(canFind(arr, [1, 2], [2, 3]));
assert(canFind(arr, [1, 2], [2, 3]) == 1);
assert(canFind(arr, [1, 7], [2, 3]));
assert(canFind(arr, [1, 7], [2, 3]) == 2);
assert(!canFind(arr, [1, 3], [2, 4]));
assert(canFind(arr, [1, 3], [2, 4]) == 0);

Example using a custom predicate. Note that the needle appears as the second argument of the predicate.

auto words = [
    "apple",
    "beeswax",
    "cardboard"
];
assert(!canFind(words, "bees"));
assert( canFind!((string elem, string needle) => elem.startsWith(needle))(words, "bees"));

Search for multiple items in an array of items (search for needles in an array of haystacks)

string s1 = "aaa111aaa";
string s2 = "aaa222aaa";
string s3 = "aaa333aaa";
string s4 = "aaa444aaa";
const hay = [s1, s2, s3, s4];
assert(hay.canFind!(e => e.canFind("111", "222")));
@see

among for checking a value against multiple arguments.

Returns true if and only if needle can be found in range. Performs O(haystack.length) evaluations of pred.

canFind
(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));
} /// Only policy changes: CRLF, a `}` out of column zero, trailing spaces and /// comments elsewhere all survive, and the region takes the host's newline. @("buildSettings.normalize.lossless") @safe
void standardize_build_settings.__unittest_L259_C7() @safe

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

Examples

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
unittest
{ import
(package) std
std
.
(module) std.array

Functions and types that manipulate built-in arrays and associative arrays.

This module provides all kinds of functions to create, manipulate or convert arrays:

Function Name Description

| array | Returns a copy of the input in a newly allocated dynamic array. | | appender | Returns a new Appender or RefAppender initialized with a given array. | | assocArray | Returns a newly allocated associative array from a range/ranges of keys and values. | | byPair | Construct a range iterating over an associative array by key/value tuples. | | insertInPlace | Inserts into an existing array at a given position. | | join | Concatenates a range of ranges into one array. | | minimallyInitializedArray | Returns a new array of type T. | | replace | Returns a new array with all occurrences of a certain subrange replaced. | | replaceFirst | Returns a new array with the first occurrence of a certain subrange replaced. | | replaceInPlace | Replaces all occurrences of a certain subrange and puts the result into a given array. | | replaceInto | Replaces all occurrences of a certain subrange and puts the result into an output range. | | replaceLast | Returns a new array with the last occurrence of a certain subrange replaced. | | replaceSlice | Returns a new array with a given slice replaced. | | replicate | Creates a new array out of several copies of an input array or range. | | sameHead | Checks if the initial segments of two arrays refer to the same place in memory. | | sameTail | Checks if the final segments of two arrays refer to the same place in memory. | | split | Eagerly split a range or string into an array. | | staticArray | Creates a new static array from given data. | | uninitializedArray | Returns a new array of type T without initializing its elements. |

Source

std/array.d

@copyrightCopyright Andrei Alexandrescu 2008- and Jonathan M Davis 2011-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu and Jonathan M Davis
array
:
(alias template) replace = std.array.replace(E, R1, R2)(E[] subject, R1 from, R2 to) if (isForwardRange!R1 && isForwardRange!R2 && (hasLength!R2 || isSomeString!R2) || is(Unqual!E : Unqual!R1))

Replace occurrences of from with to in subject in a new array.

    Params:
        subject = the array to scan
        from = the item to replace
        to = the item to replace all instances of `from` with

    Returns:
        A new array without changing the contents of `subject`, or the original
        array if no match is found.

    See_Also:
        $(REF substitute, std,algorithm,iteration) for a lazy replace.
replace
;
const
(local variable) const(string) crlf
crlf
= "name \"x\" \r\n// keep me\r\nbuildType \"checked\" {\r\n"
~ " buildOptions \"optimize\"\r\n }\r\n"; assert(
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) crlf
crlf
) == "name \"x\" \r\n// keep me\r\n\r\n" ~
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
.
string std.array.replace!(immutable(char), string, string)(string subject, string from, string to) pure nothrow @safe

Replace occurrences of from with to in subject in a new array.

Examples

assert("Hello Wörld".replace("o Wö", "o Wo") == "Hello World");
assert("Hello Wörld".replace("l", "h") == "Hehho Wörhd");
@paramsubject the array to scan@paramfrom the item to replace@paramto the item to replace all instances of from with@returnsA new array without changing the contents of subject, or the original array if no match is found.@seesubstitute for a lazy replace.
replace
("\n", "\r\n"));
const
(local variable) const(string) legacy
legacy
= "name \"y\"\n" ~
(constant) string standardize_build_settings.legacyComment = "// Optimised, assertions live, `debug {}` blocks out \xe2\x80\x94 the build every nix\n// artifact uses. Neither `debug` (which compiles those blocks in) nor\n// `release` (which deletes assert *expressions*, side effects included).\n"

The comment an earlier generator wrote above its checked build type; only this exact text is its, so a reworded copy is the author's.

legacyComment
~ "buildType \"checked\" {\n buildOptions \"optimize\"\n}\n"; assert(
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) legacy
legacy
) == "name \"y\"\n\n" ~
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
);
// A reworded copy is the author's comment, and stays. const
(local variable) const(string) reworded
reworded
= "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
~ "// artifact uses.\n\n" ~
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
;
assert(
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) reworded
reworded
) ==
(local variable) const(string) reworded
reworded
);
// An up-to-date file is left byte for byte, wherever its region sits. const
(local variable) const(string) current
current
= "name \"z\" // note\n\n" ~
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
~ "\nconfiguration \"c\" {\n}\n";
assert(
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) current
current
) ==
(local variable) const(string) current
current
);
// A stale region is replaced in place. const
(local variable) const(string) stale
stale
= "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
~ "// END managed build types\nconfiguration \"c\" {\n}\n"; assert(
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) stale
stale
) == "name \"z\"\n\n" ~
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
~ "configuration \"c\" {\n}\n");
} /// A legacy setting is recognized by its content, however it is laid out; /// one that differs in any value or attribute is the package's own. @("buildSettings.normalize.legacySettingsByContent") @safe
void standardize_build_settings.__unittest_L287_C7() @safe

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

Examples

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
unittest
{ const
(local variable) const(string) source
source
= "name \"s\"\nconfiguration \"unittest\" {\n"
~ " lflags \\\n \"--export-dynamic\" platform=\"linux-ldc\" // old\n" ~ " lflags \"--export-dynamic\" platform=\"linux-dmd\"\n" ~ " lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n" ~ " lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n"; const
(local variable) const(string) normalized
normalized
=
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) source
source
);
assert(
(local variable) const(string) normalized
normalized
== "name \"s\"\nconfiguration \"unittest\" {\n"
~ " lflags \"--export-dynamic\" platform=\"linux-dmd\"\n" ~ " lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n" ~ " lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~
(constant) string standardize_build_settings.managed = "// BEGIN managed build types \xe2\x80\x94 apps/ci/tools/standardize-build-settings.d\ndflags \"--linker=lld\" platform=\"linux-ldc\"\ndflags \"-L-fuse-ld=lld\" platform=\"linux-dmd\"\n\nbuildType \"unittest\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-debug\" {\n buildOptions \"unittests\" \"debugMode\" \"debugInfo\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov\" {\n buildOptions \"unittests\" \"coverage\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"unittest-cov-ctfe\" {\n buildOptions \"unittests\" \"coverageCTFE\" \"debugMode\" \"debugInfo\"\n dflags \"--gline-tables-only\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"checked\" {\n buildOptions \"optimize\" \"inline\" \"debugInfo\"\n}\nbuildType \"bench\" {\n buildOptions \"unittests\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-unchecked\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"-defaultlib=libphobos2.so\" platform=\"linux-dmd\"\n dflags \"--link-defaultlib-shared\" platform=\"linux-ldc\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\nbuildType \"bench-static\" {\n buildOptions \"unittests\" \"releaseMode\" \"optimize\" \"inline\"\n dflags \"-mcpu=native\" \"-O3\" \"-allinst\" platform=\"ldc\"\n dflags \"--link-defaultlib-shared=false\" platform=\"linux-ldc\"\n dflags \"-defaultlib=libphobos2.a\" platform=\"linux-dmd\"\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n// END managed build types\n"
managed
,
(local variable) const(string) normalized
normalized
);
} /// A build type or configuration named by more than one value is not the /// policy's, nor is `configuration "offline"`: each is kept, and so are the /// settings it holds. @("buildSettings.normalize.selectsByOneName") @safe
void standardize_build_settings.__unittest_L306_C7() @safe

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

Examples

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
unittest
{ const
(local variable) const(string) source
source
= "buildType \"checked\" \"x\" {\n}\n"
~ "configuration \"unittest\" \"x\" {\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n" ~ "configuration \"offline\" {\n lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"; const
(local variable) const(string) normalized
normalized
=
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) source
source
);
assert(
(local variable) const(string) normalized
normalized
==
(local variable) const(string) source
source
~ "\n" ~ managed,
(local variable) const(string) normalized
normalized
);
} /// Package-specific calibration types are outside the managed policy. @("buildSettings.normalize.preservesCalibration") @safe
void standardize_build_settings.__unittest_L317_C7() @safe

Package-specific calibration types are outside the managed policy.

unittest
{ const
(local variable) const(string) source
source
= "buildType \"bench-plain\" {\n"
~ " dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n"; assert(
string standardize_build_settings.normalize(string source) @safe

Normalizes only policy, through the lossless SDL editor: the managed region (between its marker comments) is replaced in place or appended, stale managed build types and legacy link settings outside it are removed, and every other byte — comments, layout, package-specific flags — is kept.

Examples

Regeneration is idempotent and preserves special codegen configurations.

const source = "name \"sample\"\nconfiguration \"library-inline\" {\n"
    ~ "    dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const normalized = normalize(source);
assert(normalize(normalized) == normalized);
assert(normalized.canFind(`"-enable-cross-module-inlining" "-linkonce-templates"`));

Old test-link settings move out of configuration scope into the build type.

const source = "name \"sample\"\nconfiguration \"unittest\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(!normalized[0 .. $ - managed.length].canFind("--linker=gold"));
assert(normalized.canFind("configuration \"unittest\" {\n}"));
assert(normalized.canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert(normalized.canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert(normalized.canFind(`dflags "-L-fuse-ld=lld" platform="linux-dmd"`));

Only policy changes: CRLF, a } out of column zero, trailing spaces and comments elsewhere all survive, and the region takes the host's newline.

import std.array : replace;

const crlf = "name \"x\"   \r\n// keep me\r\nbuildType \"checked\" {\r\n"
    ~ "    buildOptions \"optimize\"\r\n  }\r\n";
assert(normalize(crlf) == "name \"x\"   \r\n// keep me\r\n\r\n" ~ managed.replace("\n", "\r\n"));

const legacy = "name \"y\"\n" ~ legacyComment
    ~ "buildType \"checked\" {\n    buildOptions \"optimize\"\n}\n";
assert(normalize(legacy) == "name \"y\"\n\n" ~ managed);
// A reworded copy is the author's comment, and stays.
const reworded = "name \"y\"\n// Optimised, assertions live, `debug {}` blocks out — the build every nix\n"
    ~ "// artifact uses.\n\n" ~ managed;
assert(normalize(reworded) == reworded);

// An up-to-date file is left byte for byte, wherever its region sits.
const current = "name \"z\" // note\n\n" ~ managed ~ "\nconfiguration \"c\" {\n}\n";
assert(normalize(current) == current);
// A stale region is replaced in place.
const stale = "name \"z\"\n\n// BEGIN managed build types — old\nbuildType \"checked\" {\n}\n"
    ~ "// END managed build types\nconfiguration \"c\" {\n}\n";
assert(normalize(stale) == "name \"z\"\n\n" ~ managed ~ "configuration \"c\" {\n}\n");

A legacy setting is recognized by its content, however it is laid out; one that differs in any value or attribute is the package's own.

const source = "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \\\n        \"--export-dynamic\"   platform=\"linux-ldc\" // old\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == "name \"s\"\nconfiguration \"unittest\" {\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-dmd\"\n"
    ~ "    lflags \"--export-dynamic\" platform=\"linux-ldc\" optional=true\n"
    ~ "    lflags \"--export-dynamic\" \"-v\" platform=\"linux-ldc\"\n}\n\n" ~ managed,
    normalized);

A build type or configuration named by more than one value is not the policy's, nor is configuration "offline": each is kept, and so are the settings it holds.

const source = "buildType \"checked\" \"x\" {\n}\n"
    ~ "configuration \"unittest\" \"x\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n"
    ~ "configuration \"offline\" {\n    lflags \"--export-dynamic\" platform=\"linux-ldc\"\n}\n";
const normalized = normalize(source);
assert(normalized == source ~ "\n" ~ managed, normalized);

Package-specific calibration types are outside the managed policy.

const source = "buildType \"bench-plain\" {\n"
    ~ "    dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(normalize(source).canFind(source));
normalize
(
(local variable) const(string) source
source
).
bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safe

Convenience function. Like find, but only returns whether or not the search was successful.

For more information about pred see find.

Examples

const arr = [0, 1, 2, 3];
assert(canFind(arr, 2));
assert(!canFind(arr, 4));

// find one of several needles
assert(arr.canFind(3, 2));
assert(arr.canFind(3, 2) == 2); // second needle found
assert(arr.canFind([1, 3], 2) == 2);

assert(canFind(arr, [1, 2], [2, 3]));
assert(canFind(arr, [1, 2], [2, 3]) == 1);
assert(canFind(arr, [1, 7], [2, 3]));
assert(canFind(arr, [1, 7], [2, 3]) == 2);
assert(!canFind(arr, [1, 3], [2, 4]));
assert(canFind(arr, [1, 3], [2, 4]) == 0);

Example using a custom predicate. Note that the needle appears as the second argument of the predicate.

auto words = [
    "apple",
    "beeswax",
    "cardboard"
];
assert(!canFind(words, "bees"));
assert( canFind!((string elem, string needle) => elem.startsWith(needle))(words, "bees"));

Search for multiple items in an array of items (search for needles in an array of haystacks)

string s1 = "aaa111aaa";
string s2 = "aaa222aaa";
string s3 = "aaa333aaa";
string s4 = "aaa444aaa";
const hay = [s1, s2, s3, s4];
assert(hay.canFind!(e => e.canFind("111", "222")));
@see

among for checking a value against multiple arguments.

Returns true if and only if needle can be found in range. Performs O(haystack.length) evaluations of pred.

canFind
(
(local variable) const(string) source
source
));
} version (
unittest
unittest
) {} else
int main(string[] args) @system { const check = args.canFind("--check"); const files = runGit(["ls-files", "*dub.sdl"]); assert(files.status == 0, files.output); size_t changed, count; foreach (path; files.output.lineSplitter) { if (!path.endsWith("dub.sdl")) continue; ++count; const before = path.readText; const after = normalize(before); if (before == after) continue; ++changed; if (check) stderr.writeln("Noncanonical build settings: ", path); else { path.write(after); writeln("Updated ", path); } } writeln(changed, " of ", count, " manifests ", check ? "need updating" : "updated"); return check && changed ? 1 : 0; }