rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.66k stars 308 forks source link

Can it support self-defined build command? #494

Closed GreenSleeper closed 1 year ago

GreenSleeper commented 1 year ago

I want to use bear with self defined build command like m mm in android, but it doesn't seem to work.

function m()
(
    call_hook ${FUNCNAME[0]} $@
    if [ $? -ne 0 ]; then
        return 1
    fi
    _trigger_build "all-modules" "$@"
)
bear: Internal error.
Traceback (most recent call last):
  File "/usr/bin/bear", line 225, in wrapper
    return function(*args, **kwargs)
  File "/usr/bin/bear", line 250, in intercept_build
    exit_code, current = capture(args)
  File "/usr/bin/bear", line 274, in capture
    exit_code = run_build(args.build, env=environment)
  File "/usr/bin/bear", line 149, in run_build
    exit_code = subprocess.call(command, *args, **kwargs)
  File "/usr/lib/python3.6/subprocess.py", line 287, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'mm': 'mm'
bear: Please run this command again and turn on verbose mode (add '-vvvv' as argument).
jbmaillet commented 1 year ago

My 2 cents: I've been routinely using bear with full Android build for 3 years.

As you know, m mm croot etc are shell functions defined once you source buildenvsetup, intended for the developer to type less on the shell. It never came to my mind to use such commands in my builds / CI. I use plain make invocation, which is a file in the path (very different from GNU make of course) and bear works fine.

Of course, I understand that this is a severe case of "ask us what you need, I'll explain you how to do without it" pattern. ¯_(ツ)_/¯

GreenSleeper commented 1 year ago

I understand what you're saying, and I directly use make too. But sometimes we use build.sh to build. And if I use something like bear make surfaceflinger I get this error:

build/make/core/main.mk:2: Calling make directly is no longer supported.
build/make/core/main.mk:3: Either use 'envsetup.sh; m' or 'build/soong/soong_ui.bash --make-mode'
build/make/core/main.mk:4: *** done.  Stop.

Maybe I'll have to modify many mk files to make it work. Strangely enough though, if I directly use make surfaceflinger, it will build successfully.

rizsotto commented 1 year ago

@GreenAsFuck if you could provide some context on your environment, that could help to help you. The issue template has some questions, which are addressing the relevant aspects of the context.

https://github.com/rizsotto/Bear/blob/master/.github/ISSUE_TEMPLATE/bug_report.md

GreenSleeper commented 1 year ago

Sorry to bother, but I found a way to make soong generate json file now, don't need bear anymore. I'm closing this. FYI: Environment:

build command m mm are just typical android build command.

jbmaillet commented 1 year ago

Sorry to bother, but I found a way to make soong generate json file now, don't need bear anymore. I'm closing this.

Personally, I'd be interested if you could document that (maybe privately / by mail?) Android build is... er... let's say "big and special" for our "also special" usecases.

rizsotto commented 1 year ago

I am also happy to host that recipe on Bear's wiki. (Similar to Sarcasm's notebook)

GreenSleeper commented 1 year ago

https://android.googlesource.com/platform/build/soong/+/refs/heads/master/docs/compdb.md https://www.naseer.dev/post/compile-commands/ I followed these links and adapt it to my working environment, don't know if it will work for everone, but it works for me now.