Test and tidy
Made the Python more Python-like. Added notes and general tidy. Tested exclusions and building with various options. Tested all scripts.
This commit is contained in:
@@ -69,7 +69,7 @@ fi
|
|||||||
echo "Single file library creation script: PASSED"
|
echo "Single file library creation script: PASSED"
|
||||||
|
|
||||||
# Copy the header to here (for the tests)
|
# Copy the header to here (for the tests)
|
||||||
cp "$ZSTD_SRC_ROOT/zstd.h" zstd.h
|
cp "$ZSTD_SRC_ROOT/zstd.h" examples/zstd.h
|
||||||
|
|
||||||
# Compile the generated output
|
# Compile the generated output
|
||||||
cc -Wall -Wextra -Werror -Wshadow -pthread -I. -Os -g0 -o $OUT_FILE zstd.c examples/roundtrip.c
|
cc -Wall -Wextra -Werror -Wshadow -pthread -I. -Os -g0 -o $OUT_FILE zstd.c examples/roundtrip.c
|
||||||
|
|||||||
@@ -2,6 +2,18 @@
|
|||||||
|
|
||||||
# Tool to bundle multiple C/C++ source files, inlining any includes.
|
# Tool to bundle multiple C/C++ source files, inlining any includes.
|
||||||
#
|
#
|
||||||
|
# Note: there are two types of exclusion options: the '-x' flag, which besides
|
||||||
|
# excluding a file also adds an #error directive in place of the #include, and
|
||||||
|
# the '-k' flag, which keeps the #include and doesn't inline the file. The
|
||||||
|
# intended use cases are: '-x' for files that would normally be #if'd out, so
|
||||||
|
# features that 100% won't be used in the amalgamated file, for which every
|
||||||
|
# occurrence adds the error, and '-k' for headers that we wish to manually
|
||||||
|
# include, such as a project's public API, for which occurrences after the first
|
||||||
|
# are removed.
|
||||||
|
#
|
||||||
|
# Todo: the error handling could be better, which currently throws and halts
|
||||||
|
# (which is functional just not very friendly).
|
||||||
|
#
|
||||||
# Author: Carl Woffenden, Numfum GmbH (this script is released under a CC0 license/Public Domain)
|
# Author: Carl Woffenden, Numfum GmbH (this script is released under a CC0 license/Public Domain)
|
||||||
|
|
||||||
import argparse, re, sys
|
import argparse, re, sys
|
||||||
@@ -116,7 +128,7 @@ def resolve_include(file: str, parent: Optional[Path] = None) -> Optional[Path]:
|
|||||||
# from the list of root paths or the owning file's 'parent', which in this case
|
# from the list of root paths or the owning file's 'parent', which in this case
|
||||||
# is case is the input file). The results are stored in 'resolved'.
|
# is case is the input file). The results are stored in 'resolved'.
|
||||||
#
|
#
|
||||||
def resolve_files(file_list: Optional[List[str]], resolved: Set[Path], parent: Optional[Path] = None) -> None:
|
def resolve_excluded_files(file_list: Optional[List[str]], resolved: Set[Path], parent: Optional[Path] = None) -> None:
|
||||||
if (file_list):
|
if (file_list):
|
||||||
for filename in file_list:
|
for filename in file_list:
|
||||||
found = resolve_include(filename, parent)
|
found = resolve_include(filename, parent)
|
||||||
@@ -138,9 +150,11 @@ def error_line(line: Any) -> None:
|
|||||||
|
|
||||||
# Inline the contents of 'file' (with any of its includes also inlined, etc.).
|
# Inline the contents of 'file' (with any of its includes also inlined, etc.).
|
||||||
#
|
#
|
||||||
def add_file(file: Path) -> None:
|
def add_file(file: Path, file_name: str = None) -> None:
|
||||||
if (file.is_file()):
|
if (file.is_file()):
|
||||||
error_line(f'Processing: {file}')
|
if (not file_name):
|
||||||
|
file_name = file.name
|
||||||
|
error_line(f'Processing: {file_name}')
|
||||||
with file.open('r') as opened:
|
with file.open('r') as opened:
|
||||||
for line in opened:
|
for line in opened:
|
||||||
line = line.rstrip('\n')
|
line = line.rstrip('\n')
|
||||||
@@ -151,7 +165,7 @@ def add_file(file: Path) -> None:
|
|||||||
resolved = resolve_include(inc_name, file.parent)
|
resolved = resolve_include(inc_name, file.parent)
|
||||||
if (resolved):
|
if (resolved):
|
||||||
if (resolved in excludes):
|
if (resolved in excludes):
|
||||||
# The file was excluded so error if the source attempts to use it
|
# The file was excluded so error if the compiler uses it
|
||||||
write_line(f'#error Using excluded file: {inc_name}')
|
write_line(f'#error Using excluded file: {inc_name}')
|
||||||
error_line(f'Excluding: {inc_name}')
|
error_line(f'Excluding: {inc_name}')
|
||||||
else:
|
else:
|
||||||
@@ -162,11 +176,11 @@ def add_file(file: Path) -> None:
|
|||||||
# But the include was flagged to keep as included
|
# But the include was flagged to keep as included
|
||||||
write_line(f'/**** *NOT* inlining {inc_name} ****/')
|
write_line(f'/**** *NOT* inlining {inc_name} ****/')
|
||||||
write_line(line)
|
write_line(line)
|
||||||
error_line('Not Inlining: {inc_name}')
|
error_line(f'Not inlining: {inc_name}')
|
||||||
else:
|
else:
|
||||||
# The file was neither excluded nor seen before so inline it
|
# The file was neither excluded nor seen before so inline it
|
||||||
write_line(f'/**** start inlining {inc_name} ****/')
|
write_line(f'/**** start inlining {inc_name} ****/')
|
||||||
add_file(resolved)
|
add_file(resolved, inc_name)
|
||||||
write_line(f'/**** ended inlining {inc_name} ****/')
|
write_line(f'/**** ended inlining {inc_name} ****/')
|
||||||
else:
|
else:
|
||||||
write_line(f'/**** skipping file: {inc_name} ****/')
|
write_line(f'/**** skipping file: {inc_name} ****/')
|
||||||
@@ -201,8 +215,8 @@ if (args.root):
|
|||||||
roots.add(path.resolve(strict=True))
|
roots.add(path.resolve(strict=True))
|
||||||
|
|
||||||
# The remaining params: so resolve the excluded files and #pragma once directive
|
# The remaining params: so resolve the excluded files and #pragma once directive
|
||||||
resolve_files(args.exclude, excludes, args.input.parent)
|
resolve_excluded_files(args.exclude, excludes, args.input.parent)
|
||||||
resolve_files(args.keep, keeps, args.input.parent)
|
resolve_excluded_files(args.keep, keeps, args.input.parent)
|
||||||
keep_pragma = args.pragma;
|
keep_pragma = args.pragma;
|
||||||
|
|
||||||
# Then recursively process the input file
|
# Then recursively process the input file
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ if [ -n "$1" ]; then
|
|||||||
printf "" > "$DESTN"
|
printf "" > "$DESTN"
|
||||||
fi
|
fi
|
||||||
test_deps
|
test_deps
|
||||||
|
log_line "Processing using the slower shell script; this might take a while"
|
||||||
add_file "$1"
|
add_file "$1"
|
||||||
else
|
else
|
||||||
echo "Input file not found: \"$1\""
|
echo "Input file not found: \"$1\""
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
ZSTD_SRC_ROOT="../../lib"
|
ZSTD_SRC_ROOT="../../lib"
|
||||||
|
|
||||||
# Amalgamate the sources
|
# Amalgamate the sources
|
||||||
echo "Amalgamating files... this can take a while"
|
echo "Amalgamating files..."
|
||||||
# Using the faster Python script if we have 3.8 or higher
|
# Using the faster Python script if we have 3.8 or higher
|
||||||
if python3 -c 'import sys; assert sys.version_info >= (3,8)' 2>/dev/null; then
|
if python3 -c 'import sys; assert sys.version_info >= (3,8)' 2>/dev/null; then
|
||||||
./combine.py -r "$ZSTD_SRC_ROOT" -o zstddeclib.c zstddeclib-in.c
|
./combine.py -r "$ZSTD_SRC_ROOT" -x legacy/zstd_legacy.h -o zstddeclib.c zstddeclib-in.c
|
||||||
else
|
else
|
||||||
./combine.sh -r "$ZSTD_SRC_ROOT" -o zstddeclib.c zstddeclib-in.c
|
./combine.sh -r "$ZSTD_SRC_ROOT" -x legacy/zstd_legacy.h -o zstddeclib.c zstddeclib-in.c
|
||||||
fi
|
fi
|
||||||
# Did combining work?
|
# Did combining work?
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
ZSTD_SRC_ROOT="../../lib"
|
ZSTD_SRC_ROOT="../../lib"
|
||||||
|
|
||||||
# Amalgamate the sources
|
# Amalgamate the sources
|
||||||
echo "Amalgamating files... this can take a while"
|
echo "Amalgamating files..."
|
||||||
# Using the faster Python script if we have 3.8 or higher
|
# Using the faster Python script if we have 3.8 or higher
|
||||||
if python3 -c 'import sys; assert sys.version_info >= (3,8)' 2>/dev/null; then
|
if python3 -c 'import sys; assert sys.version_info >= (3,8)' 2>/dev/null; then
|
||||||
./combine.py -r "$ZSTD_SRC_ROOT" -o zstd.c zstd-in.c
|
./combine.py -r "$ZSTD_SRC_ROOT" -x legacy/zstd_legacy.h -o zstd.c zstd-in.c
|
||||||
else
|
else
|
||||||
./combine.sh -r "$ZSTD_SRC_ROOT" -o zstd.c zstd-in.c
|
./combine.sh -r "$ZSTD_SRC_ROOT" -x legacy/zstd_legacy.h -o zstd.c zstd-in.c
|
||||||
fi
|
fi
|
||||||
# Did combining work?
|
# Did combining work?
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Generate using:
|
* Generate using:
|
||||||
* \code
|
* \code
|
||||||
* combine.sh -r ../../lib -o zstd.c zstd-in.c
|
* combine.sh -r ../../lib -x legacy/zstd_legacy.h -o zstd.c zstd-in.c
|
||||||
* \endcode
|
* \endcode
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Generate using:
|
* Generate using:
|
||||||
* \code
|
* \code
|
||||||
* combine.sh -r ../../lib -o zstddeclib.c zstddeclib-in.c
|
* combine.sh -r ../../lib -x legacy/zstd_legacy.h -o zstddeclib.c zstddeclib-in.c
|
||||||
* \endcode
|
* \endcode
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user