Skip to content

[iwyu] Fixing inclusions for string_util.h pt.1 #29376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025

Conversation

cdesouza-chromium
Copy link
Collaborator

Files that use functions from string_util.h should include that header directly instead of relying on transient inclusions.

This is a mechanical change using this script:

remove_header_if_unused() {
    files=$(git grep -l "base/strings/string_util.h")
    for file in $files; do
        if ! git grep -qE "base::MakeStringPiece|base::MakeWStringView|base::ToLowerASCII|base::ToUpperASCII|base::CompareCaseInsensitiveASCII|base::EqualsCaseInsensitiveASCII|base::EmptyString|base::RemoveChars|base::ReplaceChars|base::TrimPositions|base::TrimString|base::TruncateUTF8ToByteSize|base::TrimWhitespace|base::CollapseWhitespace|base::ContainsOnlyChars|base::IsStringUTF8|base::IsStringASCII|base::EqualsASCII|base::CompareCase|base::StartsWith|base::EndsWith|base::RemovePrefix|base::RemoveSuffix|base::IsAscii|base::IsUnicodeControl|base::IsHexDigit|base::IsUnicodeWhitespace|base::FormatBytesUnlocalized|base::ReplaceFirstSubstringAfterOffset|base::ReplaceSubstringsAfterOffset|base::WriteInto|base::JoinString|base::ReplaceStringPlaceholders|base::MakeStringViewWithNulChars" "$file"; then
            sed -i '/base\/strings\/string_util.h/d' "$file"
            echo "Removed 'base/strings/string_util.h' from $file"
        fi
    done
}

add_header_if_needed() {
    files=$(git grep -lE "base::MakeStringPiece|base::MakeWStringView|base::ToLowerASCII|base::ToUpperASCII|base::CompareCaseInsensitiveASCII|base::EqualsCaseInsensitiveASCII|base::EmptyString|base::RemoveChars|base::ReplaceChars|base::TrimPositions|base::TrimString|base::TruncateUTF8ToByteSize|base::TrimWhitespace|base::CollapseWhitespace|base::ContainsOnlyChars|base::IsStringUTF8|base::IsStringASCII|base::EqualsASCII|base::CompareCase|base::StartsWith|base::EndsWith|base::RemovePrefix|base::RemoveSuffix|base::IsAscii|base::IsUnicodeControl|base::IsHexDigit|base::IsUnicodeWhitespace|base::FormatBytesUnlocalized|base::ReplaceFirstSubstringAfterOffset|base::ReplaceSubstringsAfterOffset|base::WriteInto|base::JoinString|base::ReplaceStringPlaceholders|base::MakeStringViewWithNulChars")
    for file in $files; do
        ../tools/add_header.py --header '"base/strings/string_util.h"' "$file"
    done
}

remove_header_if_unused
add_header_if_needed

Resolves brave/brave-browser#46559

@cdesouza-chromium cdesouza-chromium self-assigned this Jun 3, 2025
@cdesouza-chromium cdesouza-chromium requested review from a team, goodov and iefremov as code owners June 3, 2025 21:11
@github-actions github-actions bot added CI/run-network-audit Run network-audit CI/run-upstream-tests Run upstream unit and browser tests on Linux and Windows (otherwise only on Linux) feature/web3/wallet feature/web3/wallet/core labels Jun 3, 2025
Copy link
Contributor

github-actions bot commented Jun 3, 2025

[puLL-Merge] - brave/brave-core@29376

Description

This PR is performing a cleanup of unused #include "base/strings/string_util.h" statements across the Brave browser codebase. The change removes unnecessary includes of this header from files that don't actually use string utility functions, and adds the include to files that do use these functions but were missing the explicit include (likely depending on transitive includes). This is a code hygiene improvement that reduces compilation dependencies and makes explicit dependencies more clear.

Changes

Changes

The PR modifies 67 files across various components of the Brave browser:

Removed includes (files that don't use string_util functions):

  • browser/about_flags.cc
  • browser/ai_chat/ai_chat_brave_search_throttle_browsertest.cc
  • browser/brave_content_browser_client_browsertest.cc
  • browser/brave_vpn/dns/brave_vpn_dns_observer_service_win.cc
  • browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/status_icon/native_popup_menu.cc
  • browser/download/brave_download_item_model.cc
  • browser/ephemeral_storage/hsts_partitioning_browsertest.cc
  • browser/net/brave_proxying_web_socket.cc
  • browser/net/brave_static_redirect_network_delegate_helper_unittest.cc
  • browser/ntp_background/custom_background_file_manager.h
  • browser/ui/views/sidebar/sidebar_items_contents_view.cc
  • browser/ui/webui/ai_rewriter/ai_rewriter_ui.cc
  • browser/ui/webui/brave_new_tab_page_refresh/new_tab_page_handler.cc
  • browser/ui/webui/brave_wallet/wallet_panel_ui_browsertest.cc
  • browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.cc
  • Plus many more in chromium_src and other directories

Added includes (files that use string_util functions but were missing the include):

  • browser/brave_ads/creatives/search_result_ad/creative_search_result_ad_tab_helper.cc
  • browser/brave_ads/tabs/ads_tab_helper_browsertest.cc
  • browser/brave_rewards/test/util/rewards_browsertest_response.cc
  • browser/brave_shields/ad_block_custom_resources_browsertest.cc
  • browser/brave_stats/brave_stats_updater.cc
  • browser/brave_wallet/asset_discovery_task_unittest.cc
  • browser/brave_wallet/blockchain_images_source.cc
  • browser/brave_wallet/brave_wallet_provider_delegate_impl.cc
  • Plus many more across the codebase
sequenceDiagram
    participant Developer
    participant BuildSystem
    participant CompilerCache
    participant Dependencies
    
    Developer->>BuildSystem: Submit PR with include cleanup
    BuildSystem->>Dependencies: Analyze include dependencies
    Dependencies->>Dependencies: Remove unused string_util.h includes
    Dependencies->>Dependencies: Add missing string_util.h includes where needed
    Dependencies->>CompilerCache: Reduce unnecessary header dependencies
    CompilerCache->>BuildSystem: Faster compilation due to reduced includes
    BuildSystem->>Developer: Build completes successfully
Loading

Copy link
Member

@yrliou yrliou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wallet++

Files that use functions from `string_util.h` should include that header
directly instead of relying on transient inclusions.

This is a mechanical change using this script:

```sh
remove_header_if_unused() {
    files=$(git grep -l "base/strings/string_util.h")
    for file in $files; do
        if ! git grep -qE "base::MakeStringPiece|base::MakeWStringView|base::ToLowerASCII|base::ToUpperASCII|base::CompareCaseInsensitiveASCII|base::EqualsCaseInsensitiveASCII|base::EmptyString|base::RemoveChars|base::ReplaceChars|base::TrimPositions|base::TrimString|base::TruncateUTF8ToByteSize|base::TrimWhitespace|base::CollapseWhitespace|base::ContainsOnlyChars|base::IsStringUTF8|base::IsStringASCII|base::EqualsASCII|base::CompareCase|base::StartsWith|base::EndsWith|base::RemovePrefix|base::RemoveSuffix|base::IsAscii|base::IsUnicodeControl|base::IsHexDigit|base::IsUnicodeWhitespace|base::FormatBytesUnlocalized|base::ReplaceFirstSubstringAfterOffset|base::ReplaceSubstringsAfterOffset|base::WriteInto|base::JoinString|base::ReplaceStringPlaceholders|base::MakeStringViewWithNulChars" "$file"; then
            sed -i '/base\/strings\/string_util.h/d' "$file"
            echo "Removed 'base/strings/string_util.h' from $file"
        fi
    done
}

add_header_if_needed() {
    files=$(git grep -lE "base::MakeStringPiece|base::MakeWStringView|base::ToLowerASCII|base::ToUpperASCII|base::CompareCaseInsensitiveASCII|base::EqualsCaseInsensitiveASCII|base::EmptyString|base::RemoveChars|base::ReplaceChars|base::TrimPositions|base::TrimString|base::TruncateUTF8ToByteSize|base::TrimWhitespace|base::CollapseWhitespace|base::ContainsOnlyChars|base::IsStringUTF8|base::IsStringASCII|base::EqualsASCII|base::CompareCase|base::StartsWith|base::EndsWith|base::RemovePrefix|base::RemoveSuffix|base::IsAscii|base::IsUnicodeControl|base::IsHexDigit|base::IsUnicodeWhitespace|base::FormatBytesUnlocalized|base::ReplaceFirstSubstringAfterOffset|base::ReplaceSubstringsAfterOffset|base::WriteInto|base::JoinString|base::ReplaceStringPlaceholders|base::MakeStringViewWithNulChars")
    for file in $files; do
        ../tools/add_header.py --header '"base/strings/string_util.h"' "$file"
    done
}

remove_header_if_unused
add_header_if_needed

```

Resolves brave/brave-browser#46559
@cdesouza-chromium cdesouza-chromium force-pushed the iwyu+fix-string-utils-part1 branch from 3e1ff0e to e36a488 Compare June 3, 2025 21:47
@cdesouza-chromium cdesouza-chromium merged commit 8df5afa into master Jun 4, 2025
18 checks passed
@cdesouza-chromium cdesouza-chromium deleted the iwyu+fix-string-utils-part1 branch June 4, 2025 15:15
@github-actions github-actions bot added this to the 1.81.x - Nightly milestone Jun 4, 2025
@brave-builds
Copy link
Collaborator

Released in v1.81.47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/run-network-audit Run network-audit CI/run-upstream-tests Run upstream unit and browser tests on Linux and Windows (otherwise only on Linux) feature/web3/wallet/core feature/web3/wallet puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix IWYU for base/strings/string_util.h
9 participants