Coverage Report

Created: 2026-09-14 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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 <iterator>
6
#include <sstream>
7
#include <string>
8
#include <vector>
9
10
#include <cm3p/json/value.h>
11
12
#include "cmJSONState.h"
13
#include "cmUVProcessChain.h"
14
#include "cmUVStream.h"
15
16
cm::optional<Json::Value> cmParsePlist(std::string const& filename)
17
0
{
18
0
  cmUVProcessChainBuilder builder;
19
0
  builder.AddCommand(
20
0
    { "/usr/bin/plutil", "-convert", "json", "-o", "-", filename });
21
0
  builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT);
22
23
0
  auto chain = builder.Start();
24
0
  chain.Wait();
25
26
0
  auto const& status = chain.GetStatus(0);
27
0
  if (status.ExitStatus != 0) {
28
0
    return cm::nullopt;
29
0
  }
30
31
  // Buffer plutil's output into a seekable stream. cmJSONState must be able
32
  // peek at a leading BOM, which the process pipe behind cmUVIStream can't
33
  // handle.
34
0
  cmUVIStream outputStream(chain.OutputStream());
35
0
  std::string output{ std::istreambuf_iterator<char>(outputStream),
36
0
                      std::istreambuf_iterator<char>() };
37
0
  std::istringstream jsonStream(output);
38
39
0
  Json::Value value;
40
0
  cmJSONState parseState(jsonStream, &value, cmJSONState::StrictMode::Relaxed);
41
0
  if (!parseState.errors.empty()) {
42
0
    return cm::nullopt;
43
0
  }
44
0
  return cm::optional<Json::Value>(value);
45
0
}