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

Make CxxToolchainInfo.mk_comp_db optional. #594

Closed
wants to merge 1 commit into from
Closed

Conversation

zadlg
Copy link
Contributor

@zadlg zadlg commented Mar 7, 2024

Make CxxToolchainInfo.mk_comp_db optional.

According to the documentation, constructing a CxxToolchainInfo requires
at least C/C++ compiler info along with linker info.
It means that CxxToolchainInfo.mk_comp_db should be optional. By the way,
its definition is set to default = None.

A None value in CxxToolchainInfo.mk_comp_db leads to an error:

Caused by:
    Traceback (most recent call last):
      File <builtin>, in <module>
      * prelude/rules.bzl:101, in buck2_compatibility_shim
          return impl(ctx)
      * prelude/cxx/cxx.bzl:191, in cxx_library_impl
          output = cxx_library_parameterized(ctx, params)
      * prelude/cxx/cxx_library.bzl:425, in cxx_library_parameterized
          comp_db = create_compilation_database(ctx, compiled_srcs.compile_cmds.src_com...
    error: Operation `[]` not supported for types `NoneType` and `run_info_callable`
      --> prelude/cxx/comp_db.bzl:34:18
       |
    34 |     mk_comp_db = get_cxx_toolchain_info(ctx).mk_comp_db[RunInfo]
       |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |

This commit fixes this small bug by allowing None in CxxToolchainInfo.mk_comp_db.

According to [the documentation], constructing a [`CxxToolchainInfo`] requires
at least C/C++ compiler info along with linker info.
It means that [`CxxToolchainInfo.mk_comp_db`] should be optional. By the way,
its definition is set to `default = None`.

A `None` value in [`CxxToolchainInfo.mk_comp_db`] leads to an error:

```
Caused by:
    Traceback (most recent call last):
      File <builtin>, in <module>
      * prelude/rules.bzl:101, in buck2_compatibility_shim
          return impl(ctx)
      * prelude/cxx/cxx.bzl:191, in cxx_library_impl
          output = cxx_library_parameterized(ctx, params)
      * prelude/cxx/cxx_library.bzl:425, in cxx_library_parameterized
          comp_db = create_compilation_database(ctx, compiled_srcs.compile_cmds.src_com...
    error: Operation `[]` not supported for types `NoneType` and `run_info_callable`
      --> prelude/cxx/comp_db.bzl:34:18
       |
    34 |     mk_comp_db = get_cxx_toolchain_info(ctx).mk_comp_db[RunInfo]
       |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
```

This commit fixes this small bug by allowing `None` in [`CxxToolchainInfo.mk_comp_db`].

[the documentation]: https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L251-L255
[`CxxToolchainInfo`]: https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L167
[`CxxToolchainInfo.mk_comp_db`]: https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L183
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 7, 2024
@zadlg zadlg marked this pull request as ready for review March 7, 2024 11:03
@JakobDegen
Copy link
Contributor

Thanks!

@facebook-github-bot
Copy link
Contributor

@JakobDegen has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@zadlg
Copy link
Contributor Author

zadlg commented Mar 11, 2024

I'm not sure to understand the failure here: https://github.com/facebook/buck2/actions/runs/8187055765/job/22490706786?pr=594#step:5:3347 but I guess it's unrelated to my PR.

facebook-github-bot pushed a commit to facebook/buck2-prelude that referenced this pull request Mar 11, 2024
Summary:
Make `CxxToolchainInfo.mk_comp_db` optional.

According to [the documentation], constructing a [`CxxToolchainInfo`] requires
at least C/C++ compiler info along with linker info.
It means that [`CxxToolchainInfo.mk_comp_db`] should be optional. By the way,
its definition is set to `default = None`.

A `None` value in [`CxxToolchainInfo.mk_comp_db`] leads to an error:

```
Caused by:
    Traceback (most recent call last):
      File <builtin>, in <module>
      * prelude/rules.bzl:101, in buck2_compatibility_shim
          return impl(ctx)
      * prelude/cxx/cxx.bzl:191, in cxx_library_impl
          output = cxx_library_parameterized(ctx, params)
      * prelude/cxx/cxx_library.bzl:425, in cxx_library_parameterized
          comp_db = create_compilation_database(ctx, compiled_srcs.compile_cmds.src_com...
    error: Operation `[]` not supported for types `NoneType` and `run_info_callable`
      --> prelude/cxx/comp_db.bzl:34:18
       |
    34 |     mk_comp_db = get_cxx_toolchain_info(ctx).mk_comp_db[RunInfo]
       |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
```

This commit fixes this small bug by allowing `None` in [`CxxToolchainInfo.mk_comp_db`].

[the documentation]: https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L251-L255
[`CxxToolchainInfo`]: https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L167
[`CxxToolchainInfo.mk_comp_db`]: https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L183

X-link: facebook/buck2#594

Reviewed By: ndmitchell

Differential Revision: D54732663

Pulled By: JakobDegen

fbshipit-source-id: 85a22a21194285919c6dd5643c4a0dedaf6099ac
facebook-github-bot pushed a commit that referenced this pull request Mar 11, 2024
Summary:
Disable stripping stage if no strip binary was provided.

[`CxxToolchainInfo`] has a field called [`binary_utilities_info`] which
points to some binary utilities such as [`strip`] or [`objcopy`].

Similar to #594, according to
[the documentation](https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L251-L255),
[`CxxToolchainInfo.binary_utilities_info`] is optional.

However, in the [`cxx_library` implementation], [`_strip_objects`] is called
regardless of the [`CxxToolchainInfo.binary_utilities_info`] value.

This leads to the following error:

```
Caused by:
    Traceback (most recent call last):
      File <builtin>, in <module>
      * prelude/rules.bzl:101, in buck2_compatibility_shim
          return impl(ctx)
      * prelude/cxx/cxx.bzl:191, in cxx_library_impl
          output = cxx_library_parameterized(ctx, params)
      * prelude/cxx/cxx_library.bzl:371, in cxx_library_parameterized
          compiled_srcs = cxx_compile_srcs(
      * prelude/cxx/cxx_library.bzl:914, in cxx_compile_srcs
          pic = _get_library_compile_output(ctx, pic_cxx_outs, impl_params.extra_link_i...
      * prelude/cxx/cxx_library.bzl:866, in _get_library_compile_output
          stripped_objects = _strip_objects(ctx, objects)
      * prelude/cxx/cxx_library.bzl:1108, in _strip_objects
          outs.append(strip_debug_info(ctx, base + ".stripped.o", obj))
      * prelude/linking/strip.bzl:67, in strip_debug_info
          return _strip_debug_info(
    error: Object of type `NoneType` has no attribute `strip`
      --> prelude/linking/strip.bzl:16:13
       |
    16 |     strip = cxx_toolchain.binary_utilities_info.strip
       |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

```

This commit prevents this bug from happening by making [`CxxToolchainInfo.binary_utilities_info`]
truely optional.

[`CxxToolchainInfo`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L167
[`binary_utilities_info`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L176
[`CxxToolchainInfo.binary_utilities_info`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L176
[`strip`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L77
[`objcopy`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L75
[`cxx_library` implementation]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_library.bzl#L866
[`_strip_objects`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_library.bzl#L1093

Pull Request resolved: #595

Reviewed By: ndmitchell

Differential Revision: D54732708

Pulled By: JakobDegen

fbshipit-source-id: a89dc6b452658c8f3c1773b9b5ad1f4882d7b957
facebook-github-bot pushed a commit to facebook/buck2-prelude that referenced this pull request Mar 11, 2024
Summary:
Disable stripping stage if no strip binary was provided.

[`CxxToolchainInfo`] has a field called [`binary_utilities_info`] which
points to some binary utilities such as [`strip`] or [`objcopy`].

Similar to facebook/buck2#594, according to
[the documentation](https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L251-L255),
[`CxxToolchainInfo.binary_utilities_info`] is optional.

However, in the [`cxx_library` implementation], [`_strip_objects`] is called
regardless of the [`CxxToolchainInfo.binary_utilities_info`] value.

This leads to the following error:

```
Caused by:
    Traceback (most recent call last):
      File <builtin>, in <module>
      * prelude/rules.bzl:101, in buck2_compatibility_shim
          return impl(ctx)
      * prelude/cxx/cxx.bzl:191, in cxx_library_impl
          output = cxx_library_parameterized(ctx, params)
      * prelude/cxx/cxx_library.bzl:371, in cxx_library_parameterized
          compiled_srcs = cxx_compile_srcs(
      * prelude/cxx/cxx_library.bzl:914, in cxx_compile_srcs
          pic = _get_library_compile_output(ctx, pic_cxx_outs, impl_params.extra_link_i...
      * prelude/cxx/cxx_library.bzl:866, in _get_library_compile_output
          stripped_objects = _strip_objects(ctx, objects)
      * prelude/cxx/cxx_library.bzl:1108, in _strip_objects
          outs.append(strip_debug_info(ctx, base + ".stripped.o", obj))
      * prelude/linking/strip.bzl:67, in strip_debug_info
          return _strip_debug_info(
    error: Object of type `NoneType` has no attribute `strip`
      --> prelude/linking/strip.bzl:16:13
       |
    16 |     strip = cxx_toolchain.binary_utilities_info.strip
       |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

```

This commit prevents this bug from happening by making [`CxxToolchainInfo.binary_utilities_info`]
truely optional.

[`CxxToolchainInfo`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L167
[`binary_utilities_info`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L176
[`CxxToolchainInfo.binary_utilities_info`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L176
[`strip`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L77
[`objcopy`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L75
[`cxx_library` implementation]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_library.bzl#L866
[`_strip_objects`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_library.bzl#L1093

X-link: facebook/buck2#595

Reviewed By: ndmitchell

Differential Revision: D54732708

Pulled By: JakobDegen

fbshipit-source-id: a89dc6b452658c8f3c1773b9b5ad1f4882d7b957
wavewave pushed a commit to MercuryTechnologies/buck2-prelude that referenced this pull request Apr 26, 2024
Summary:
Make `CxxToolchainInfo.mk_comp_db` optional.

According to [the documentation], constructing a [`CxxToolchainInfo`] requires
at least C/C++ compiler info along with linker info.
It means that [`CxxToolchainInfo.mk_comp_db`] should be optional. By the way,
its definition is set to `default = None`.

A `None` value in [`CxxToolchainInfo.mk_comp_db`] leads to an error:

```
Caused by:
    Traceback (most recent call last):
      File <builtin>, in <module>
      * prelude/rules.bzl:101, in buck2_compatibility_shim
          return impl(ctx)
      * prelude/cxx/cxx.bzl:191, in cxx_library_impl
          output = cxx_library_parameterized(ctx, params)
      * prelude/cxx/cxx_library.bzl:425, in cxx_library_parameterized
          comp_db = create_compilation_database(ctx, compiled_srcs.compile_cmds.src_com...
    error: Operation `[]` not supported for types `NoneType` and `run_info_callable`
      --> prelude/cxx/comp_db.bzl:34:18
       |
    34 |     mk_comp_db = get_cxx_toolchain_info(ctx).mk_comp_db[RunInfo]
       |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
```

This commit fixes this small bug by allowing `None` in [`CxxToolchainInfo.mk_comp_db`].

[the documentation]: https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L251-L255
[`CxxToolchainInfo`]: https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L167
[`CxxToolchainInfo.mk_comp_db`]: https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L183

X-link: facebook/buck2#594

Reviewed By: ndmitchell

Differential Revision: D54732663

Pulled By: JakobDegen

fbshipit-source-id: 85a22a21194285919c6dd5643c4a0dedaf6099ac
wavewave pushed a commit to MercuryTechnologies/buck2-prelude that referenced this pull request Apr 26, 2024
Summary:
Disable stripping stage if no strip binary was provided.

[`CxxToolchainInfo`] has a field called [`binary_utilities_info`] which
points to some binary utilities such as [`strip`] or [`objcopy`].

Similar to facebook/buck2#594, according to
[the documentation](https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L251-L255),
[`CxxToolchainInfo.binary_utilities_info`] is optional.

However, in the [`cxx_library` implementation], [`_strip_objects`] is called
regardless of the [`CxxToolchainInfo.binary_utilities_info`] value.

This leads to the following error:

```
Caused by:
    Traceback (most recent call last):
      File <builtin>, in <module>
      * prelude/rules.bzl:101, in buck2_compatibility_shim
          return impl(ctx)
      * prelude/cxx/cxx.bzl:191, in cxx_library_impl
          output = cxx_library_parameterized(ctx, params)
      * prelude/cxx/cxx_library.bzl:371, in cxx_library_parameterized
          compiled_srcs = cxx_compile_srcs(
      * prelude/cxx/cxx_library.bzl:914, in cxx_compile_srcs
          pic = _get_library_compile_output(ctx, pic_cxx_outs, impl_params.extra_link_i...
      * prelude/cxx/cxx_library.bzl:866, in _get_library_compile_output
          stripped_objects = _strip_objects(ctx, objects)
      * prelude/cxx/cxx_library.bzl:1108, in _strip_objects
          outs.append(strip_debug_info(ctx, base + ".stripped.o", obj))
      * prelude/linking/strip.bzl:67, in strip_debug_info
          return _strip_debug_info(
    error: Object of type `NoneType` has no attribute `strip`
      --> prelude/linking/strip.bzl:16:13
       |
    16 |     strip = cxx_toolchain.binary_utilities_info.strip
       |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

```

This commit prevents this bug from happening by making [`CxxToolchainInfo.binary_utilities_info`]
truely optional.

[`CxxToolchainInfo`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L167
[`binary_utilities_info`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L176
[`CxxToolchainInfo.binary_utilities_info`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L176
[`strip`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L77
[`objcopy`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_toolchain_types.bzl#L75
[`cxx_library` implementation]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_library.bzl#L866
[`_strip_objects`]: https://github.com/facebook/buck2/blob/6b2b497907676c662baa2f39d7622241da6f0081/prelude/cxx/cxx_library.bzl#L1093

X-link: facebook/buck2#595

Reviewed By: ndmitchell

Differential Revision: D54732708

Pulled By: JakobDegen

fbshipit-source-id: a89dc6b452658c8f3c1773b9b5ad1f4882d7b957
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants