Skip to content

[bug] Bazel for Clion failed to Sync Project with BUILD Files #8104

@Charlie17Li

Description

@Charlie17Li

Description of the bug:

Issue Description

When clicking the [Sync Project with BUILD Files] button in CLion, the synchronization fails with a Starlark evaluation error.

Updating VCS...
Running Bazel info...
Command: bazel info --tool_tag=ijwb:CLion --color=yes --progress_in_terminal_title=no bazel-bin bazel-genfiles bazel-testlogs execution_root package_path output_path output_base release starlark-semantics java-home --
Starting local Bazel server and connecting to it...

...

bazel build --tool_tag=ijwb:CLion --keep_going --norun_validations --color=yes --progress_in_terminal_title=no --aspects=//.clwb/aspects:intellij_info_bundled.bzl%intellij_info_aspect --output_groups=intellij-resolve-cpp,intellij-resolve-py,intellij-info-cpp,intellij-info-generic,intellij-info-py --build_event_binary_file=/var/folders/h6/19lnk30x0_9grp77c854fm1m0000gn/T/intellij-bep-1ffb92f8-14bd-4c3d-a1b5-01522760c282 --nobuild_event_binary_file_path_conversion --build_event_publish_all_actions --curses=yes -- //source/exe:envoy-static @com_github_gabime_spdlog//:spdlog
...
INFO: Elapsed time: 327.850s, Critical Path: 85.07s
INFO: 6157 processes: 4478 internal, 1677 darwin-sandbox, 1 local, 1 worker.
INFO: Build Event Protocol files produced successfully.
INFO: Build completed successfully, 6157 total actions

...

Command: /private/var/folders/h6/19lnk30x0_9grp77c854fm1m0000gn/T/xcode_cquery8.sh
Loading:
Loading: 0 packages loaded
Analyzing: target @bazel_tools//tools/osx:current_xcode_config (0 packages loaded, 0 targets configured)
INFO: Analyzed target @bazel_tools//tools/osx:current_xcode_config (0 packages loaded, 7 targets configured).
INFO: Found 1 target...
ERROR: Starlark evaluation error for @bazel_tools//tools/osx:current_xcode_config: Traceback (most recent call last):
        File ".clwb/aspects/xcode_query.bzl", line 15, column 16, in format
Error: type 'NoneType' is not iterable
ERROR: Starlark evaluation error for @bazel_tools//tools/osx:current_xcode_config: Traceback (most recent call last):
        File ".clwb/aspects/xcode_query.bzl", line 15, column 16, in format
Error: type 'NoneType' is not iterable

Root Cause Analysis

The logs show that bazel build completes successfully, but the subsequent xcode configuration query command fails:

# Command: /private/var/folders/h6/19lnk30x0_9grp77c854fm1m0000gn/T/xcode_cquery8.sh, the detail is below

#!/bin/bash
bazel cquery \
 'deps(@bazel_tools//tools/osx:current_xcode_config)' \
 --output=starlark \
 --starlark:file='.clwb/aspects/xcode_query.bzl'

Upon investigating .clwb/aspects/xcode_query.bzl, I discovered that the providers() function can return None in certain cases:

provider_attrs = ["xcode_version", "default_macos_sdk_version"]

def all_items_are_true(items):
    for item in items:
        if item == False:
            return False

    return True

def hasattrs(obj, attrs):
    return all_items_are_true([hasattr(obj, attr) for attr in attrs])

def format(target):
    all_providers = providers(target)  # Can return None for alias targets
    
    ###### debug
    print("target =", target)
    print("all_providers =", all_providers)
    ###### debug

    for key in all_providers:  # Error: NoneType is not iterable
        provider = all_providers[key]

        if hasattrs(provider, provider_attrs):
            attrs = [getattr(provider, attr) for attr in provider_attrs]
            return "{} {}".format(attrs[0], attrs[1])

    return ""

Findings

After adding debug logs, I found that providers() returns None when the target is an alias. This causes the iteration for key in all_providers to fail with the error: type 'NoneType' is not iterable.

Image

Proposed Solution

We should add a null check before iterating over the providers:

def format(target):
    all_providers = providers(target)
    
+    # Handle None case for alias targets
+   if all_providers is None:
+       return ""
    
    for key in all_providers:
        provider = all_providers[key]
        if hasattrs(provider, provider_attrs):
            attrs = [getattr(provider, attr) for attr in provider_attrs]
            return "{} {}".format(attrs[0], attrs[1])
    
    return ""

Which category does this issue belong to?

CLion

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

No response

Which Intellij IDE are you using? Please provide the specific version.

CLion 2025.3.1.1

What programming languages and tools are you using? Please provide specific versions.

c++ && bazel

What Bazel plugin version are you using?

6.0.0

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions