Skip to content

Add C Conan classes, update config file parser w/ multi-language support

Leaminn Ma requested to merge add-c-config-file-classes into master

What does this MR do and why?

Previous MRs

In !162313 (merged), we introduced the ConfigFiles::Base class where the intention is for each dependency manager config file type to be represented by a child class. The child class contains the parsing logic to extract a list of libraries and their versions from the file content.

In !165260 (merged), !165583 (merged), and !166227 (merged), we introduced config file classes CppConanPy, CppConanTxt, and CppVcpkg for the language C++.

This MR

In this MR, we introduce the counterparts to CppConanPy, CppConanTxt, and CppVcpkg for the language C. We also update ConfigFileParser to support these new classes (where the same config file path is used for multiple languages).

Notes about this approach:

Since these C config classes have the same self.file_name_glob value and parsing logic as their C++ counterparts, there may be redundant finding and parsing of the exact same file when executing ConfigFileParser.

For example, if a project only has the ConanPy dependency manager, then the file conanfile.py will be found and parsed once for C and again for C++.

We require a copy of the Xray report for both c and cpp in the xray_reports table as it enables the report to be injected into the AI prompt context for either language (see the logic here.)

Having said the above, this potential redundancy is minor in operational cost (especially when compared to the external Gitaly calls, which have not changed). It prevents the need to overcomplicate the related logic and allows us to finely tune the order of precedence of dependency managers in ConfigFiles::Constants. It also allows us to easily support future cases where the dependency manager uses the same file path but different parsing logic depending on the target language.

Resolves part of #476177 (closed).

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Enable the feature flag: Feature.enable(:ai_enable_internal_repository_xray_service)

  2. Create a new blank project and add the following file to the repo:

subdir/conanfile.py:

class SampleConan(ConanFile):
    other_lib = "my_other_lib"
    version = "1.2.3"

    def requirements(self):
        self.requires("fmt/6.0.0@bin/stable")
        self.requires("libiconv/1.17")
        self.requires("poco/[>1.0 <1.9]") # Range of versions specified
        self.requires("glog/0.5.0#revision1")
  1. Observe that an X-ray report for both c and cpp is recorded:
project = Project.last # Should be the project you created earlier
project.reload.xray_reports

Screenshot_2024-09-18_at_5.46.31_PM

Related to #476177 (closed)

Edited by Leaminn Ma

Merge request reports

Loading