#!/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_settingsCanonical 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) stdstd.(module) std.algorithmThis 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
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.
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.
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).
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.
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.
startsWith;
import (package) stdstd.(module) std.arrayFunctions 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
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.
join;
import (package) stdstd.(package) std.experimentalexperimental.(package) std.experimental.allocatorallocator.(module) std.experimental.allocator.mallocatorThe C heap allocator.
Source
std/experimental/allocator/mallocator.d
mallocator : (struct) std.experimental.allocator.mallocator.MallocatorThe C heap allocator.
Examples
auto buffer = Mallocator.instance.allocate(1024 * 1024 * 4);
scope(exit) Mallocator.instance.deallocate(buffer);
//...
Mallocator;
import (package) stdstd.(module) std.fileUtilities 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
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.
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.
write;
import (package) stdstd.(module) std.stdioCategory 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:
The lowest layer is the operating system layer. The two main schemes are Windows and Posix.
C's stdio.h which unifies the two operating system schemes.
std.stdio, this module, unifies the various stdio.h implementations into
a high level package for D programs.
Source
std/stdio.d
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);
}
}
writeln;
import (package) stdstd.(module) std.stringString 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
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.
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.
strip;
import (package) sparklessparkles.(package) sparkles.basebase.(module) sparkles.base.bufferA @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) sparklessparkles.(package) sparkles.basebase.(package) sparkles.base.texttext.(module) sparkles.base.text.spanCanonical 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.TextSpanAn 8-byte byte range [startOffset, endOffset) into a source text.
TextSpan;
import (package) sparklessparkles.(package) sparkles.build_primitivesbuild_primitives.(module) sparkles.build_primitives.git_envThe 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) @safeRun git on a repository the caller names, never an inherited one.
runGit;
import (package) sparklessparkles.(package) sparkles.wiredwired.(module) sparkles.wired.sdlSDL 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.SdlNodeCopyable 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.SdlSpanHalf-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) sparklessparkles.(package) sparkles.wiredwired.(package) sparkles.wired.sdlsdl.(module) sparkles.wired.sdl.selectPath 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.SdlSelectorA 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 = stringstring[] (immutable global) immutable(string[]) standardize_build_settings.managedBuildTypesManaged 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.managedBuildTypesManaged 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 @safeImplements 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" ]));
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 @safeEagerly concatenates all of the ranges in ror together (with the GC)
into one array using sep as the separator if present.
join(" || ") ~ ")";
/// A setting by content: its name, its string values in order, and its one
/// `platform` attribute.
private struct (struct) standardize_build_settings.SettingA setting by content: its name, its string values in order, and its one
platform attribute.
Setting
{
(alias) object.string = stringstring (field) string standardize_build_settings.Setting.namename;
(alias) object.string = stringstring[] (field) string[] standardize_build_settings.Setting.valuesvalues;
(alias) object.string = stringstring (field) string standardize_build_settings.Setting.platformplatform;
}
/// Link settings an earlier policy put in configurations, now in build types.
private immutable (struct) standardize_build_settings.SettingA 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.legacySettingsLink settings an earlier policy put in configurations, now in build types.
legacySettings = [
(struct) standardize_build_settings.SettingA 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.SettingA 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.SettingA 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.SettingA 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 @safeWhether 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.SdlNodeCopyable 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 nodenode, in (struct) standardize_build_settings.SettingA setting by content: its name, its string values in order, and its one
platform attribute.
Setting (parameter) const(standardize_build_settings.Setting) settingsetting) @safe pure nothrow @nogc
{
import (package) stdstd.(package) std.algorithmalgorithm.(module) std.algorithm.comparisonThis 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
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) stdstd.(package) std.algorithmalgorithm.(module) std.algorithm.iterationThis 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
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) sparklessparkles.(package) sparkles.wiredwired.(module) sparkles.wired.sdlSDL backend for sparkles:wired — public surface.
sdl : (enum) sparkles.wired.sdl.document.SdlScalarKindExact semantic kind retained for every SDL scalar.
SdlScalarKind;
if ((parameter) sparkles.wired.sdl.document.SdlNode nodenode.sparkles.wired.sdl.document.SdlQualifiedName sparkles.wired.sdl.document.SdlNode.qualifiedName() const pure nothrow @nogc return scope @safeFull 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)[].lengthlength || (parameter) sparkles.wired.sdl.document.SdlNode nodenode.sparkles.wired.sdl.document.SdlQualifiedName sparkles.wired.sdl.document.SdlNode.qualifiedName() const pure nothrow @nogc return scope @safeFull stored name. The synthetic root returns the empty/default name.
qualifiedName.(field) const(char)[] sparkles.wired.sdl.document.SdlQualifiedName.localNameName after the prefix.
localName != (parameter) const(standardize_build_settings.Setting) settingsetting.(field) string standardize_build_settings.Setting.namename
|| (parameter) sparkles.wired.sdl.document.SdlNode nodenode.ulong sparkles.wired.sdl.document.SdlNode.childCount() const pure nothrow @nogc scope @safeNumber of direct children, including repeated names.
childCount || (parameter) sparkles.wired.sdl.document.SdlNode nodenode.ulong sparkles.wired.sdl.document.SdlNode.attributeCount() const pure nothrow @nogc scope @safeNumber of attributes, including duplicates.
attributeCount != 1 || (parameter) sparkles.wired.sdl.document.SdlNode nodenode.ulong sparkles.wired.sdl.document.SdlNode.valueCount() const pure nothrow @nogc scope @safeNumber of positional scalar values.
valueCount != (parameter) const(standardize_build_settings.Setting) settingsetting.(field) string[] standardize_build_settings.Setting.valuesvalues.(field) ulong const(string[]).lengthlength)
return false;
foreach ((local variable) sparkles.wired.sdl.document.SdlScalar valuevalue; (parameter) sparkles.wired.sdl.document.SdlNode nodenode.sparkles.wired.sdl.document.SdlValueRange sparkles.wired.sdl.document.SdlNode.byValue() const pure nothrow @nogc return scope @safeForward range over positional values in source order.
byValue)
if ((local variable) sparkles.wired.sdl.document.SdlScalar valuevalue.sparkles.wired.sdl.document.SdlScalarKind sparkles.wired.sdl.document.SdlScalar.kind() const pure nothrow @nogc scope @safeThe active payload kind.
kind != (enum) sparkles.wired.sdl.document.SdlScalarKindExact semantic kind retained for every SDL scalar.
SdlScalarKind.(enum value) sparkles.wired.sdl.document.SdlScalarKind.string_ = 3Decoded UTF-8 text.
string_)
return false;
const (local variable) const(sparkles.wired.sdl.document.SdlAttributeView) platformplatform = (parameter) sparkles.wired.sdl.document.SdlNode nodenode.sparkles.wired.sdl.document.SdlAttributeRange sparkles.wired.sdl.document.SdlNode.byAttribute() const pure nothrow @nogc return scope @safeForward 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 @safeForward-range primitives.
front;
return (local variable) const(sparkles.wired.sdl.document.SdlAttributeView) platformplatform.sparkles.wired.sdl.document.SdlQualifiedName sparkles.wired.sdl.document.SdlAttributeView.qualifiedName() const pure nothrow @nogc return scope @safeFull 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)[].lengthlength == 0
&& (local variable) const(sparkles.wired.sdl.document.SdlAttributeView) platformplatform.sparkles.wired.sdl.document.SdlQualifiedName sparkles.wired.sdl.document.SdlAttributeView.qualifiedName() const pure nothrow @nogc return scope @safeFull stored attribute name.
qualifiedName.(field) const(char)[] sparkles.wired.sdl.document.SdlQualifiedName.localNameName after the prefix.
localName == "platform"
&& (local variable) const(sparkles.wired.sdl.document.SdlAttributeView) platformplatform.sparkles.wired.sdl.document.SdlScalar sparkles.wired.sdl.document.SdlAttributeView.value() const pure nothrow @nogc return scope @safeBorrowed scalar value and its exact token span.
value.sparkles.wired.sdl.document.SdlScalarKind sparkles.wired.sdl.document.SdlScalar.kind() const pure nothrow @nogc scope @safeThe active payload kind.
kind == (enum) sparkles.wired.sdl.document.SdlScalarKindExact semantic kind retained for every SDL scalar.
SdlScalarKind.(enum value) sparkles.wired.sdl.document.SdlScalarKind.string_ = 3Decoded UTF-8 text.
string_
&& (local variable) const(sparkles.wired.sdl.document.SdlAttributeView) platformplatform.sparkles.wired.sdl.document.SdlScalar sparkles.wired.sdl.document.SdlAttributeView.value() const pure nothrow @nogc return scope @safeBorrowed scalar value and its exact token span.
value.const(char)[] sparkles.wired.sdl.document.SdlScalar.stringValue() const pure nothrow @nogc return scope @safeActive string payload.
stringValue == (parameter) const(standardize_build_settings.Setting) settingsetting.(field) string standardize_build_settings.Setting.platformplatform
&& (parameter) sparkles.wired.sdl.document.SdlNode nodenode.sparkles.wired.sdl.document.SdlValueRange sparkles.wired.sdl.document.SdlNode.byValue() const pure nothrow @nogc return scope @safeForward 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 @safeImplements 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" ]));
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 @safeCompares 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)
));
equal((parameter) const(standardize_build_settings.Setting) settingsetting.(field) string[] standardize_build_settings.Setting.valuesvalues);
}
/// 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 = stringstring string standardize_build_settings.normalize(string source) @safeNormalizes 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 = stringstring (parameter) string sourcesource) @safe
{
auto (local variable) sparkles.wired.sdl.reader.SdlParseResult!(Mallocator) parsedparsed = 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 @safeParses 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 sourcesource);
if ((local variable) sparkles.wired.sdl.reader.SdlParseResult!(Mallocator) parsedparsed.bool sparkles.wired.sdl.reader.SdlParseResult!(std.experimental.allocator.mallocator.Mallocator).hasError() const pure nothrow @nogc @safeWhether the parse succeeded, as on Expected.
hasError)
return (parameter) string sourcesource; // not ours to repair; `dub` reports it
auto (local variable) sparkles.wired.sdl.document.SdlNode rootroot = (local variable) sparkles.wired.sdl.reader.SdlParseResult!(Mallocator) parsedparsed.(field) sparkles.wired.sdl.document.SdlDocument!(Mallocator) sparkles.wired.sdl.reader.SdlParseResult!(std.experimental.allocator.mallocator.Mallocator).documentvalid 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 @safeBorrowed 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) editoreditor = 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 @safeConstructs 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) parsedparsed.(field) sparkles.wired.sdl.document.SdlDocument!(Mallocator) sparkles.wired.sdl.reader.SdlParseResult!(std.experimental.allocator.mallocator.Mallocator).documentvalid iff hasValue
document, (parameter) string sourcesource);
// 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.TextSpanAn 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 @safewholeLines((alias) object.size_t = ulongsize_t (parameter) ulong startstart, (alias) object.size_t = ulongsize_t (parameter) ulong endend)
{
while ((parameter) ulong startstart > 0 && (parameter) string sourcesource[(parameter) ulong startstart - 1] != '\n')
(parameter) ulong startstart--;
while ((parameter) ulong endend < (parameter) string sourcesource.(field) ulong string.lengthlength && (parameter) string sourcesource[(parameter) ulong endend] != '\n')
(parameter) ulong endend++;
return (struct) sparkles.base.text.span.TextSpanAn 8-byte byte range [startOffset, endOffset) into a source text.
TextSpan(cast(uint) (parameter) ulong startstart, cast(uint)((parameter) ulong endend < (parameter) string sourcesource.(field) ulong string.lengthlength ? (parameter) ulong endend + 1 : (parameter) ulong endend));
}
(struct) sparkles.wired.sdl.document.SdlSpanHalf-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 beginbegin, (local variable) sparkles.wired.sdl.document.SdlSpan endend, (local variable) sparkles.wired.sdl.document.SdlSpan legacylegacy;
foreach ((local variable) sparkles.wired.sdl.document.SdlComment commentcomment; (local variable) sparkles.wired.sdl.reader.SdlParseResult!(Mallocator) parsedparsed.(field) sparkles.wired.sdl.document.SdlDocument!(Mallocator) sparkles.wired.sdl.reader.SdlParseResult!(std.experimental.allocator.mallocator.Mallocator).documentvalid 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 @safeEvery comment in the source, in source order (editing SDE6).
comments)
{
const (local variable) const(char[]) texttext = (local variable) sparkles.wired.sdl.document.SdlComment commentcomment.(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.spanThe 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 @safeThe covered bytes of text, the source the span was made from.
sliceOf((parameter) string sourcesource);
if ((local variable) const(char[]) texttext.bool std.algorithm.searching.startsWith!("a == b", const(char)[], string)(const(char)[] doesThisStart, string withThis) pure nothrow @nogc @safeChecks 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.
startsWith("// BEGIN managed build types"))
(local variable) sparkles.wired.sdl.document.SdlSpan beginbegin = (local variable) sparkles.wired.sdl.document.SdlComment commentcomment.(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.spanThe comment's bytes, delimiters included, newline excluded.
span;
else if ((local variable) const(char[]) texttext.bool std.algorithm.searching.startsWith!("a == b", const(char)[], string)(const(char)[] doesThisStart, string withThis) pure nothrow @nogc @safeChecks 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.
startsWith("// END managed build types"))
(local variable) sparkles.wired.sdl.document.SdlSpan endend = (local variable) sparkles.wired.sdl.document.SdlComment commentcomment.(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.spanThe comment's bytes, delimiters included, newline excluded.
span;
else if ((local variable) sparkles.wired.sdl.document.SdlComment commentcomment.(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.spanThe comment's bytes, delimiters included, newline excluded.
span.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst 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 = 222LUlength <= (parameter) string sourcesource.(field) ulong string.lengthlength
&& (parameter) string sourcesource[(local variable) sparkles.wired.sdl.document.SdlComment commentcomment.(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.spanThe comment's bytes, delimiters included, newline excluded.
span.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst byte offset inside the range.
startOffset .. (local variable) sparkles.wired.sdl.document.SdlComment commentcomment.(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.spanThe comment's bytes, delimiters included, newline excluded.
span.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst 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 = 222LUlength]
== (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 legacylegacy = (local variable) sparkles.wired.sdl.document.SdlComment commentcomment.(field) sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlComment.spanThe comment's bytes, delimiters included, newline excluded.
span;
}
const (local variable) const(bool) hasRegionhasRegion = (local variable) sparkles.wired.sdl.document.SdlSpan beginbegin.bool sparkles.wired.sdl.document.SdlSpan.isValid() const pure nothrow @nogc @safeWhether the span names source bytes at all.
isValid && (local variable) sparkles.wired.sdl.document.SdlSpan endend.bool sparkles.wired.sdl.document.SdlSpan.isValid() const pure nothrow @nogc @safeWhether the span names source bytes at all.
isValid && (local variable) sparkles.wired.sdl.document.SdlSpan beginbegin.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst byte offset inside the range.
startOffset < (local variable) sparkles.wired.sdl.document.SdlSpan endend.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst byte offset inside the range.
startOffset;
const (local variable) const(sparkles.base.text.span.TextSpan) regionregion = (local variable) const(bool) hasRegionhasRegion ? sparkles.base.text.span.TextSpan standardize_build_settings.normalize.wholeLines(ulong start, ulong end) pure nothrow @nogc @safewholeLines((local variable) sparkles.wired.sdl.document.SdlSpan beginbegin.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst byte offset inside the range.
startOffset, (local variable) sparkles.wired.sdl.document.SdlSpan endend.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst byte offset inside the range.
startOffset) : (struct) sparkles.base.text.span.TextSpanAn 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 @safeinRegion(scope (struct) sparkles.wired.sdl.document.SdlNodeCopyable 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 nodenode)
=> (local variable) const(bool) hasRegionhasRegion && (parameter) sparkles.wired.sdl.document.SdlNode nodenode.sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlNode.span() const pure nothrow @nogc scope @safeComplete declaration span, from the name through the terminator.
span.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst byte offset inside the range.
startOffset >= (local variable) const(sparkles.base.text.span.TextSpan) regionregion.(field) uint sparkles.base.text.span.TextSpan.startOffsetstartOffset
&& (parameter) sparkles.wired.sdl.document.SdlNode nodenode.sparkles.wired.sdl.document.SdlSpan sparkles.wired.sdl.document.SdlNode.span() const pure nothrow @nogc scope @safeComplete declaration span, from the name through the terminator.
span.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst byte offset inside the range.
startOffset < (local variable) const(sparkles.base.text.span.TextSpan) regionregion.(field) uint sparkles.base.text.span.TextSpan.endOffsetendOffset;
if ((local variable) sparkles.wired.sdl.document.SdlSpan legacylegacy.bool sparkles.wired.sdl.document.SdlSpan.isValid() const pure nothrow @nogc @safeWhether the span names source bytes at all.
isValid)
{
const (local variable) const(uint) startstart = sparkles.base.text.span.TextSpan standardize_build_settings.normalize.wholeLines(ulong start, ulong end) pure nothrow @nogc @safewholeLines((local variable) sparkles.wired.sdl.document.SdlSpan legacylegacy.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst byte offset inside the range.
startOffset, (local variable) sparkles.wired.sdl.document.SdlSpan legacylegacy.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst byte offset inside the range.
startOffset).(field) uint sparkles.base.text.span.TextSpan.startOffsetstartOffset;
(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) editoreditor.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.TextSpanAn 8-byte byte range [startOffset, endOffset) into a source text.
TextSpan((local variable) const(uint) startstart, cast(uint)((local variable) sparkles.wired.sdl.document.SdlSpan legacylegacy.uint sparkles.wired.sdl.document.SdlSpan.startOffset() const pure nothrow @nogc @safeFirst 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 = 222LUlength)), "");
}
void void standardize_build_settings.normalize.removeLegacySettings(scope sparkles.wired.sdl.document.SdlNode parent) pure nothrow @nogc @saferemoveLegacySettings(scope (struct) sparkles.wired.sdl.document.SdlNodeCopyable 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 parentparent)
{
(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) editoreditor.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 parentparent.sparkles.wired.sdl.document.SdlChildRange sparkles.wired.sdl.document.SdlNode.byChild() const pure nothrow @nogc return scope @safeForward 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 @safefilter`!(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 ]));
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 @saferemoveLegacySettings((local variable) sparkles.wired.sdl.document.SdlNode rootroot);
// 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 configurationsconfigurations = (struct) sparkles.wired.sdl.select.SdlSelectorA 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) @safeValidates 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 @safeReturns 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 configurationconfiguration; (local variable) sparkles.wired.sdl.select.SdlSelector configurationsconfigurations.sparkles.wired.sdl.select.SdlSelectedNodes sparkles.wired.sdl.select.SdlSelector.nodes(return scope sparkles.wired.sdl.document.SdlNode start) @safeThe nodes the path selects below start that pass the filter.
nodes((local variable) sparkles.wired.sdl.document.SdlNode rootroot))
if (!bool standardize_build_settings.normalize.inRegion(scope sparkles.wired.sdl.document.SdlNode node) pure nothrow @nogc @safeinRegion((local variable) sparkles.wired.sdl.document.SdlNode configurationconfiguration))
void standardize_build_settings.normalize.removeLegacySettings(scope sparkles.wired.sdl.document.SdlNode parent) pure nothrow @nogc @saferemoveLegacySettings((local variable) sparkles.wired.sdl.document.SdlNode configurationconfiguration);
auto (local variable) sparkles.wired.sdl.select.SdlSelector staleBuildTypesstaleBuildTypes = (struct) sparkles.wired.sdl.select.SdlSelectorA 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) @safeValidates 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 @safeReturns 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) editoreditor.editor.removeremove((local variable) sparkles.wired.sdl.select.SdlSelector staleBuildTypesstaleBuildTypes.sparkles.wired.sdl.select.SdlSelectedNodes sparkles.wired.sdl.select.SdlSelector.nodes(return scope sparkles.wired.sdl.document.SdlNode start) @safeThe nodes the path selects below start that pass the filter.
nodes((local variable) sparkles.wired.sdl.document.SdlNode rootroot).filter!(node => !inRegion(node)));
if ((local variable) const(bool) hasRegionhasRegion)
{
if ((local variable) const(sparkles.base.text.span.TextSpan) regionregion.const(char)[] sparkles.base.text.span.TextSpan.sliceOf(return scope const(char)[] text) const pure nothrow @nogc @safeSlices text by this span.
sliceOf((parameter) string sourcesource) != (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) editoreditor.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) regionregion, (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) editoreditor.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 rootroot, ((parameter) string sourcesource.bool std.algorithm.searching.endsWith!("a == b", string, string)(string doesThisEnd, string withThis) pure nothrow @nogc @safeChecks if the given range ends with (one of) the given needle(s).
The reciprocal of startsWith.
endsWith("\n\n") || (parameter) string sourcesource.(field) ulong string.lengthlength == 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) outputoutput;
(struct) std.experimental.allocator.mallocator.MallocatorThe 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 allocatorallocator;
const (local variable) const(_error_) writtenwritten = (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) editoreditor.(void) voidwrite((local variable) sparkles.base.buffer.Buffer!(char, 16LU, cast(Storage)cast(ubyte)7u) outputoutput, (local variable) std.experimental.allocator.mallocator.Mallocator allocatorallocator);
assert(!written.(field) _error_ written.hasErrorhasError, written.written.hasErrorhasError ? written.error.toString : "");
return (local variable) sparkles.base.buffer.Buffer!(char, 16LU, cast(Storage)cast(ubyte)7u) outputoutput[].string object.idup!char(char[] a) pure nothrow @property @safeProvide 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() @safeRegeneration 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) sourcesource = "name \"sample\"\nconfiguration \"library-inline\" {\n"
~ " dflags \"-enable-cross-module-inlining\" \"-linkonce-templates\" platform=\"ldc\"\n}\n";
const (local variable) const(string) normalizednormalized = string standardize_build_settings.normalize(string source) @safeNormalizes 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) sourcesource);
assert(string standardize_build_settings.normalize(string source) @safeNormalizes 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) normalizednormalized) == (local variable) const(string) normalizednormalized);
assert((local variable) const(string) normalizednormalized.bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safeConvenience 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")));
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() @safeOld 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) sourcesource = "name \"sample\"\nconfiguration \"unittest\" {\n"
~ " dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
const (local variable) const(string) normalizednormalized = string standardize_build_settings.normalize(string source) @safeNormalizes 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) sourcesource);
assert(!(local variable) const(string) normalizednormalized[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 = 2393LUlength].bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safeConvenience 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")));
canFind("--linker=gold"));
assert((local variable) const(string) normalizednormalized.bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safeConvenience 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")));
canFind("configuration \"unittest\" {\n}"));
assert((local variable) const(string) normalizednormalized.bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safeConvenience 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")));
canFind(`buildOptions "unittests" "debugMode" "debugInfo"`));
assert((local variable) const(string) normalizednormalized.bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safeConvenience 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")));
canFind(`dflags "--linker=lld" platform="linux-ldc"`));
assert((local variable) const(string) normalizednormalized.bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safeConvenience 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")));
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() @safeOnly 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) stdstd.(module) std.arrayFunctions 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
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) crlfcrlf = "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) @safeNormalizes 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) crlfcrlf) == "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 @safeReplace 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");
replace("\n", "\r\n"));
const (local variable) const(string) legacylegacy = "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) @safeNormalizes 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) legacylegacy) == "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) rewordedreworded = "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) @safeNormalizes 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) rewordedreworded) == (local variable) const(string) rewordedreworded);
// An up-to-date file is left byte for byte, wherever its region sits.
const (local variable) const(string) currentcurrent = "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) @safeNormalizes 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) currentcurrent) == (local variable) const(string) currentcurrent);
// A stale region is replaced in place.
const (local variable) const(string) stalestale = "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) @safeNormalizes 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) stalestale) == "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() @safeA 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) sourcesource = "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) normalizednormalized = string standardize_build_settings.normalize(string source) @safeNormalizes 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) sourcesource);
assert((local variable) const(string) normalizednormalized == "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) normalizednormalized);
}
/// 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() @safeA 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) sourcesource = "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) normalizednormalized = string standardize_build_settings.normalize(string source) @safeNormalizes 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) sourcesource);
assert((local variable) const(string) normalizednormalized == (local variable) const(string) sourcesource ~ "\n" ~ managed, (local variable) const(string) normalizednormalized);
}
/// Package-specific calibration types are outside the managed policy.
@("buildSettings.normalize.preservesCalibration")
@safe void standardize_build_settings.__unittest_L317_C7() @safePackage-specific calibration types are outside the managed policy.
unittest
{
const (local variable) const(string) sourcesource = "buildType \"bench-plain\" {\n"
~ " dflags \"--link-defaultlib-shared\" \"--linker=gold\" platform=\"linux-ldc\"\n}\n";
assert(string standardize_build_settings.normalize(string source) @safeNormalizes 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) sourcesource).bool std.algorithm.searching.canFind!().canFind!(string, string)(string haystack, scope string needle) pure nothrow @nogc @safeConvenience 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")));
canFind((local variable) const(string) sourcesource));
}
version (unittestunittest) {} 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;
}