How to generate compiler param file reliably or pass no-cache to cc_common.compile?

376 views
Skip to first unread message

Konstantin

unread,
Oct 12, 2022, 2:09:26 PM10/12/22
to bazel-discuss

We have custom C++ compilation rule which invokes cc_common.compile. To test that rule we enable “compiler_param_file” toolchain feature in order to examine generated param file for the presence of expected compiler options. Unfortunately when the compilation is cached the object file is taken from the cache, but param file is not, probably as it is not included in the list of compilation action outputs.

The question: how to get param file reliably?

First thing which come to mind is to disable caching for this particular rule by adding “no-cache” tag to it. It does not work because I believe the tag must be translated to corresponding “execution_requirements” on actions.run and I don’t see a way to pass execution_requirements to cc_common.compile.

We probably can use command line switch “--modify_execution_info=CppCompile=no-cache” but it would affect ALL compilations while we need it for one.

Any ideas?

Thank you!

Konstantin

Alex Humesky

unread,
Oct 12, 2022, 5:35:16 PM10/12/22
to Konstantin, bazel-discuss
Could you write a Starlark unit test to inspect the actions and their args?

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/e70e8a2c-d0bd-4ec3-a8c4-f6847279b9b7n%40googlegroups.com.

Konstantin

unread,
Oct 12, 2022, 6:31:26 PM10/12/22
to bazel-discuss
Wow, this is something I have not thought about! Actually I didn't even know about this feature. 
Thank you Alex for widening my field of view!

Konstantin

Konstantin

unread,
Oct 13, 2022, 2:46:45 PM10/13/22
to bazel-discuss
Very interestingly this approach does not seem to work!

I use this test rule implementation
def _compiler_param_file_test_impl(ctx):
    env = analysistest.begin(ctx)
    target_under_test = analysistest.target_under_test(env)
    actions = analysistest.target_actions(env)
    asserts.equals(env, 1, len(actions))
    action = actions[0]
    args = action.args  # list
    asserts.equals(env, 1, len(args))
    arg = args[0]
    print(arg)
    return analysistest.end(env)

And what it prints is:
    external/tab_msvc_toolchain_repo_64/external/tab_msvc_2019/bin/Hostx64/x64/cl.exe /nologo /DUNICODE /D_UNICODE ...
i.e. compiler command line with all the options inline.

But when I run the same action with --subcommands it can be clearly seen that it uses param file:
    external\tab_msvc_toolchain_repo_64\external\tab_msvc_2019\bin\Hostx64\x64\cl.exe @bazel-out/x64_windows dbg/bin/tests/cpp/compiler_param_file/_objs/obj_param/src1.obj.params

analysistest will definitely help with the other Bazel rule testing we need to do, but not with the param file.

Konstantin

Alex Humesky

unread,
Oct 14, 2022, 4:55:00 PM10/14/22
to Konstantin, bazel-discuss
Could you give more details on what specifically you want to test? In the first email, it seemed that you were using params files just as a means to examine the arguments.
i.e., do you want to test that the correct arguments are being created in your rules, or do you want to test that params files are being created and used?

Konstantin

unread,
Oct 14, 2022, 6:30:59 PM10/14/22
to bazel-discuss
In this particular case I  want to test that params files are being created and used.

Alex Humesky

unread,
Oct 14, 2022, 7:23:50 PM10/14/22
to Konstantin, bazel-discuss
Hmm I'm not sure if there's a direct way to test this from within bazel.
It looks like for our own tests of something like this we have a shell test that invokes bazel and looks for the params file:

So conceivably you could write something similar, though it's somewhat of a maintenance burden to invoke bazel from within a bazel test, and not very fast

Reply all
Reply to author
Forward
0 new messages