Skip to content

Commit 32fa496

Browse files
authored
Merge pull request #8 from nkcsgexi/update-branch
Update Swift fork of cmark with upstream cmark repository
2 parents b00c889 + cd8a1cd commit 32fa496

File tree

149 files changed

+20205
-28644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+20205
-28644
lines changed

.travis.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ language: c
88
compiler:
99
- clang
1010
- gcc
11+
matrix:
12+
include:
13+
- os: linux
14+
compiler: gcc
15+
env: CMAKE_OPTIONS="-DCMARK_SHARED=OFF"
1116
addons:
1217
apt:
1318
# we need a more recent cmake than travis/linux provides (at least 2.8.9):
1419
sources:
1520
- kubuntu-backports
21+
- kalakris-cmake
1622
packages:
1723
- cmake
1824
- python3
@@ -23,14 +29,10 @@ before_install:
2329
then
2430
echo "Building without python3, to make sure that works."
2531
fi
32+
2633
script:
27-
- make
34+
- (mkdir -p build && cd build && cmake $CMAKE_OPTIONS ..)
2835
- make test
29-
- |
30-
if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]
31-
then
32-
make roundtrip_test
33-
fi
3436
- |
3537
if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]
3638
then

CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
project(cmark)
21
cmake_minimum_required(VERSION 2.8.9)
2+
3+
# prevent ugly developer warnings because version is set directly, not through project()
4+
# it should be redone properly by using VERSION in project() if on CMake 3.x
5+
if(CMAKE_MAJOR_VERSION GREATER 2)
6+
cmake_policy(SET CMP0048 OLD)
7+
endif()
8+
9+
project(cmark)
10+
311
include("FindAsan.cmake")
412

513
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
@@ -9,14 +17,17 @@ endif()
917
set(PROJECT_NAME "cmark")
1018

1119
set(PROJECT_VERSION_MAJOR 0)
12-
set(PROJECT_VERSION_MINOR 22)
13-
set(PROJECT_VERSION_PATCH 0)
20+
set(PROJECT_VERSION_MINOR 28)
21+
set(PROJECT_VERSION_PATCH 3)
1422
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} )
1523

1624
option(CMARK_TESTS "Build cmark tests and enable testing" ON)
25+
option(CMARK_STATIC "Build static libcmark library" ON)
26+
option(CMARK_SHARED "Build shared libcmark library" ON)
27+
option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
1728

1829
add_subdirectory(src)
19-
if(CMARK_TESTS)
30+
if(CMARK_TESTS AND (CMARK_SHARED OR CMARK_STATIC))
2031
add_subdirectory(api_test)
2132
endif()
2233
add_subdirectory(man)

COPYING

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727

2828
-----
2929

30-
houdini.h, houdini_href_e.c, houdini_html_e.c, houdini_html_u.c,
31-
html_unescape.gperf, html_unescape.h
30+
houdini.h, houdini_href_e.c, houdini_html_e.c, houdini_html_u.c
3231

3332
derive from https://github.com/vmg/houdini (with some modifications)
3433

@@ -104,7 +103,7 @@ DEALINGS IN THE SOFTWARE.
104103

105104
-----
106105

107-
The normalization code in runtests.py was derived from the
106+
The normalization code in normalize.py was derived from the
108107
markdowntest project, Copyright 2013 Karl Dubost:
109108

110109
The MIT License (MIT)
@@ -169,24 +168,3 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
169168
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
170169
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
171170
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
172-
173-
-----
174-
175-
The normalization code in runtests.py was derived from the
176-
markdowntest project, Copyright 2013 Karl Dubost:
177-
178-
The MIT License (MIT)
179-
180-
Copyright (c) 2013 Karl Dubost
181-
182-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
183-
184-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
185-
186-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
187-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
188-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
189-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
190-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
191-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
192-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,28 @@ SITE=_site
99
SPECVERSION=$(shell perl -ne 'print $$1 if /^version: *([0-9.]+)/' $(SPEC))
1010
FUZZCHARS?=2000000 # for fuzztest
1111
BENCHDIR=bench
12+
BENCHSAMPLES=$(wildcard $(BENCHDIR)/samples/*.md)
1213
BENCHFILE=$(BENCHDIR)/benchinput.md
1314
ALLTESTS=alltests.md
1415
NUMRUNS?=10
1516
CMARK=$(BUILDDIR)/src/cmark
17+
CMARK_FUZZ=$(BUILDDIR)/src/cmark-fuzz
1618
PROG?=$(CMARK)
17-
BENCHINP?=README.md
1819
VERSION?=$(SPECVERSION)
1920
RELEASE?=CommonMark-$(VERSION)
2021
INSTALL_PREFIX?=/usr/local
2122
CLANG_CHECK?=clang-check
23+
CLANG_FORMAT=clang-format -style llvm -sort-includes=0 -i
24+
AFL_PATH?=/usr/local/bin
2225

23-
.PHONY: all cmake_build spec leakcheck clean fuzztest dingus upload test update-site upload-site debug ubsan asan mingw archive bench format update-spec afl clang-check
26+
.PHONY: all cmake_build leakcheck clean fuzztest test debug ubsan asan mingw archive newbench bench format update-spec afl clang-check libFuzzer
2427

2528
all: cmake_build man/man3/cmark.3
2629

2730
$(CMARK): cmake_build
2831

2932
cmake_build: $(BUILDDIR)
30-
@make -j2 -C $(BUILDDIR)
33+
@$(MAKE) -j2 -C $(BUILDDIR)
3134
@echo "Binaries can be found in $(BUILDDIR)/src"
3235

3336
$(BUILDDIR):
@@ -41,52 +44,59 @@ $(BUILDDIR):
4144
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
4245

4346
install: $(BUILDDIR)
44-
make -C $(BUILDDIR) install
47+
$(MAKE) -C $(BUILDDIR) install
4548

4649
debug:
4750
mkdir -p $(BUILDDIR); \
4851
cd $(BUILDDIR); \
4952
cmake .. -DCMAKE_BUILD_TYPE=Debug; \
50-
make
53+
$(MAKE)
5154

5255
ubsan:
5356
mkdir -p $(BUILDDIR); \
5457
cd $(BUILDDIR); \
5558
cmake .. -DCMAKE_BUILD_TYPE=Ubsan; \
56-
make
59+
$(MAKE)
5760

5861
asan:
5962
mkdir -p $(BUILDDIR); \
6063
cd $(BUILDDIR); \
6164
cmake .. -DCMAKE_BUILD_TYPE=Asan; \
62-
make
65+
$(MAKE)
6366

6467
prof:
6568
mkdir -p $(BUILDDIR); \
6669
cd $(BUILDDIR); \
6770
cmake .. -DCMAKE_BUILD_TYPE=Profile; \
68-
make
71+
$(MAKE)
6972

7073
afl:
7174
@[ -n "$(AFL_PATH)" ] || { echo '$$AFL_PATH not set'; false; }
7275
mkdir -p $(BUILDDIR)
73-
cd $(BUILDDIR) && cmake .. -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-gcc
74-
make
76+
cd $(BUILDDIR) && cmake .. -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang
77+
$(MAKE)
7578
$(AFL_PATH)/afl-fuzz \
7679
-i test/afl_test_cases \
7780
-o test/afl_results \
78-
-x test/afl_dictionary \
81+
-x test/fuzzing_dictionary \
7982
-t 100 \
8083
$(CMARK) $(CMARK_OPTS)
8184

85+
libFuzzer:
86+
@[ -n "$(LIB_FUZZER_PATH)" ] || { echo '$$LIB_FUZZER_PATH not set'; false; }
87+
mkdir -p $(BUILDDIR)
88+
cd $(BUILDDIR) && cmake -DCMAKE_BUILD_TYPE=Asan -DCMARK_LIB_FUZZER=ON -DCMAKE_LIB_FUZZER_PATH=$(LIB_FUZZER_PATH) ..
89+
$(MAKE) -j2 -C $(BUILDDIR) cmark-fuzz
90+
test/run-cmark-fuzz $(CMARK_FUZZ)
91+
8292
clang-check: all
8393
${CLANG_CHECK} -p build -analyze src/*.c
8494

8595
mingw:
8696
mkdir -p $(MINGW_BUILDDIR); \
8797
cd $(MINGW_BUILDDIR); \
8898
cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\
89-
make && make install
99+
$(MAKE) && $(MAKE) install
90100

91101
man/man3/cmark.3: src/cmark.h | $(CMARK)
92102
python man/make_man_page.py $< > $@ \
@@ -100,22 +110,21 @@ clean:
100110

101111
# We include case_fold_switch.inc in the repository, so this shouldn't
102112
# normally need to be generated.
103-
$(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
113+
$(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding.txt
104114
perl tools/mkcasefold.pl < $< > $@
105115

106116
# We include scanners.c in the repository, so this shouldn't
107117
# normally need to be generated.
108118
$(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
109119
@case "$$(re2c -v)" in \
110-
*\ 0.13.7*|*\ 0.14|*\ 0.14.1) \
111-
echo "re2c versions 0.13.7 through 0.14.1 are known to produce buggy code."; \
112-
echo "Try a version >= 0.14.2 or <= 0.13.6."; \
120+
*\ 0.13.*|*\ 0.14|*\ 0.14.1) \
121+
echo "re2c >= 0.14.2 is required"; \
113122
false; \
114123
;; \
115124
esac
116-
re2c --case-insensitive -b -i --no-generation-date -8 \
125+
re2c -W -Werror --case-insensitive -b -i --no-generation-date -8 \
117126
--encoding-policy substitute -o $@ $<
118-
clang-format -style llvm -i $@
127+
$(CLANG_FORMAT) $@
119128

120129
# We include entities.inc in the repository, so normally this
121130
# doesn't need to be regenerated:
@@ -127,23 +136,18 @@ update-spec:
127136
> $(SPEC)
128137

129138
test: $(SPEC) cmake_build
130-
make -C $(BUILDDIR) test || (cat $(BUILDDIR)/Testing/Temporary/LastTest.log && exit 1)
131-
132-
roundtrip_test: $(SPEC) cmake_build
133-
python3 test/spec_tests.py --spec $< --prog test/roundtrip.sh
139+
$(MAKE) -C $(BUILDDIR) test || (cat $(BUILDDIR)/Testing/Temporary/LastTest.log && exit 1)
134140

135141
$(ALLTESTS): $(SPEC)
136142
python3 test/spec_tests.py --spec $< --dump-tests | python3 -c 'import json; import sys; tests = json.loads(sys.stdin.read()); print("\n".join([test["markdown"] for test in tests]))' > $@
137143

138144
leakcheck: $(ALLTESTS)
139-
rc=0; \
140145
for format in html man xml latex commonmark; do \
141-
for opts in "" "--smart" "--normalize"; do \
146+
for opts in "" "--smart"; do \
142147
echo "cmark -t $$format $$opts" ; \
143-
cat $< | valgrind -q --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) -t $$format $$opts >/dev/null || rc=1; \
148+
valgrind -q --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) -t $$format $$opts $(ALLTESTS) >/dev/null || exit 1;\
144149
done; \
145-
done; \
146-
exit $$rc
150+
done;
147151

148152
fuzztest:
149153
{ for i in `seq 1 10`; do \
@@ -154,25 +158,39 @@ fuzztest:
154158
progit:
155159
git clone https://github.com/progit/progit.git
156160

157-
$(BENCHDIR)/benchinput.md: progit
161+
$(BENCHFILE): progit
158162
echo "" > $@
159163
for lang in ar az be ca cs de en eo es es-ni fa fi fr hi hu id it ja ko mk nl no-nb pl pt-br ro ru sr th tr uk vi zh zh-tw; do \
160-
cat progit/$$lang/*/*.markdown >> $@; \
164+
for i in `seq 1 10`; do \
165+
cat progit/$$lang/*/*.markdown >> $@; \
166+
done; \
161167
done
162168

169+
# for more accurate results, run with
170+
# sudo renice -10 $$; make bench
163171
bench: $(BENCHFILE)
164-
{ sudo renice -10 $$$$; \
165-
for x in `seq 1 $(NUMRUNS)` ; do \
166-
/usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
167-
/usr/bin/env time -p $(PROG) $< >/dev/null ; \
168-
done \
172+
{ for x in `seq 1 $(NUMRUNS)` ; do \
173+
/usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
174+
/usr/bin/env time -p $(PROG) $< >/dev/null ; \
175+
done \
169176
} 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
170177

178+
newbench:
179+
for f in $(BENCHSAMPLES) ; do \
180+
printf "%26s " `basename $$f` ; \
181+
{ for x in `seq 1 $(NUMRUNS)` ; do \
182+
/usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
183+
for x in `seq 1 200` ; do cat $$f ; done | \
184+
/usr/bin/env time -p $(PROG) > /dev/null; \
185+
done \
186+
} 2>&1 | grep 'real' | awk '{print $$2}' | \
187+
python3 'bench/stats.py'; done
188+
171189
format:
172-
clang-format -style llvm -i src/*.c src/*.h
190+
$(CLANG_FORMAT) src/*.c src/*.h api_test/*.c api_test/*.h
173191

174192
operf: $(CMARK)
175-
operf $< < $(BENCHINP) > /dev/null
193+
operf $< < $(BENCHFILE) > /dev/null
176194

177195
distclean: clean
178196
-rm -rf *.dSYM

0 commit comments

Comments
 (0)