Skip to content
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

Suppress the error caused by Bazel when the headers(hdrs) become absolute path ("/**") #1095

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

phoepsilonix
Copy link
Contributor

When pkg-config's cflags only include -I/usr/include for a package, the reference to headers (hdrs) may become an absolute path ("/**"), causing Bazel to generate an error. It seems that _exec_pkg_config does not accept the --keep-system-cflags option.

Description

Currently, when attempting to build fcitx-mozc with Bazel, the output of pkg-config --cflags-only-I is empty. As a result, the hdrs reference becomes an absolute path (/**), causing Bazel to stop due to not finding @fcitx.
If we can avoid this error, the build will be possible. Other packages may not have issues at present, but if cflags only includes -I/usr/include, there is a high likelihood of encountering the same type of error.
This is a patch to suppress that.

Issue IDs

Steps to test new behaviors (if any)

Additional context

…lute paths("/**")

When pkg-config's cflags only include -I/usr/include for a package, the reference to headers (hdrs) may become an absolute path ("/**"), causing Bazel to generate an error.
It seems that _exec_pkg_config does not accept the --keep-system-cflags option.
@phoepsilonix phoepsilonix marked this pull request as ready for review October 26, 2024 09:06
@phoepsilonix
Copy link
Contributor Author

Related fcitx#68

@hiroyuki-komatsu
Copy link
Collaborator

The root cause sounds that _exec_pkg_config returns [''] when pkg-config --cflags-only-I returns an empty string. So how about updating _exec_pkg_config as follows instead of modifying _pkg_config_repository_impl?

def _exec_pkg_config(repo_ctx, flag):
    binary = repo_ctx.which("pkg-config")
    if not binary:
        # Using print is not recommended, but this will be a clue to debug build errors in
        # the case of pkg-config is not found.
        print("pkg-config is not found")  # buildifier: disable=print
        return []
    result = repo_ctx.execute([binary, flag] + repo_ctx.attr.packages)
    items = result.stdout.strip().split(" ")

+   # If items is empty, return an empty list.
+   if len(items) == 1 and items[0] == '':
+     return []

    uniq_items = sorted({key: None for key in items}.keys())
    return uniq_items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants