rizsotto / Bear

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

Bear does not catch cross compiler #460

Closed hanyazou closed 2 years ago

hanyazou commented 2 years ago

Expected behavior

I expect it to catch the arm-none-eabi-gcc command, but it doesn't seem to be.

Environment:

OS name: macOS OS version: 11.5.2 OS architecture: x86_64 Bear version: bear 3.0.19 Bear install method: brew install bear

Additional context

Could you tell me how to handle a cross compiler with the intercept? The output file compile_commands.events.json was empty if I run the bear with a cross compiler arm-none-eabi-gcc. I read #279 and tried the --use-cc command line options. But the output was "Unrecognized parameter". The configuration file which is explained in the man page of citnames does not seem help because the bear will spawn the intercept without the --config option.

The only way in which the bear could handle cross compiler was that I made a symbolic link in the wrapper.d directory to tell the bear the cross compiler should be hooked. But I feel this was not a proper way to do that.

kay-22 commented 2 years ago

I am having the same issue. --use-cc is also unrecognized.

I am trying to compile with a different CC, and getting an empty comile_commands.json.

I have a simple makefile

CC = /usr/local/opt/llvm/bin/clang

buggy: zero.c buggy.c
    $(CC) -o buggy $^

and the following config file

{
    "compilation": {
        "compilers_to_recognize": [
            {
                "executable": "/usr/local/opt/llvm/bin/clang",
                "flags_to_add": [],
                "flags_to_remove": []
            }
        ],
        "compilers_to_exclude": []
    },
    "output": {
        "content": {
            "include_only_existing_source": true,
            "paths_to_include": [],
            "paths_to_exclude": []
        },
        "format": {
            "command_as_array": true,
            "drop_output_field": false
        }
    }
}

running bear --verbose --config config.json -- make gives

[11:28:29.534566, br, 84888] bear: 3.0.19
[11:28:29.535161, br, 84888] arguments: ["bear", "--verbose", "--config", "config.json", "--", "make"]
[11:28:29.535188, br, 84888] environment: [< intentionally removed >]
[11:28:29.535327, br, 84888] sysname: Darwin
[11:28:29.535330, br, 84888] release: 20.6.0
[11:28:29.535332, br, 84888] version: Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:42 PST 2022; root:xnu-7195.141.19~2/RELEASE_X86_64
[11:28:29.535334, br, 84888] machine: x86_64
[11:28:29.535362, br, 84888] arguments parsed: {program: bear, arguments: [{--: [make]}, {--citnames: [/usr/local/Cellar/bear/3.0.19_1/bin/citnames]}, {--config: [config.json]}, {--interceptor: [/usr/local/Cellar/bear/3.0.19_1/bin/intercept]}, {--library: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/libexec.dylib]}, {--output: [compile_commands.json]}, {--verbose: []}, {--wrapper: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper]}, {--wrapper-dir: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d]}]}
[11:28:29.536784, br, 84888] Process spawned. [pid: 84889, command: [/usr/local/Cellar/bear/3.0.19_1/bin/intercept, --library, /usr/local/Cellar/bear/3.0.19_1/lib/bear/libexec.dylib, --wrapper, /usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper, --wrapper-dir, /usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d, --output, compile_commands.events.json, --verbose, --, make]]
[11:28:29.536819, br, 84888] Process wait requested. [pid: 84889]
[11:28:29.558885, ic, 84889] intercept: 3.0.19
[11:28:29.559118, ic, 84889] arguments: ["/usr/local/Cellar/bear/3.0.19_1/bin/intercept", "--library", "/usr/local/Cellar/bear/3.0.19_1/lib/bear/libexec.dylib", "--wrapper", "/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper", "--wrapper-dir", "/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d", "--output", "compile_commands.events.json", "--verbose", "--", "make"]
[11:28:29.559137, ic, 84889] environment: [< intentionally removed >]
[11:28:29.559267, ic, 84889] sysname: Darwin
[11:28:29.559271, ic, 84889] release: 20.6.0
[11:28:29.559273, ic, 84889] version: Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:42 PST 2022; root:xnu-7195.141.19~2/RELEASE_X86_64
[11:28:29.559274, ic, 84889] machine: x86_64
[11:28:29.559286, ic, 84889] arguments parsed: {program: /usr/local/Cellar/bear/3.0.19_1/bin/intercept, arguments: [{--: [make]}, {--library: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/libexec.dylib]}, {--output: [compile_commands.events.json]}, {--verbose: []}, {--wrapper: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper]}, {--wrapper-dir: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d]}]}
[11:28:29.560806, ic, 84889] session initialized with: wrapper_dir: /usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d
[11:28:29.560817, ic, 84889] session initialized with: mapping: [{ "ar": "/usr/bin/ar" }, { "as": "/usr/bin/as" }, { "bison": "/usr/bin/bison" }, { "c++": "/usr/bin/c++" }, { "cc": "/usr/bin/cc" }, { "clang": "/usr/local/opt/llvm/bin/clang" }, { "clang++": "/usr/local/opt/llvm/bin/clang++" }, { "cpp": "/usr/bin/cpp" }, { "flex": "/usr/bin/flex" }, { "g++": "/usr/bin/g++" }, { "gcc": "/usr/bin/gcc" }, { "ld": "/usr/bin/ld" }, { "lex": "/usr/bin/lex" }, { "makeinfo": "/usr/bin/makeinfo" }, { "nm": "/usr/bin/nm" }, { "objdump": "/usr/bin/objdump" }, { "ranlib": "/usr/bin/ranlib" }, { "strip": "/usr/bin/strip" }, { "yacc": "/usr/bin/yacc" }]
[11:28:29.560825, ic, 84889] session initialized with: override: []
[11:28:29.568538, ic, 84889] Running gRPC server. dns:///localhost:54384
[11:28:29.568851, ic, 84889] Process spawned. [pid: 84890, command: [make]]
[11:28:29.568879, ic, 84889] Process wait requested. [pid: 84890]
/usr/local/opt/llvm/bin/clang  -o buggy zero.c buggy.c
[11:28:29.672667, wr, 84894, ppid: 84891] wrapper: 3.0.19
[11:28:29.673072, wr, 84894, ppid: 84891] arguments: ["/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d/ld", "-demangle", "-lto_library", "/usr/local/Cellar/llvm/13.0.1_1/lib/libLTO.dylib", "-no_deduplicate", "-dynamic", "-arch", "x86_64", "-platform_version", "macos", "11.0.0", "11.0.0", "-syslibroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk", "-o", "buggy", "/var/folders/07/d9r8gjmj1_z7bff9bx_6lp2w0000gp/T/zero-632d32.o", "/var/folders/07/d9r8gjmj1_z7bff9bx_6lp2w0000gp/T/buggy-cdba0e.o", "-lSystem", "/usr/local/Cellar/llvm/13.0.1_1/lib/clang/13.0.1/lib/darwin/libclang_rt.osx.a"]
[11:28:29.673096, wr, 84894, ppid: 84891] environment: [< intentionally removed >]
[11:28:29.673921, wr, 84894, ppid: 84891] gRPC call requested: supervise::Supervisor::Resolve
[11:28:29.675814, ic, 84889] trying to resolve for wrapper: /usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d/ld
[11:28:29.676136, wr, 84894, ppid: 84891] gRPC call [Resolve] finished: true
[11:28:29.676438, wr, 84894, ppid: 84891] Process spawned. [pid: 84895, command: [/usr/bin/ld, -demangle, -lto_library, /usr/local/Cellar/llvm/13.0.1_1/lib/libLTO.dylib, -no_deduplicate, -dynamic, -arch, x86_64, -platform_version, macos, 11.0.0, 11.0.0, -syslibroot, /Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk, -o, buggy, /var/folders/07/d9r8gjmj1_z7bff9bx_6lp2w0000gp/T/zero-632d32.o, /var/folders/07/d9r8gjmj1_z7bff9bx_6lp2w0000gp/T/buggy-cdba0e.o, -lSystem, /usr/local/Cellar/llvm/13.0.1_1/lib/clang/13.0.1/lib/darwin/libclang_rt.osx.a]]
[11:28:29.676481, wr, 84894, ppid: 84891] gRPC call requested: supervise::Interceptor::Register
[11:28:29.678068, wr, 84894, ppid: 84891] gRPC call [Register] finished: true
[11:28:29.678130, wr, 84894, ppid: 84891] Process wait requested. [pid: 84895]
[11:28:29.711293, wr, 84894, ppid: 84891] Process wait request: done. [pid: 84895]
[11:28:29.711323, wr, 84894, ppid: 84891] gRPC call requested: supervise::Interceptor::Register
[11:28:29.711633, wr, 84894, ppid: 84891] gRPC call [Register] finished: true
[11:28:29.711903, wr, 84894, ppid: 84891] succeeded with: 0
[11:28:29.714212, ic, 84889] Process wait request: done. [pid: 84890]
[11:28:29.714232, ic, 84889] Running command. [Exited with 0]
[11:28:29.714241, ic, 84889] Stopping gRPC server.
[11:28:29.714581, ic, 84889] succeeded with: 0
[11:28:29.715503, br, 84888] Process wait request: done. [pid: 84889]
[11:28:29.715577, br, 84888] Running intercept finished. [Exited with 0]
[11:28:29.716339, br, 84888] Process spawned. [pid: 84896, command: [/usr/local/Cellar/bear/3.0.19_1/bin/citnames, --input, compile_commands.events.json, --output, compile_commands.json, --run-checks, --config, config.json, --verbose]]
[11:28:29.716361, br, 84888] Process wait requested. [pid: 84896]
[11:28:29.734782, cs, 84896] citnames: 3.0.19
[11:28:29.735016, cs, 84896] arguments: ["/usr/local/Cellar/bear/3.0.19_1/bin/citnames", "--input", "compile_commands.events.json", "--output", "compile_commands.json", "--run-checks", "--config", "config.json", "--verbose"]
[11:28:29.735035, cs, 84896] environment: [< intentionally removed >]
[11:28:29.735148, cs, 84896] sysname: Darwin
[11:28:29.735151, cs, 84896] release: 20.6.0
[11:28:29.735152, cs, 84896] version: Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:42 PST 2022; root:xnu-7195.141.19~2/RELEASE_X86_64
[11:28:29.735153, cs, 84896] machine: x86_64
[11:28:29.735163, cs, 84896] arguments parsed: {program: /usr/local/Cellar/bear/3.0.19_1/bin/citnames, arguments: [{--config: [config.json]}, {--input: [compile_commands.events.json]}, {--output: [compile_commands.json]}, {--run-checks: []}, {--verbose: []}]}
[11:28:29.735368, cs, 84896] Configuration: {"compilation":{"compilers_to_recognize":[{"executable":"/usr/local/opt/llvm/bin/clang"}]},"output":{"content":{"include_only_existing_source":true},"format":{"command_as_array":true,"drop_output_field":false}}}
[11:28:29.736497, cs, 84896] [pid: 84895] execution: {"executable":"/usr/bin/ld","arguments":["/usr/bin/ld","-demangle","-lto_library","/usr/local/Cellar/llvm/13.0.1_1/lib/libLTO.dylib","-no_deduplicate","-dynamic","-arch","x86_64","-platform_version","macos","11.0.0","11.0.0","-syslibroot","/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk","-o","buggy","/var/folders/07/d9r8gjmj1_z7bff9bx_6lp2w0000gp/T/zero-632d32.o","/var/folders/07/d9r8gjmj1_z7bff9bx_6lp2w0000gp/T/buggy-cdba0e.o","-lSystem","/usr/local/Cellar/llvm/13.0.1_1/lib/clang/13.0.1/lib/darwin/libclang_rt.osx.a"],"workingDir":"< intentionally removed >","environment":{< intentionally removed >}}
[11:28:29.736723, cs, 84896] [pid: 84895] recognition failed: No tools recognize this execution.
[11:28:29.736817, cs, 84896] compilation entries created. [size: 0]
[11:28:29.736822, cs, 84896] compilation entries to output. [size: 0]
[11:28:29.736995, cs, 84896] compilation entries written. [size: 0]
[11:28:29.737008, cs, 84896] succeeded with: 0
[11:28:29.737657, br, 84888] Process wait request: done. [pid: 84896]
[11:28:29.737679, br, 84888] Running citnames finished. [Exited with 0]
[11:28:29.737771, br, 84888] succeeded with: 0

Note: I removed environment from the log. If it helps I can see how to specify it better other than completely removing it.

running only intercept -- make gives the following events.json

{
    "rid":"3804693015727755300",
    "started":{
        "execution":{
            "executable":"/usr/bin/ld",
            "arguments":[
                "/usr/bin/ld",
                "-demangle",
                "-lto_library",
                "/usr/local/Cellar/llvm/13.0.1_1/lib/libLTO.dylib",
                "-no_deduplicate",
                "-dynamic",
                "-arch",
                "x86_64",
                "-platform_version",
                "macos",
                "11.0.0",
                "11.0.0",
                "-syslibroot",
                "/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk",
                "-o",
                "buggy",
                "/var/folders/07/d9r8gjmj1_z7bff9bx_6lp2w0000gp/T/zero-5ba14d.o",
                "/var/folders/07/d9r8gjmj1_z7bff9bx_6lp2w0000gp/T/buggy-080a77.o",
                "-lSystem","/usr/local/Cellar/llvm/13.0.1_1/lib/clang/13.0.1/lib/darwin/libclang_rt.osx.a"
            ],
            "working_dir":"< intentionally removed >",
            "environment":{"< intentionally removed >"}
        },
        "pid":85148,
        "ppid":85144
    },
    "timestamp":"2022-05-04T08:58:53.140421Z"
}
{
    "rid":"3804693015727755300",
    "terminated":{"status":"0"},
    "timestamp":"2022-05-04T08:58:53.183272Z"
}

Running with the default CC works perfectly fine.

rizsotto commented 2 years ago

@hanyazou the flags you try to use are for the 2.3.x and 2.4.x versions. (As the #279 ticket was raised against those versions.) The solution for the latest 3.x version is what @kay-22 is doing: create a config file and name the compiler you would like to catch.

@kay-22 for you the solution is to not define the CC inside the makefile, but pass it as environment variable. Something like this:

CC=/usr/local/opt/llvm/bin/clang bear --config config.json -- make

while your makefile is only this:

buggy: zero.c buggy.c
    $(CC) -o buggy $^
hanyazou commented 2 years ago

@rizsotto Thank you for your comment.

The solution for the latest 3.x version is what @kay-22 is doing: create a config file and name the compiler you would like to catch.

I've tried bear with some config file. The output was empty. The intercept which spawned did not seem to catch the compiler. What was wrong with my configuration?

Makefile:

hello.o: hello.c
        /usr/local/bin/arm-none-eabi-gcc -c hello.c

config.json:

{
        "compilation": {
        "compilers_to_recognize": [
            {
                            "executable": "/usr/local/bin/arm-none-eabi-gcc",
                "flags_to_add": [],
                "flags_to_remove": []
            }
        ],
                "compilers_to_exclude": []
    },
        "output": {
                "content": {
                        "include_only_existing_source": true,
            "paths_to_include": [],
            "paths_to_exclude": []
        },
                "format": {
                        "command_as_array": true,
            "drop_output_field": false
        }
    }
}

how to run:

% export CC=/usr/local/bin/arm-none-eabi-gcc
% bear --verbose --config config.json -- make
[16:12:42.014662, br, 33193] bear: 3.0.19
[16:12:42.015045, br, 33193] arguments: ["bear", "--verbose", "--config", "config.json", "--", "make"]
[16:12:42.015057, br, 33193] environment: [ ... ]
[16:12:42.043464, br, 33193] sysname: Darwin
[16:12:42.043469, br, 33193] release: 20.6.0
[16:12:42.043470, br, 33193] version: Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
[16:12:42.043471, br, 33193] machine: x86_64
[16:12:42.043486, br, 33193] arguments parsed: {program: bear, arguments: [{--: [make]}, {--citnames: [/usr/local/Cellar/bear/3.0.19_1/bin/citnames]}, {--config: [config.json]}, {--interceptor: [/usr/local/Cellar/bear/3.0.19_1/bin/intercept]}, {--library: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/libexec.dylib]}, {--output: [compile_commands.json]}, {--verbose: []}, {--wrapper: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper]}, {--wrapper-dir: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d]}]}
[16:12:42.081434, br, 33193] Process spawned. [pid: 33194, command: [/usr/local/Cellar/bear/3.0.19_1/bin/intercept, --library, /usr/local/Cellar/bear/3.0.19_1/lib/bear/libexec.dylib, --wrapper, /usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper, --wrapper-dir, /usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d, --output, compile_commands.events.json, --verbose, --, make]]
[16:12:42.081461, br, 33193] Process wait requested. [pid: 33194]
[16:12:42.097067, ic, 33194] intercept: 3.0.19
[16:12:42.097552, ic, 33194] arguments: ["/usr/local/Cellar/bear/3.0.19_1/bin/intercept", "--library", "/usr/local/Cellar/bear/3.0.19_1/lib/bear/libexec.dylib", "--wrapper", "/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper", "--wrapper-dir", "/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d", "--output", "compile_commands.events.json", "--verbose", "--", "make"]
[16:12:42.114416, ic, 33194] environment: [ ... ]
[16:12:42.153932, ic, 33194] sysname: Darwin
[16:12:42.153936, ic, 33194] release: 20.6.0
[16:12:42.153938, ic, 33194] version: Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
[16:12:42.189187, ic, 33194] machine: x86_64
[16:12:42.189221, ic, 33194] arguments parsed: {program: /usr/local/Cellar/bear/3.0.19_1/bin/intercept, arguments: [{--: [make]}, {--library: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/libexec.dylib]}, {--output: [compile_commands.events.json]}, {--verbose: []\
}, {--wrapper: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper]}, {--wrapper-dir: [/usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d]}]}
[16:12:42.191648, ic, 33194] session initialized with: wrapper_dir: /usr/local/Cellar/bear/3.0.19_1/lib/bear/wrapper.d
[16:12:42.191657, ic, 33194] session initialized with: mapping: [{ "ar": "/usr/bin/ar" }, { "arm-none-eabi-gcc": "/usr/local/bin/arm-none-eabi-gcc" }, { "as": "/usr/bin/as" }, { "bison": "/usr/bin/bison" }, { "c++": "/usr/bin/c++" }, { "cc": "/usr/local/bin/a\
rm-none-eabi-gcc" }, { "clang": "/usr/bin/clang" }, { "clang++": "/usr/bin/clang++" }, { "cpp": "/usr/bin/cpp" }, { "flex": "/usr/bin/flex" }, { "g++": "/usr/bin/g++" }, { "gcc": "/usr/bin/gcc" }, { "ld": "/usr/bin/ld" }, { "lex": "/usr/bin/lex" }, { "makeinfo": "/usr/bin/makeinfo" }, { "nm": "/usr/bin/nm" }, { "objdump": "/usr/bin/objdump" }, { "ranlib": "/usr/bin/ranlib" }, { "strip": "/usr/bin/strip" }, { "yacc": "/usr/bin/yacc" }]
[16:12:42.228376, ic, 33194] session initialized with: override: [{ "CC": "cc" }]
[16:12:42.230692, ic, 33194] Running gRPC server. dns:///localhost:61360
[16:12:42.231629, ic, 33194] Process spawned. [pid: 33195, command: [make]]
[16:12:42.231654, ic, 33194] Process wait requested. [pid: 33195]
/usr/local/bin/arm-none-eabi-gcc -c hello.c
[16:12:42.271137, ic, 33194] Process wait request: done. [pid: 33195]
[16:12:42.271161, ic, 33194] Running command. [Exited with 0]
[16:12:42.271169, ic, 33194] Stopping gRPC server.
[16:12:42.271552, ic, 33194] succeeded with: 0
[16:12:42.272357, br, 33193] Process wait request: done. [pid: 33194]
[16:12:42.272374, br, 33193] Running intercept finished. [Exited with 0]
[16:12:42.273160, br, 33193] Process spawned. [pid: 33199, command: [/usr/local/Cellar/bear/3.0.19_1/bin/citnames, --input, compile_commands.events.json, --output, compile_commands.json, --run-checks, --config, config.json, --verbose]]
[16:12:42.273178, br, 33193] Process wait requested. [pid: 33199]
[16:12:42.289157, cs, 33199] citnames: 3.0.19
[16:12:42.289788, cs, 33199] arguments: ["/usr/local/Cellar/bear/3.0.19_1/bin/citnames", "--input", "compile_commands.events.json", "--output", "compile_commands.json", "--run-checks", "--config", "config.json", "--verbose"]
[16:12:42.289820, cs, 33199] environment: [ ... ]
[16:12:42.344521, cs, 33199] sysname: Darwin
[16:12:42.344527, cs, 33199] release: 20.6.0
[16:12:42.344528, cs, 33199] version: Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
[16:12:42.344529, cs, 33199] machine: x86_64
[16:12:42.344542, cs, 33199] arguments parsed: {program: /usr/local/Cellar/bear/3.0.19_1/bin/citnames, arguments: [{--config: [config.json]}, {--input: [compile_commands.events.json]}, {--output: [compile_commands.json]}, {--run-checks: []}, {--verbose: []}]}
[16:12:42.344769, cs, 33199] Configuration: {"compilation":{"compilers_to_recognize":[{"executable":"/usr/local/bin/arm-none-eabi-gcc"}]},"output":{"content":{"include_only_existing_source":true},"format":{"command_as_array":true,"drop_output_field":false}}}
[16:12:42.380663, cs, 33199] compilation entries created. [size: 0]
[16:12:42.380670, cs, 33199] compilation entries to output. [size: 0]
[16:12:42.380866, cs, 33199] compilation entries written. [size: 0]
[16:12:42.380879, cs, 33199] succeeded with: 0
[16:12:42.381760, br, 33193] Process wait request: done. [pid: 33199]
[16:12:42.381795, br, 33193] Running citnames finished. [Exited with 0]
[16:12:42.381856, br, 33193] succeeded with: 0
% 

compile_commands.json:

[]
rizsotto commented 2 years ago

@hanyazou your make file should allow to interpose the compiler. Change it into this...

hello.o: hello.c
        $(CC) -c hello.c

and call it as...

CC=/usr/local/bin/arm-none-eabi-gcc bear --config config.json -- make

I presume it will work without the config file too...

CC=/usr/local/bin/arm-none-eabi-gcc bear -- make
hanyazou commented 2 years ago

Okay, so the make must spawn just 'cc' command instead of real compiler? I could understand how the bear works though I have difficulty to change the Makefile(s) with huge complex build system.

Thank you.

Makefile:

hello.o: hello.c
        $(CC) -c hello.c

run:

% CC=/usr/local/bin/arm-none-eabi-gcc bear -- make
cc -c hello.c

compile_commands.json:

[
  {
    "arguments": [
      "/usr/local/bin/arm-none-eabi-gcc",
      "-c",
      "hello.c"
    ],
    "directory": "/Users/hanyazou/workspace/tmp/bear-test",
    "file": "/Users/hanyazou/workspace/tmp/bear-test/hello.c"
  }
]
rizsotto commented 2 years ago

Okay, so the make must spawn just 'cc' command instead of real compiler?

It is executing the real compiler (as you have seen in the output), but the build file just refers the environment variable that contains the compiler name.

I could understand how the bear works though I have difficulty to change the Makefile(s) with huge complex build system.

@hanyazou the build should be open to configure the compiler. (And usually it's like that for "huge complex" projects. See GCC or the Linux kernel source.) It's considered a bad practice if the build "hardcode" the compiler (or it's path).

If your build is using a configuration step (./configure in GNU autotools), run Bear against it too. (See more here.)

hanyazou commented 2 years ago

@rizsotto

It's considered a bad practice if the build "hardcode" the compiler (or it's path).

True.

This works perfect for my current project. The build system determine which compiler should be used depending to the target specified. But I could override the compiler with CC=cc.

% CC=/usr/local/bin/arm-none-eabi-gcc bear -- make CC=cc

Your tool is very helpful. Thank you.