Skip to content

Commit

Permalink
Add checking and verification support for includes using IWYU (#23092)
Browse files Browse the repository at this point in the history
* Add new script with feature for checking includes in project

* Add build and install IWYU 0.16 on chip-build Docker image and repair lost Tizen env

* Fix includes for ConnectivityManagerImpl.cpp in Tizen

* Fix includes in Tizen platform - First IWYU scan

* Fix includes in ThreadStackManager and BLEManager

* Fix include after commit:
Remove using-directives namespaces in Tizen platform

* Add some rules to IWYU mapping files and fix logging in iwyu_check.py script

* Fix version and restyled

* Compile ChipDeviceScanner only when BLE support is enabled

* Small improvements for Tizen SDK installation script

* Cleanup IWYU mapping files

* Purge clang-12 after compiling IWYU from source

* Show stderr output of include-what-you-use tool

Co-authored-by: Arkadiusz Bokowy <[email protected]>
  • Loading branch information
DamMicSzm and arkq authored Nov 29, 2022
1 parent 7999342 commit 6157859
Show file tree
Hide file tree
Showing 50 changed files with 653 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ function show_help() {
echo "Example: $SCRIPT_NAME --tizen-sdk-path ~/tizen-sdk --tizen-version 6.0 --install-dependencies"
echo
echo "Options:"
echo " --help Display this information"
echo " -h, --help Display this information"
echo " --tizen-sdk-path Set directory where Tizen will be installed. Default is $TIZEN_SDK_ROOT"
echo " --tizen-sdk-data-path Set directory where Tizen have data. Default is $TIZEN_SDK_DATA_PATH"
echo " --install-dependencies This options install all dependencies."
echo " --tizen-version Select Tizen version. Default is $TIZEN_VERSION"
echo " --override-secret-tool Without password manager circumvents the requirement of having functional D-Bus Secrets service"
echo " --override-secret-tool Circumvent the requirement of having functional D-Bus Secrets service."
echo
echo "Note:"
echo "The script should run fully with ubuntu. For other distributions you may have to manually"
echo "install all needed dependencies. Use the script specifying --tizen-sdk-path with or"
echo "without --tizen-version. The script will only install the tizen platform for Matter."
echo "without --tizen-version. The script will only install Tizen platform for Matter."
}

# ------------------------------------------------------------------------------
Expand All @@ -66,7 +66,7 @@ function error() {
# ------------------------------------------------------------------------------
# Info print function
function info() {
echo "$COLOR_GREEN$1$COLOR_NONE"
echo "$COLOR_GREEN[INFO]: $1$COLOR_NONE"
}

# ------------------------------------------------------------------------------
Expand All @@ -78,7 +78,7 @@ function warning() {
# ------------------------------------------------------------------------------
# Show dependencies
function show_dependencies() {
warning "Need dependencies for use this script installation SDK: cpio wget unzip unrpm"
warning "Need dependencies for use this script installation SDK: cpio unrpm unzip wget"
warning "Need dependencies for Tizen SDK: JAVA JRE >=8.0"
}

Expand Down Expand Up @@ -135,10 +135,11 @@ function install_tizen_sdk() {

TIZEN_SDK_SYSROOT="$TIZEN_SDK_ROOT/platforms/tizen-$TIZEN_VERSION/mobile/rootstraps/mobile-$TIZEN_VERSION-device.core"

# Get tizen studio CLI
info "Get tizen studio CLI [...]"
cd "$TMP_DIR" || return

# Get Tizen Studio CLI
info "Downloading Tizen Studio CLI..."

# Download
URL="http://download.tizen.org/sdk/tizenstudio/official/binary/"
PKG_ARR=(
Expand All @@ -150,7 +151,7 @@ function install_tizen_sdk() {
download "$URL" "${PKG_ARR[@]}"

# Get toolchain
info "Get toolchain"
info "Downloading Tizen toolchain..."

# Download
URL="http://download.tizen.org/sdk/tizenstudio/official/binary/"
Expand All @@ -159,11 +160,11 @@ function install_tizen_sdk() {
"sbi-toolchain-gcc-9.2.cpp.app_2.2.16_ubuntu-64.zip")
download "$URL" "${PKG_ARR[@]}"

# Get tizen sysroot
info "Get tizen sysroot"
# Get Tizen sysroot
info "Downloading Tizen sysroot..."

# Base sysroot
# Different versions of tizen have different rootstrap versions
# Different versions of Tizen have different rootstrap versions
URL="http://download.tizen.org/sdk/tizenstudio/official/binary/"
PKG_ARR=(
"mobile-$TIZEN_VERSION-core-add-ons_*_ubuntu-64.zip"
Expand Down Expand Up @@ -224,7 +225,7 @@ function install_tizen_sdk() {
download "$URL" "${PKG_ARR[@]}"

# Install all
info "Installation Tizen SDK [...]"
info "Installing Tizen SDK..."

unzip -o '*.zip'
cp -rf data/* "$TIZEN_SDK_ROOT"
Expand All @@ -234,12 +235,12 @@ function install_tizen_sdk() {

# Install secret tool or not
if ("$SECRET_TOOL"); then
info "Override secret tool"
info "Overriding secret tool..."
cp "$SCRIPT_DIR/secret-tool.py" "$TIZEN_SDK_ROOT/tools/certificate-encryptor/secret-tool"
chmod 0755 "$TIZEN_SDK_ROOT/tools/certificate-encryptor/secret-tool"
fi

# Configure tizen cli
# Configure Tizen CLI
echo "TIZEN_SDK_INSTALLED_PATH=$TIZEN_SDK_ROOT" >"$TIZEN_SDK_ROOT/sdk.info"
echo "TIZEN_SDK_DATA_PATH=$TIZEN_SDK_DATA_PATH" >>"$TIZEN_SDK_ROOT/sdk.info"
ln -sf "$TIZEN_SDK_DATA_PATH/.tizen-cli-config" "$TIZEN_SDK_ROOT/tools/.tizen-cli-config"
Expand All @@ -251,9 +252,12 @@ function install_tizen_sdk() {
ln -sf ../../lib/libcap.so.2 "$TIZEN_SDK_SYSROOT/usr/lib/libcap.so"
ln -sf openssl1.1.pc "$TIZEN_SDK_SYSROOT/usr/lib/pkgconfig/openssl.pc"

info "Done."
echo

# Information on necessary environment variables
warning "You must add the appropriate environment variables before proceeding with matter."
echo "$COLOR_YELLOW"
warning "Before proceeding with Matter export environment variables as follows:"
echo -n "$COLOR_YELLOW"
echo "export TIZEN_VESRSION=\"$TIZEN_VERSION\""
echo "export TIZEN_SDK_ROOT=\"$(realpath "$TIZEN_SDK_ROOT")\""
echo "export TIZEN_SDK_TOOLCHAIN=\"\$TIZEN_SDK_ROOT/tools/arm-linux-gnueabi-gcc-9.2\""
Expand All @@ -264,7 +268,7 @@ function install_tizen_sdk() {

while (($#)); do
case $1 in
--help)
-h | --help)
show_help
exit 0
;;
Expand Down Expand Up @@ -308,20 +312,19 @@ if [ "$INSTALL_DEPENDENCIES" = true ]; then
show_dependencies
exit 1
fi
else
show_dependencies
fi

# ------------------------------------------------------------------------------
# Checking dependencies needed to install the tizen platform
for PKG in 'cpio' 'unzip' 'wget' 'unrpm'; do
# Checking dependencies needed to install Tizen platform
info "Checking required tools: cpio, java, unrpm, unzip, wget"
for PKG in 'cpio' 'java' 'unrpm' 'unzip' 'wget'; do
if ! command -v "$PKG" &>/dev/null; then
warning "Not found $PKG"
error "Required tool not found: $PKG"
dep_lost=1
fi
done
if [[ $dep_lost ]]; then
error "You need install dependencies before [HINT]: On Ubuntu-like distro run: sudo apt install ${DEPENDENCIES[@]}"
echo "[HINT]: sudo apt-get install ${DEPENDENCIES[*]}"
exit 1
fi

Expand Down
1 change: 1 addition & 0 deletions integrations/docker/images/chip-build-vscode/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ ENV ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb

ENV TIZEN_VERSION 6.0
ENV TIZEN_SDK_ROOT /opt/tizen-sdk
ENV TIZEN_SDK_TOOLCHAIN $TIZEN_SDK_ROOT/tools/arm-linux-gnueabi-gcc-9.2
ENV TIZEN_SDK_SYSROOT $TIZEN_SDK_ROOT/platforms/tizen-$TIZEN_VERSION/mobile/rootstraps/mobile-$TIZEN_VERSION-device.core

ENV FVP_CORSTONE_300_PATH=/opt/FVP_Corstone_SSE-300
Expand Down
25 changes: 25 additions & 0 deletions integrations/docker/images/chip-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ RUN set -x \
ninja-build \
openjdk-8-jdk \
pkg-config \
python-is-python3 \
python3.9 \
python3.9-dev \
python3.9-venv \
Expand Down Expand Up @@ -120,6 +121,30 @@ RUN set -x \
&& rm -rf bloaty \
&& : # last line

# Need newer version of include-what-you-use
RUN set -x \
&& apt-get update \
# Install build and runtime requirements for IWYU
&& DEBIAN_FRONTEND=noninteractive apt-get install -fy --fix-missing clang-12 libclang-12-dev \
# Build and install IWYU
&& git clone --depth=1 --branch=clang_12 https://github.com/include-what-you-use/include-what-you-use.git \
&& mkdir -p include-what-you-use/build \
&& cd include-what-you-use/build \
&& cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_PREFIX_PATH=/usr/lib/llvm-12 -DIWYU_LINK_CLANG_DYLIB=OFF .. \
&& make -j8 \
&& make install \
# Save clang-12 files, so we can restore them after build dependencies cleanup
&& tar -cf clang-12-files.tar $(dpkg -L libclang-common-12-dev |grep /include) /usr/lib/llvm-12/lib/libLLVM-12.so.1 \
# Cleanup build dependencies
&& apt autoremove -fy clang-12 libclang-12-dev \
&& rm -rf /var/lib/apt/lists/ \
# Restore clang-12 files
&& tar -xf clang-12-files.tar -C / \
# Cleanup
&& cd ../.. \
&& rm -rf include-what-you-use \
&& : # last line

# Build glib-2.0 from source with enabled thread sanitizer. This is needed for
# running CHIP tests with TSAN enabled. When running applications with TSAN
# all shared libraries should be built with TSAN enabled, otherwise TSAN might
Expand Down
2 changes: 1 addition & 1 deletion integrations/docker/images/chip-build/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.13 Version bump reason: Update zap to latest release
0.6.14 Version bump reason: Add checking and verification support for includes using IWYU
Loading

0 comments on commit 6157859

Please sign in to comment.