Preparing to run tests
Combine script more robust and can output to a specified file. Initial buck files added (work in progress).
This commit is contained in:
parent
36a59336da
commit
d760e35ebc
11
contrib/declib/BUCK
Normal file
11
contrib/declib/BUCK
Normal file
@ -0,0 +1,11 @@
|
||||
sh_test(
|
||||
name='combine',
|
||||
visibility=['PUBLIC'],
|
||||
test='combine.sh',
|
||||
args=[
|
||||
'-r', '../../lib',
|
||||
'-r', '../../lib/common',
|
||||
'-r', '../../lib/decompress',
|
||||
'-o', 'zstddeclib.c',
|
||||
'zstddeclib-in.c']
|
||||
)
|
@ -3,6 +3,6 @@
|
||||
Create the file using the shell script:
|
||||
```
|
||||
cd zstd/contrib/declib
|
||||
./combine.sh -r "../../lib ../../lib/common ../../lib/decompress" zstddeclib-in.c > zstddeclib.c
|
||||
./combine.sh -r ../../lib -r ../../lib/common -r ../../lib/decompress -o zstddeclib.c zstddeclib-in.c
|
||||
```
|
||||
Then add the resulting file to your project (see the [test sources](tests) for examples).
|
||||
|
@ -1,6 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Tool to bundle multiple C/C++ source files, inlining any includes.
|
||||
#
|
||||
# TODO: ROOTS and FOUND as arrays (since they fail on paths with spaces)
|
||||
|
||||
# Common file roots
|
||||
ROOTS="./"
|
||||
@ -8,11 +10,15 @@ ROOTS="./"
|
||||
# Files previously visited
|
||||
FOUND=""
|
||||
|
||||
# Optional destination file (empty string to write to stdout)
|
||||
DESTN=""
|
||||
|
||||
# Prints the script usage then exits
|
||||
function usage {
|
||||
echo "Usage: $0 [-r <paths>] infile"
|
||||
echo "Usage: $0 [-r <path>] [-o <outfile>] infile"
|
||||
echo " -r file root search paths"
|
||||
echo "Example: $0 -r \"../my/path ../my/other\" in.c > out.c"
|
||||
echo " -o output file (otherwise stdout)"
|
||||
echo "Example: $0 -r ../my/path - r ../other/path -o out.c in.c"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -26,6 +32,15 @@ function list_has_item {
|
||||
return 1
|
||||
}
|
||||
|
||||
# Adds a new line with the supplied arguments to $DESTN (or stdout)
|
||||
function write_line {
|
||||
if [ -n "$DESTN" ]; then
|
||||
printf "%s\n" "$@" >> "$DESTN"
|
||||
else
|
||||
printf "%s\n" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Adds the contents of $1 with any of its includes inlined
|
||||
function add_file {
|
||||
# Match the path
|
||||
@ -35,7 +50,7 @@ function add_file {
|
||||
file="$root/$1"
|
||||
fi
|
||||
done
|
||||
if [ "$file" != "" ]; then
|
||||
if [ -n "$file" ]; then
|
||||
# Read the file
|
||||
local line
|
||||
while IFS= read -r line; do
|
||||
@ -45,26 +60,29 @@ function add_file {
|
||||
if ! `list_has_item "$FOUND" "$inc"`; then
|
||||
# And we've not previously encountered it
|
||||
FOUND="$FOUND $inc"
|
||||
echo "/**** start inlining $inc ****/"
|
||||
write_line "/**** start inlining $inc ****/"
|
||||
add_file "$inc"
|
||||
echo "/**** ended inlining $inc ****/"
|
||||
write_line "/**** ended inlining $inc ****/"
|
||||
else
|
||||
echo "/**** skipping file: $inc ****/"
|
||||
write_line "/**** skipping file: $inc ****/"
|
||||
fi
|
||||
else
|
||||
# Otherwise write the source line
|
||||
echo "$line"
|
||||
write_line "$line"
|
||||
fi
|
||||
done < "$file"
|
||||
else
|
||||
echo "#error Unable to find \"$1\""
|
||||
write_line "#error Unable to find \"$1\""
|
||||
fi
|
||||
}
|
||||
|
||||
while getopts ":r:" opts; do
|
||||
while getopts ":r:o:" opts; do
|
||||
case $opts in
|
||||
r)
|
||||
ROOTS="$ROOTS $OPTARG"
|
||||
ROOTS="$OPTARG $ROOTS"
|
||||
;;
|
||||
o)
|
||||
DESTN="$OPTARG"
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
@ -73,8 +91,17 @@ while getopts ":r:" opts; do
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if [ "$1" != "" ]; then
|
||||
add_file $1
|
||||
if [ -n "$1" ]; then
|
||||
if [ -f "$1" ]; then
|
||||
if [ -n "$DESTN" ]; then
|
||||
printf "" > "$DESTN"
|
||||
fi
|
||||
add_file $1
|
||||
else
|
||||
echo "Input file not found: '$1'"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
usage
|
||||
fi
|
||||
exit 0
|
||||
|
5
contrib/declib/tests/BUCK
Normal file
5
contrib/declib/tests/BUCK
Normal file
@ -0,0 +1,5 @@
|
||||
cxx_test(
|
||||
name='simple',
|
||||
srcs=['simple.c'],
|
||||
deps=['//contrib/declib:combine']
|
||||
)
|
@ -3385,8 +3385,12 @@ size_t ZSTD_decompress(void* dst, size_t dstLen, const void* src, size_t srcLen)
|
||||
* the binary by 74kB.
|
||||
*/
|
||||
int main() {
|
||||
size_t bytes = ZSTD_decompress(dstDxt1, sizeof dstDxt1, srcZstd, sizeof srcZstd);
|
||||
printf("Decompressed size: %ld (expected %ld)\n", bytes, sizeof dstDxt1);
|
||||
printf("Byte comparison: %s\n", (memcmp(rawDxt1, dstDxt1, sizeof dstDxt1)) ? "failed" : "succeeded");
|
||||
return 0;
|
||||
size_t size = ZSTD_decompress(dstDxt1, sizeof dstDxt1, srcZstd, sizeof srcZstd);
|
||||
int compare = memcmp(rawDxt1, dstDxt1, sizeof dstDxt1);
|
||||
printf("Decompressed size: %ld (expected %ld)\n", size, sizeof dstDxt1);
|
||||
printf("Byte comparison: %s\n", (compare) ? "failed" : "succeeded");
|
||||
if (size == sizeof dstDxt1 && compare == 0) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* Generate using:
|
||||
* \code
|
||||
* combine.sh -r "../../lib ../../lib/common ../../lib/decompress" zstddeclib-in.c > zstddeclib.c
|
||||
* combine.sh -r ../../lib -r ../../lib/common -r ../../lib/decompress -o zstddeclib.c zstddeclib-in.c
|
||||
* \endcode
|
||||
*/
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user