aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/variable.hxx
AgeCommit message (Collapse)AuthorFilesLines
2024-02-20Add json_map and json_set buildfile value typesBoris Kolpackov1-1/+21
These expose the std::map<json_value,json_value> and std::set<json_value> types to buildfiles. New functions: $size(<json-set>) $size(<json-map>) $keys(<json-map>) Note that the $keys() function returns the list of map key as a json array. For example: m = [json_map] 2@([json] a@1 b@2) 1@([json] 1 2) s = [json_set] ([json] x@1 y@2) ([json] a@1 b@2) print ($m[2][b]) # 2 print ($s[([json] y@2 x@1)]) # true
2024-02-20Make json value type prepend non-overriding for consistency with mapBoris Kolpackov1-0/+6
2024-02-20Add string_set buildfile value typeBoris Kolpackov1-0/+22
This exposes the std::set<std::string> type to buildfiles. New functions: $size(<string-set>) Subscript returns true if the value is present and false otherwise (so it is mapped to std::set::contains()). For example: set = [string_set] a b c if ($set[b]) ... Note that append (+=) and prepend (=+) have the same semantics (std::set::insert()). For example: set = [string_set] a b set += c b # a b c set =+ d b # a b c d Example of iteration: set = [string_set] a b c for k: $set ...
2024-02-19Add string_map buildfile value typeBoris Kolpackov1-7/+10
This exposes the std::map<std::string,std::string> type to buildfiles. New functions: $size(<string-map>) $keys(<string-map>) Subscript can be used to lookup a value by key. The result is [null] if there is no value associated with the specified key. For example: map = [string_map] a@1 b@2 c@3 b = ($map[b]) # 2 if ($map[z] == [null]) ... Note that append (+=) is overriding (like std::map::insert_or_assign()) while prepend (=+) is not (like std::map::insert()). In a sense, whatever appears last (from left to right) is kept, which is consistent with what we expect to happen when specifying the same key repeatedly in a literal representation. For example: map = [string_map] a@0 b@2 a@1 # a@1 b@2 map += b@0 c@3 # a@1 b@0 c@3 map =+ b@1 d@4 # a@1 b@0 c@3 d@4 Example of iteration: map = [string_map] a@1 b@2 c@3 for p: $map { k = $first($p) v = $second($p) } While the subscript is mapped to key lookup only, index-based access can be implemented (with a bit of overhead) using the $keys() function: map = [string_map] a@1 b@2 c@3 keys = $keys($m) for i: $integer_sequence(0, $size($keys)) { k = ($keys[$i]) v = ($map[$k]) } Also, this commit changes the naming of other template-based value types (not exposed as buildfile value types) to use C++ template id-like names (e.g., map<string,optional<bool>>).
2024-02-07Add experimental support for JSON value typesBoris Kolpackov1-0/+61
New types: json json_array json_object New functions: $json.value_type(<json>) $json.value_size(<json>) $json.member_{name,value}(<json-member>) $json.object_names(<json-object>) $json.array_size(<json-array>) $json.array_find(<json-array>, <json>) $json.array_find_index(<json-array>, <json>) $json.load(<path>) $json.parse(<text>) $json.serialize(<json>[, <indentation>]) For example, to load a JSON value from a file: j = $json.load($src_base/board.json) Or to construct it in a buildfile: j = [json] one@1 two@([json] 2 3 4) three@([json] x@1 y@-1) This can also be done incrementally with append/prepend: j = [json_object] j += one@1 j += two@([json] 2 3 4) j += three@([json] x@1 y@-1) Instead of using this JSON-like syntax, one can also specify valid JSON input text: j = [json] '{"one":1, "two":[2, 3, 4], "three":{"x":1, "y":-1}' Besides the above set of functions, other handy ways to access components in a JSON value are iteration and subscript. For example: for m: $j print $member_name($m) $member_value($m) print ($j[three]) A subscript can be nested: print ($j[two][1]) print ($j[three][x]) While a JSON value can be printed directly like any other value, the representation will not be pretty-printed. As a result, for complex JSON values, printing a serialized representation might be a more readable option: info $serialize($j)
2024-02-06Add support for value type-specific subscript and iterationBoris Kolpackov1-0/+22
2023-08-09Complete and cleanup function documentation in preparation for auto-extractionBoris Kolpackov1-2/+3
Also: - Move the $target.*() function family from functions-name.cxx to separate functions-target.cxx. - Get rid of the separate $process_path_ex.*() family, merging it with $process_path.*().
2023-06-12Hack around GCC 13 -Wdangling-reference false positivesBoris Kolpackov1-6/+6
See GCC bugs 107532, 110213.
2023-05-09Add support for dumping build system state in JSON format (GH issue #182)Boris Kolpackov1-1/+3
Specifically: 1. New --dump-format option. Valid values are `buildfile` and `json-v0.1`. 2. The --dump option now recognizes two additional values: `match-pre` and `match-post` to dump the state of pre/post-operations. The `match` value now only triggers dumping of the main operation.
2023-03-02Replace deprecated std::aligned_storage with alignasBoris Kolpackov1-3/+4
Based on patch by Matthew Krupcale.
2022-12-15Add noexcept to move constructors and move assignment operatorsKaren Arutyunov1-3/+9
2022-12-14Improve empty simple value to empty list of names reduction heuristicsBoris Kolpackov1-10/+18
Specifically, do not reduce typed RHS empty simple values for prepend/append and additionally for assignment provided LHS is typed and is a container.
2022-11-30Reserve targets, variables to avoid rehashingBoris Kolpackov1-0/+19
2022-10-13Work around Clang 6, 7 codegen issuesBoris Kolpackov1-1/+0
2022-10-13Fix couple of corner cases in public/private variable modelBoris Kolpackov1-2/+2
2022-10-13Add visibility, overridable variable attributesBoris Kolpackov1-0/+3
2022-10-13Switch to public/private variables modelBoris Kolpackov1-2/+9
Now unqualified variables are project-private and can be typified.
2022-10-11Factor variable patterns out of variable_pool into separate variable_patternsBoris Kolpackov1-67/+131
We have patterns only for the public variables pool.
2022-10-10Preparatory work for public/private variable distinctionBoris Kolpackov1-32/+107
We still always use the public var_pool from context but where required, all access now goes through scope::var_pool().
2022-10-10Use term shared instead of global for scope, var pool, etcBoris Kolpackov1-18/+20
2022-07-07Use new cmdline type for canned command lines in {Build,Test}scriptBoris Kolpackov1-0/+29
2022-07-05Recognize special .for_install variable suffix in library user metadataBoris Kolpackov1-1/+16
2022-06-03Reset value::extra on variable_map value change/version incrementBoris Kolpackov1-4/+15
The reset on each modification semantics is used to implement the default value distinction as currently done in the config module but later probably will be done for ?= and $origin().
2022-06-03Add another variable_map::insert() overloadBoris Kolpackov1-0/+6
2022-05-23Add ability to iterate over variable poolBoris Kolpackov1-7/+14
2022-05-22Add support for variable patterns in config.config.disfigureBoris Kolpackov1-0/+3
2022-03-29Add variable_map::lookup_namespace(string) overloadBoris Kolpackov1-0/+10
2021-09-28Adapt to libbutl headers extension change from .mxx to .hxxKaren Arutyunov1-2/+2
2021-09-02Don't consider aliasing in variable override lookupBoris Kolpackov1-3/+5
2021-07-23Remove duplicate friend declaration to make GCC 4.9 happyBoris Kolpackov1-2/+0
2021-07-23Reserve variable names/components that start with underscore to build2 coreBoris Kolpackov1-10/+13
2021-06-21Add support for automatic generation of symbol exporting .def fileBoris Kolpackov1-2/+1
2021-05-28Add support for regex-based target type/pattern specific variablesBoris Kolpackov1-4/+60
This is in addition to the already supported path-based target type/pattern specific variables. For example: hxx{*}: x = y # path-based hxx{~/.*/}: x = y # regex-based
2021-05-28Ban conversion of patterns to valuesBoris Kolpackov1-0/+2
Also improve conversion diagnostic.
2021-05-28Tie loose ends in target type/pattern-specific matchingBoris Kolpackov1-1/+1
2021-05-28Make notion of name pattern explicit, fix various related loose endsBoris Kolpackov1-2/+2
2021-04-20Detect environment changes in ad hoc recipesBoris Kolpackov1-2/+2
2021-04-04Add base functionality for hermetic build configurationshermeticBoris Kolpackov1-7/+12
2021-02-09Minor simplificationBoris Kolpackov1-1/+1
2021-01-30Add std::{map, multimap} to types.hxxBoris Kolpackov1-11/+10
Seeing that std::map is becoming a common Buildfile variable type.
2021-01-28Make std::map prepend (=+) overriding (like insert_or_assign())Boris Kolpackov1-5/+19
2021-01-22Add support for optional pair halves in variable valuesBoris Kolpackov1-31/+91
2020-11-11Make value_traits<bool>::convert() non-modifyingBoris Kolpackov1-1/+4
2020-08-24Add copying version of convert<T>(value)Boris Kolpackov1-0/+6
2020-08-12Add int64 and int64s variable typesBoris Kolpackov1-2/+34
2020-08-11Add another variable_pool::insert() overloadBoris Kolpackov1-0/+9
2020-06-09Make metadata variable prefix mandatoryBoris Kolpackov1-1/+4
While we could automatically set it if the target is imported, there is nothing we can do if the target is used in the same project. So to avoid confusion we make it mandatory.
2020-06-03Fix $process.run() to properly handle proces_path_exKaren Arutyunov1-4/+10
2020-06-03Get rid of remaining typedef'sBoris Kolpackov1-1/+1
2020-06-02Add process_path_ex with program stable name and checksumBoris Kolpackov1-2/+22