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:
|
Create the file using the shell script:
|
||||||
```
|
```
|
||||||
cd zstd/contrib/declib
|
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).
|
Then add the resulting file to your project (see the [test sources](tests) for examples).
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Tool to bundle multiple C/C++ source files, inlining any includes.
|
# 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
|
# Common file roots
|
||||||
ROOTS="./"
|
ROOTS="./"
|
||||||
@ -8,11 +10,15 @@ ROOTS="./"
|
|||||||
# Files previously visited
|
# Files previously visited
|
||||||
FOUND=""
|
FOUND=""
|
||||||
|
|
||||||
|
# Optional destination file (empty string to write to stdout)
|
||||||
|
DESTN=""
|
||||||
|
|
||||||
# Prints the script usage then exits
|
# Prints the script usage then exits
|
||||||
function usage {
|
function usage {
|
||||||
echo "Usage: $0 [-r <paths>] infile"
|
echo "Usage: $0 [-r <path>] [-o <outfile>] infile"
|
||||||
echo " -r file root search paths"
|
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
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +32,15 @@ function list_has_item {
|
|||||||
return 1
|
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
|
# Adds the contents of $1 with any of its includes inlined
|
||||||
function add_file {
|
function add_file {
|
||||||
# Match the path
|
# Match the path
|
||||||
@ -35,7 +50,7 @@ function add_file {
|
|||||||
file="$root/$1"
|
file="$root/$1"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ "$file" != "" ]; then
|
if [ -n "$file" ]; then
|
||||||
# Read the file
|
# Read the file
|
||||||
local line
|
local line
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
@ -45,26 +60,29 @@ function add_file {
|
|||||||
if ! `list_has_item "$FOUND" "$inc"`; then
|
if ! `list_has_item "$FOUND" "$inc"`; then
|
||||||
# And we've not previously encountered it
|
# And we've not previously encountered it
|
||||||
FOUND="$FOUND $inc"
|
FOUND="$FOUND $inc"
|
||||||
echo "/**** start inlining $inc ****/"
|
write_line "/**** start inlining $inc ****/"
|
||||||
add_file "$inc"
|
add_file "$inc"
|
||||||
echo "/**** ended inlining $inc ****/"
|
write_line "/**** ended inlining $inc ****/"
|
||||||
else
|
else
|
||||||
echo "/**** skipping file: $inc ****/"
|
write_line "/**** skipping file: $inc ****/"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Otherwise write the source line
|
# Otherwise write the source line
|
||||||
echo "$line"
|
write_line "$line"
|
||||||
fi
|
fi
|
||||||
done < "$file"
|
done < "$file"
|
||||||
else
|
else
|
||||||
echo "#error Unable to find \"$1\""
|
write_line "#error Unable to find \"$1\""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts ":r:" opts; do
|
while getopts ":r:o:" opts; do
|
||||||
case $opts in
|
case $opts in
|
||||||
r)
|
r)
|
||||||
ROOTS="$ROOTS $OPTARG"
|
ROOTS="$OPTARG $ROOTS"
|
||||||
|
;;
|
||||||
|
o)
|
||||||
|
DESTN="$OPTARG"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
usage
|
usage
|
||||||
@ -73,8 +91,17 @@ while getopts ":r:" opts; do
|
|||||||
done
|
done
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
if [ "$1" != "" ]; then
|
if [ -n "$1" ]; then
|
||||||
add_file $1
|
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
|
else
|
||||||
usage
|
usage
|
||||||
fi
|
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.
|
* the binary by 74kB.
|
||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
size_t bytes = ZSTD_decompress(dstDxt1, sizeof dstDxt1, srcZstd, sizeof srcZstd);
|
size_t size = ZSTD_decompress(dstDxt1, sizeof dstDxt1, srcZstd, sizeof srcZstd);
|
||||||
printf("Decompressed size: %ld (expected %ld)\n", bytes, sizeof dstDxt1);
|
int compare = memcmp(rawDxt1, dstDxt1, sizeof dstDxt1);
|
||||||
printf("Byte comparison: %s\n", (memcmp(rawDxt1, dstDxt1, sizeof dstDxt1)) ? "failed" : "succeeded");
|
printf("Decompressed size: %ld (expected %ld)\n", size, sizeof dstDxt1);
|
||||||
return 0;
|
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:
|
* Generate using:
|
||||||
* \code
|
* \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
|
* \endcode
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user