summaryrefslogtreecommitdiff
path: root/src/third_party/scripts/yaml-cpp_get_sources.sh
blob: 4b06f88244f5d431d206eb857720e872a8a4115b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# This script downloads and imports yaml-cpp
# It can be run on Linux, Mac OS X or Windows WSL.
# Actual integration into the build system is not done by this script.

set -xeuo pipefail

NAME=yaml-cpp
VERSION=0.6.2
BRANCH="${NAME}-${VERSION}"
GIT_REPO=https://github.com/jbeder/yaml-cpp.git

GIT_EXE=git
if grep -q Microsoft /proc/version; then
    GIT_EXE=git.exe
fi

DEST_DIR="$("${GIT_EXE}" rev-parse --show-toplevel)/src/third_party/${NAME}-${VERSION}"
if grep -q Microsoft /proc/version; then
    DEST_DIR=$(wslpath -u "${DEST_DIR}")
fi

CLONE_DEST="${DEST_DIR}/${NAME}"
if grep -q Microsoft /proc/version; then
    CLONE_DEST=$(wslpath -m "${CLONE_DEST}")
fi

echo "dest: ${DEST_DIR}"

[[ -d ${CLONE_DEST} ]] && mv "${CLONE_DEST}" "${CLONE_DEST}.old"
"${GIT_EXE}" clone --branch="${BRANCH}" "${GIT_REPO}" "${CLONE_DEST}"


# Apply patches

# These patches are backports for CVE and compile fixes, so we need to remove
# them when we finally upgrade to a version that has them.
# TODO: https://jira.mongodb.org/browse/SERVER-48258

# Patch CVE-2019-6292 and CVE-2019-6285
# We're using diff-tree here because the commit includes a change to a test
# which doesn't exist in this version, so we exclude it from the patch that
# gets generated.
git -C "${CLONE_DEST}" diff-tree -p 4edff1fa5dbfca16fc72d89870841bee89f8ef89 -- \
    include/yaml-cpp/depthguard.h                                               \
    src/depthguard.cpp                                                          \
    src/singledocparser.h                                                       \
| git -C "${CLONE_DEST}" apply

# Fix error C3646 on VS2017 due to _NOEXCEPT override specifier
git -C "${CLONE_DEST}" cherry-pick -x 0f9a586ca1dc29c2ecb8dd715a315b93e3f40f79


# Prune sources

echo "Prune tree"
rm -rf "${CLONE_DEST}/.git"
rm -rf "${CLONE_DEST}/test"
rm -rf "${CLONE_DEST}/util"
rm -rf "${CLONE_DEST}/docs"
rm -f "${CLONE_DEST}/BUILD.bazel"
rm -f "${CLONE_DEST}/WORKSPACE"
rm -f "${CLONE_DEST}/CMakeLists.txt"
rm -f "${CLONE_DEST}/"*.cmake*
rm -f "${CLONE_DEST}/yaml-cpp.pc.in"

[[ -d ${CLONE_DEST}.old ]] && rm -rf "${CLONE_DEST}.old"


# Generate the SConscript

( cat > "${DEST_DIR}/SConscript" ) << ___EOF___
# -*- mode: python; -*-
# NOTE: This file is auto-generated by "$(basename $0)" - DO NOT EDIT

Import("env")

# Create a new environment since this one doesn't build without errors when using -Wno-virtual-dtor
env = env.Clone()

try:
    env['CXXFLAGS'].remove('-Wnon-virtual-dtor')
    env['CCFLAGS'].remove('-Wall')
except ValueError:
    pass

env.InjectThirdParty('yaml', 'CPPDEFINES')

env.Library(
    target="yaml",
    source=[
        "yaml-cpp/src/binary.cpp",
        "yaml-cpp/src/contrib/graphbuilder.cpp",
        "yaml-cpp/src/contrib/graphbuilderadapter.cpp",
        "yaml-cpp/src/convert.cpp",
        "yaml-cpp/src/depthguard.cpp",
        "yaml-cpp/src/directives.cpp",
        "yaml-cpp/src/emit.cpp",
        "yaml-cpp/src/emitfromevents.cpp",
        "yaml-cpp/src/emitter.cpp",
        "yaml-cpp/src/emitterstate.cpp",
        "yaml-cpp/src/emitterutils.cpp",
        "yaml-cpp/src/exceptions.cpp",
        "yaml-cpp/src/exp.cpp",
        "yaml-cpp/src/memory.cpp",
        "yaml-cpp/src/node.cpp",
        "yaml-cpp/src/node_data.cpp",
        "yaml-cpp/src/nodebuilder.cpp",
        "yaml-cpp/src/nodeevents.cpp",
        "yaml-cpp/src/null.cpp",
        "yaml-cpp/src/ostream_wrapper.cpp",
        "yaml-cpp/src/parse.cpp",
        "yaml-cpp/src/parser.cpp",
        "yaml-cpp/src/regex_yaml.cpp",
        "yaml-cpp/src/scanner.cpp",
        "yaml-cpp/src/scanscalar.cpp",
        "yaml-cpp/src/scantag.cpp",
        "yaml-cpp/src/scantoken.cpp",
        "yaml-cpp/src/simplekey.cpp",
        "yaml-cpp/src/singledocparser.cpp",
        "yaml-cpp/src/stream.cpp",
        "yaml-cpp/src/tag.cpp",
    ])
___EOF___

echo "Done"