Skip to content

Commit

Permalink
[R-package] Suppresses unknown pragma warnings during CRAN build (#3460)
Browse files Browse the repository at this point in the history
* Modified script to also remove pragma warnings.

This also includes modifying the scope of the pragma removal.
Previously this script only searched inside the ./src/include/LightGMB directory.
This was not inclusive enough to remove the warnings in files shown in the ticket.

* Adds CI test that exits if unknown pragma warnings are present.

* Expanding pragma removal to cpp and hpp files.

* Update .ci/test_r_package.sh

Removing unneeded conditions since this script will only run on Linux and Mac builds anyway.

Co-authored-by: James Lamb <jaylamb20@gmail.com>

* Update .ci/test_r_package.sh

Fixes typo

Co-authored-by: James Lamb <jaylamb20@gmail.com>

* replacing double quotes with single quotes

* Using a more portable find syntax so it works on macOS and Linux

Co-authored-by: James Lamb <jaylamb20@gmail.com>
  • Loading branch information
cctechwiz and jameslamb committed Oct 16, 2020
1 parent 0c1c36c commit 2e1b39b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 14 additions & 0 deletions .ci/test_r_package.sh
Expand Up @@ -216,3 +216,17 @@ if [[ $OS_NAME == "macos" ]] && [[ $R_BUILD_TYPE == "cran" ]]; then
exit -1
fi
fi

# this check makes sure that no "warning: unknown pragma ignored" logs
# reach the user leading them to believe that something went wrong
if [[ $R_BUILD_TYPE == "cran" ]]; then
pragma_warning_present=$(
cat $BUILD_LOG_FILE \
| grep -E "warning: unknown pragma ignored" \
| wc -l
)
if [[ $pragma_warning_present -ne 0 ]]; then
echo "Unknown pragma warning is present, pragmas should have been removed before build"
exit -1
fi
fi
11 changes: 6 additions & 5 deletions build-cran-package.sh
Expand Up @@ -50,19 +50,20 @@ cd ${TEMP_R_DIR}
sed -i.bak -e "s/~~VERSION~~/${LGB_VERSION}/" DESCRIPTION
sed -i.bak -e "s/~~DATE~~/${CURRENT_DATE}/" DESCRIPTION

# Remove 'region' and 'endregion' pragmas. This won't change
# the correctness of the code. CRAN does not allow you
# to use compiler flag '-Wno-unknown-pragmas' or
# Remove 'region', 'endregion', and 'warning' pragmas.
# This won't change the correctness of the code. CRAN does
# not allow you to use compiler flag '-Wno-unknown-pragmas' or
# pragmas that suppress warnings.
echo "Removing unknown pragmas in headers"
for file in src/include/LightGBM/*.h; do
for file in $(find . -name '*.h' -o -name '*.hpp' -o -name '*.cpp'); do
sed \
-i.bak \
-e 's/^.*#pragma region.*$//' \
-e 's/^.*#pragma endregion.*$//' \
-e 's/^.*#pragma warning.*$//' \
"${file}"
done
rm src/include/LightGBM/*.h.bak
find . -name '*.h.bak' -o -name '*.hpp.bak' -o -name '*.cpp.bak' -exec rm {} \;

# When building an R package with 'configure', it seems
# you're guaranteed to get a shared library called
Expand Down

0 comments on commit 2e1b39b

Please sign in to comment.