/src/CMake/Source/cmPlistParser.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmPlistParser.h" |
4 | | |
5 | | #include <vector> |
6 | | |
7 | | #include <cm3p/json/reader.h> |
8 | | #include <cm3p/json/value.h> |
9 | | |
10 | | #include "cmUVProcessChain.h" |
11 | | #include "cmUVStream.h" |
12 | | |
13 | | cm::optional<Json::Value> cmParsePlist(std::string const& filename) |
14 | 0 | { |
15 | 0 | cmUVProcessChainBuilder builder; |
16 | 0 | builder.AddCommand( |
17 | 0 | { "/usr/bin/plutil", "-convert", "json", "-o", "-", filename }); |
18 | 0 | builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT); |
19 | |
|
20 | 0 | auto chain = builder.Start(); |
21 | 0 | chain.Wait(); |
22 | |
|
23 | 0 | auto const& status = chain.GetStatus(0); |
24 | 0 | if (status.ExitStatus != 0) { |
25 | 0 | return cm::nullopt; |
26 | 0 | } |
27 | | |
28 | 0 | Json::Reader reader; |
29 | 0 | Json::Value value; |
30 | 0 | cmUVIStream outputStream(chain.OutputStream()); |
31 | 0 | if (!reader.parse(outputStream, value)) { |
32 | 0 | return cm::nullopt; |
33 | 0 | } |
34 | 0 | return cm::optional<Json::Value>(value); |
35 | 0 | } |