Method and device for generating compiling database and integrated development environment
By introducing project configuration files and Rust language compilation management tools, a compilation database in JSON format is generated, which solves the problems of insufficient cross-platform compatibility and cross-compilation support in the C/C++ compilation process, achieves consistency and accuracy of cross-platform compilation parameters, and improves code analysis and development efficiency.
Patent Information
- Application Number
- CN202510849214.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-24
- Publication Date
- 2025-10-03
AI Technical Summary
The existing build system has problems such as poor cross-platform compatibility, complex configuration, and insufficient cross-compilation support during the C/C++ compilation process, which leads to inaccurate compilation parameters, affecting code compilation and intelligent functions in the integrated development environment.
By introducing project configuration files and compilation management tools implemented in Rust language, the compiler path and parameters are explicitly specified, and a compilation database in JSON format is generated to ensure the accuracy and consistency of compilation parameters and support cross-platform compilation.
It realizes cross-platform compilation database generation, improves the accuracy of code analysis and inspection, enhances development efficiency and security, and ensures the reliability and consistency of the compilation process.
Smart Images

Figure CN120743332A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of embedded system technology, and in particular to a method, device and integrated development environment for generating a compilation database. Background Art
[0002] In modern software development, different programming languages exhibit significant differences in how they build and manage project dependencies, due to their varying design mechanisms and ecosystems. For example, languages like Java and Go have comprehensive package management mechanisms that centrally manage dependent libraries and source code within a project, treating all source files as a single entity during compilation, thereby streamlining the build process and improving development efficiency. However, as system-level programming languages, C / C++ has a unique compilation process: each source file is treated as an independent compilation unit, meaning that each source file may be compiled using different compilation parameters.
[0003] Especially when it comes to importing external libraries, C / C++ lacks a centralized dependency repository mechanism like Java. In the Java programming language, all dependencies are centrally stored in a specific repository, located in a custom directory on the local computer. When a developer needs to use a dependency in a project, they can use a build tool like Maven or Gradle to automatically download the required dependency from the repository. Then, using a simple import statement in the source code, they can directly call the functionality provided by the dependency. However, in C / C++, dependent libraries can be stored in any directory, requiring manual configuration of the relevant file paths during compilation. If these paths are configured correctly, the compilation process generally proceeds smoothly. However, once compilation is complete, in most development environments, developers often encounter issues such as header file locators and undefined symbols due to a lack of accurate identification of the locations of these dependent libraries. This not only impacts the proper compilation of the code but also hinders features in integrated development environments (IDEs), such as code jumps and smart prompts.
[0004] To address these issues, the concept of a compilation database was introduced. This database typically exists as a compile_commands.json file, which lists the complete compilation parameters used during the compilation of every source file in the project. Each list item contains three core fields: directory, command, and file. Their specific meanings are shown in Table 1.
[0005] Table 1
[0006] property meaning directory The working directory where the compilation command is executed, usually the root path of the project. command Compilation parameter options, that is, the complete compilation command line. file The path to the compiled source code file.
[0007] By generating and maintaining the compile_commands.json file, developers can use it with mainstream IDEs (such as Visual Studio Code, CLion, etc.) or static analysis tools (such as clang-tidy, clangd, etc.) to achieve advanced features such as smart code completion, symbol jump, error checking, etc.
[0008] Currently, there are many build systems that support generating compile_commands.json files during the compilation process, including Make and CMake:
[0009] Make: By installing the third-party tool Bear, you can capture compilation commands during the compilation process and generate a compile_commands.json file. However, Bear only works on Linux systems and lacks cross-platform support, limiting its application in multi-platform development.
[0010] CMake: As a meta-build system, CMake itself does not directly perform compilation operations. Instead, it generates target-specific build scripts through designated generators (such as Unix Makefiles and Ninja). CMake natively supports the generation of compile_commands.json files and runs on both Windows and Linux systems. However, in cross-compilation scenarios, the compilation database generated by CMake may prioritize system libraries over toolchain libraries, resulting in inaccurate compilation parameters and affecting the correct parsing and use of the subsequent toolchain.
[0011] In summary, although existing build systems support the generation of compilation databases to a certain extent, there are still problems such as poor cross-platform compatibility, complex configuration, and insufficient cross-compilation support. Summary of the Invention
[0012] In view of the above problems in the prior art, the present application provides a method, apparatus, integrated development environment, equipment and storage medium for generating a compilation database. By providing an engineering configuration file in a unified format and a compilation management tool implemented in the Rust language, the accurate and efficient generation of the compilation database is achieved, and it supports directly driving the source file to complete the actual compilation process, which not only improves the consistency of build information and compilation behavior, but also enhances cross-platform compatibility.
[0013] To achieve the above-mentioned objectives, the first aspect of the present application provides a method for generating a compilation database, comprising:
[0014] Create a project configuration file, which includes a compiler path, compilation parameters, and a source file list;
[0015] Parsing the project configuration file through a compilation management tool to obtain a list of source files to be compiled, compilation parameters corresponding to each source file, and a compiler path;
[0016] The compilation management tool generates a compilation database based on the source file list and the corresponding compilation parameters and compiler path for use by the static scanning tool, wherein the compilation database records the compilation command line and source file path corresponding to each source file, and the compilation command line is composed of at least the compiler path, compilation parameters and the name of the source file to be compiled.
[0017] In this way, the present application introduces a project configuration file and allows the user to explicitly specify the compiler path and compilation parameters in the project configuration file. This makes it possible for the compilation process in a cross-compilation environment no longer rely on the default configuration of the host system, but is executed based on the parameters specified by the user in the project configuration file. Therefore, it ensures that the compilation parameters used in the process of generating the compilation database are accurate and reliable, and consistent with the target platform, solving the technical problem of inaccurate parameter configuration in cross-compilation scenarios in the prior art.
[0018] In addition, the generated compilation database can be directly provided to the static scanning tool, enabling the static scanning tool to accurately obtain the compilation information of each source file, helping the static scanning tool to achieve more accurate code analysis and inspection, and improve code quality and security.
[0019] As a possible implementation of the first aspect, the compilation database is an array in JSON format, wherein the compilation information of each source file is represented by each array {director, command, file}.
[0020] Among them, the directory represents the working directory where the compilation command is executed; the command represents the compilation command line, which is composed of at least the compiler path, compilation parameters and the name of the source file to be compiled; and the file represents the path of the source file to be compiled relative to the directory path.
[0021] In this way, the compilation database is represented by an array in JSON format, and the compilation information of each source file is represented by an object containing directory, command, and file fields. Specifically, directory specifies the working directory where the compilation command is executed, ensuring the consistency of the command execution environment; command contains the compilation command line, which is composed of at least the compiler path, compilation parameters, and the name of the source file to be compiled, providing detailed compilation instructions for easy debugging and verification; file represents the path of the source file to be compiled relative to the directory path, enhancing the portability and accuracy of the configuration. This standardized structure enables the compilation database to be directly read and processed by modern development tools and CI / CD pipelines, thereby supporting automated code analysis, testing, and deployment processes. For example, static analysis tools can accurately restore the compilation context of each source file based on the compilation information in the database, achieving more accurate code checking and error detection.
[0022] As a possible implementation of the first aspect, creating the project configuration file includes:
[0023] When creating a new project in an integrated development environment, initialize a project configuration file in the project root directory; or, for an existing project imported from outside, copy a project configuration file template to the project root directory;
[0024] Use the graphical interface or manually edit the file to modify the contents of the initialized project configuration file or the copied project configuration file.
[0025] This implementation makes the creation of project configuration files more flexible and convenient, catering to both novice and advanced users. By providing automatic initialization and template import mechanisms in different scenarios, combined with a graphical interface and manual editing, this application effectively improves configuration efficiency and accuracy, laying a solid foundation for the subsequent generation of a standardized compilation database.
[0026] As a possible implementation of the first aspect, the following also is included:
[0027] The compilation management tool also calls the corresponding compiler under the compiler path according to the project configuration file, executes the compilation process on each source file according to the compilation parameters corresponding to each source file, and generates an executable binary file.
[0028] In this way, the compilation management tool can generate a compilation database based on the project configuration file and directly drive the compilation process of the source file without relying on or using other additional build systems or tools to complete it, thus realizing the unified management of build information and compilation behavior.
[0029] As a possible implementation of the first aspect, the compilation management tool is implemented using the Rust language.
[0030] As a result, Rust boasts security, high performance, and powerful cross-platform capabilities, overcoming the limitations of traditional tools like Bear, which only run on specific platforms (such as Linux), achieving true cross-platform support. This means that build management tools written in Rust can run on different operating systems, such as Windows, Linux, and macOS, without requiring extensive code modifications or adaptations. This cross-platform nature greatly enhances the versatility and portability of build management tools, allowing developers to use the same tools for project building and management in a variety of environments.
[0031] To achieve the above-mentioned purpose, the second aspect of the present application provides an apparatus for generating a compilation database, comprising:
[0032] A creation unit, configured to create a project configuration file, wherein the project configuration file includes a compiler path, compilation parameters, and a source file list;
[0033] A parsing unit, configured to parse the project configuration file through a compilation management tool to obtain a list of source files to be compiled, compilation parameters corresponding to each source file, and a compiler path;
[0034] A generation unit is configured to generate a compilation database based on the source file list and corresponding compilation parameters and compiler path through the compilation management tool for use by the static scanning tool, wherein the compilation database records the compilation command line and source file path corresponding to each source file, and the compilation command line is composed of at least the compiler path, compilation parameters, and the name of the source file to be compiled.
[0035] To achieve the above objectives, the third aspect of the present application provides an integrated development environment, including:
[0036] A project management module is used to create a project, wherein the project creation includes creating a project configuration file, wherein the project configuration file includes a compiler path, compilation parameters, and a source file list;
[0037] Code editing module, used to implement the writing of source file code;
[0038] A compilation management tool, configured to generate a compilation database based on the source file list and corresponding compilation parameters and compiler path, and to call the corresponding compiler under the compiler path to execute a compilation process on each source file according to the compilation parameters corresponding to each source file, thereby generating an executable binary file; wherein the compilation database records the compilation command line and source file path corresponding to each source file, and the compilation command line is composed of at least the compiler path, compilation parameters, and the name of the source file to be compiled;
[0039] A static scanning tool is used to provide auxiliary functions for code writing based on the compilation database, wherein the auxiliary functions include code completion, code navigation or code error diagnosis during the writing process of the source file code.
[0040] As a possible implementation of the third aspect, the compilation management tool is integrated into the integrated development environment in a plug-in manner.
[0041] To achieve the above-mentioned objectives, the fourth aspect of the present application provides a computing device, including:
[0042] processor, and
[0043] A memory having program instructions stored thereon, wherein when the program instructions are executed by the processor, the processor is caused to execute the method described in any one of the first aspects above.
[0044] To achieve the above-mentioned objectives, the fifth aspect of the present application provides a computer-readable storage medium having program instructions stored thereon, which, when executed by a computer, enables the computer to implement any of the methods described in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 This is a flow chart of the main steps of a method for generating a compilation database provided by the present application;
[0046] Figure 2 This is a schematic diagram of the structure of the first embodiment provided by this application;
[0047] Figure 3 This is a flowchart of the steps of Example 1 provided in this application;
[0048] Figure 4 This is a schematic diagram of the structure of a device for generating a compilation database provided by the present application;
[0049] Figure 5 This is a schematic diagram of the structure of an integrated development environment provided by this application;
[0050] Figure 6 It is a structural diagram of a computing device provided by this application.
[0051] It should be understood that the sizes and shapes of the blocks in the above structural diagrams are for reference only and should not constitute an exclusive interpretation of the embodiments of the present invention. The relative positions and inclusion relationships between the blocks presented in the structural diagrams are merely schematic representations of the structural relationships between the blocks and do not limit the physical connection methods of the embodiments of the present invention. DETAILED DESCRIPTION
[0052] The technical solution provided by this application is further described below with reference to the accompanying drawings and examples. It should be understood that the system structure and business scenarios provided in the examples of this application are mainly for illustrating possible implementation methods of the technical solution of this application and should not be interpreted as the sole limitation of the technical solution of this application. It is known to those skilled in the art that with the evolution of the system structure and the emergence of new business scenarios, the technical solution provided by this application is also applicable to similar technical problems.
[0053] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art in the art of this application. In the event of any inconsistency, the meaning described in this specification or the meaning derived from the contents recorded in this specification shall prevail. In addition, the terms used herein are only for the purpose of describing the embodiments of the present application and are not intended to limit this application.
[0054] Before introducing the embodiments of the present application, the following contents are introduced first:
[0055] 1) Integrated Development Environment: An IDE is a tool used by developers to write, debug, and manage code. It typically provides functions such as code completion, syntax highlighting, code jumps, and error prompts.
[0056] 2) Static analysis tools, in the embodiment of the present application, refer to tools that can understand code based on the compilation database (compile_commands.json) and provide programmers with support such as code completion, navigation, and diagnostics.
[0057] 3) clangd language server: A static analysis tool that provides intelligent features for C / C++ code, such as code completion, code jump, and error prompts. It understands the context of the code by analyzing the code and the compilation database (compile_commands.json).
[0058] When developing C / C++ projects in many integrated development environments (IDEs), they often integrate language servers like clangd to provide features like code jumps and intelligent prompts. The compilation database (e.g., compile_commands.json) is the core data source for clangd. By parsing the information in the compilation database, clangd provides intelligent features such as code completion, error prompts, and header file navigation. The compilation database records the compilation commands and parameters for each source file, ensuring that the clangd language server accurately understands the project's compilation context.
[0059] However, if the compilation database is not generated accurately, it will significantly affect the accuracy of code hints and other intelligent features. For example, the following problems may occur:
[0060] Inaccurate code hints: Because the compilation database fails to correctly reflect the actual compilation configuration of the project, the code hint function may not be able to identify the correct variable, function, or macro definition.
[0061] Header file not found: Even if the compilation process is completed successfully, the development environment may still continue to prompt the problem of header file or macro undefined, because the clangd language server cannot find the required header file path or macro definition based on the incorrect compilation database.
[0062] Therefore, generating an accurate and compliant compilation database is crucial to ensuring the normal operation of intelligent functions in the development environment. This not only improves development efficiency but also reduces potential problems caused by configuration errors, improving the overall development experience.
[0063] Based on the above problems, the following contents of this application are proposed.
[0064] The present application embodiment provides a method for generating a compilation database, such as Figure 1 As shown, including:
[0065] S101, creating a project configuration file, wherein the project configuration file includes a compiler path, compilation parameters, and a source file list;
[0066] In the project configuration file, users can specify the corresponding compiler path and compilation parameters for different operating systems and compilers.
[0067] Example 1: When using the MSVC compiler on Windows, users can specify the MSVC compiler path and related compilation parameters in the project configuration file;
[0068] Example 2: When using the GCC compiler on Linux, users can specify the GCC compiler path and related compilation parameters in the project configuration file.
[0069] S102, parsing the project configuration file through a compilation management tool to obtain a list of source files to be compiled, compilation parameters corresponding to each source file, and a compiler path;
[0070] S103. Generate a compilation database using the compilation management tool based on the source file list and corresponding compilation parameters and compiler path for use by the static scanning tool, wherein the compilation database records the compilation command line and source file path corresponding to each source file, and the compilation command line is composed of at least the compiler path, compilation parameters, and the name of the source file to be compiled.
[0071] In this way, the present application introduces a project configuration file and allows the user to explicitly specify the compiler path and compilation parameters in the project configuration file. This makes it possible for the compilation process in a cross-compilation environment no longer rely on the default configuration of the host system, but is executed based on the parameters specified by the user in the project configuration file. Therefore, it ensures that the compilation parameters used in the process of generating the compilation database are accurate and reliable, and consistent with the target platform, solving the technical problem of inaccurate parameter configuration in cross-compilation scenarios in the prior art.
[0072] In addition, the generated compilation database can be directly provided to the static scanning tool, enabling the static scanning tool to accurately obtain the compilation information of each source file, helping the static scanning tool to achieve more accurate code analysis and inspection, and improve code quality and security.
[0073] In some embodiments, the compilation database is an array in JSON format, wherein the compilation information of each source file is represented by each array {director, command, file}.
[0074] Among them, the directory represents the working directory where the compilation command is executed; the command represents the compilation command line, which is composed of at least the compiler path, compilation parameters and the name of the source file to be compiled; and the file represents the path of the source file to be compiled relative to the directory path.
[0075] In this way, the compilation database is represented by an array in JSON format, and the compilation information of each source file is represented by an object containing directory, command, and file fields. Specifically, directory specifies the working directory where the compilation command is executed, ensuring the consistency of the command execution environment; command contains the compilation command line, which is composed of at least the compiler path, compilation parameters, and the name of the source file to be compiled, providing detailed compilation instructions for easy debugging and verification; file represents the path of the source file to be compiled relative to the directory path, enhancing the portability and accuracy of the configuration. This standardized structure enables the compilation database to be directly read and processed by modern development tools and CI / CD pipelines, thereby supporting automated code analysis, testing, and deployment processes. For example, static analysis tools can accurately restore the compilation context of each source file based on the compilation information in the database, achieving more accurate code checking and error detection.
[0076] In some embodiments, creating a project configuration file includes:
[0077] When creating a new project in an integrated development environment, initialize a project configuration file in the project root directory; or, for an existing project imported from outside, copy a project configuration file template to the project root directory;
[0078] Use the graphical interface or manually edit the file to modify the contents of the initialized project configuration file or the copied project configuration file.
[0079] Specifically, there are two ways to create a project configuration file.
[0080] Method 1: When you create a new project in the integrated development environment (IDE), the system automatically generates a default project configuration file template in the project root directory. This template contains the compiler path, compilation parameters, and a list of source files. Its contents are empty or set to default values. You can subsequently modify and supplement the contents of this template based on your needs.
[0081] Method 2: For an existing project imported from an external source, you can copy the predefined project configuration file template to the current project root directory.
[0082] Furthermore, after creating the project configuration file, edit and configure it in the following two ways.
[0083] Method 1: The integrated development environment (IDE) provides a graphical user interface (GUI) tool. Users can configure the information in the project configuration file by clicking, selecting, and typing, such as which compiler to use, which compilation parameters to add, and which source files to include. This eliminates the need to manually write or modify the underlying JSON configuration file.
[0084] Method 2: Users can also directly open the project configuration file and manually edit it using a text editor (such as VS Code, Sublime Text, Vim, etc.).
[0085] It is worth noting that when editing and configuring the created project configuration file, the parameters specified by the user in the configuration interface are given priority to ensure that these custom settings are strictly implemented throughout the compilation process, minimizing dependence on system environment variables. Especially in cross-compilation scenarios, it effectively avoids compilation errors or inaccuracies caused by the host system's default settings, and improves the consistency and reliability of build results.
[0086] This implementation makes the creation of project configuration files more flexible and convenient, catering to both novice and advanced users. By providing automatic initialization and template import mechanisms in different scenarios, combined with a graphical interface and manual editing, this application effectively improves configuration efficiency and accuracy, laying a solid foundation for the subsequent generation of a standardized compilation database.
[0087] In some embodiments, it further includes:
[0088] The compilation management tool also calls the corresponding compiler under the compiler path according to the project configuration file, executes the compilation process on each source file according to the compilation parameters corresponding to each source file, and generates an executable binary file.
[0089] The compilation management tool can also record detailed log information during the entire compilation process. This log information may include, but is not limited to, the start and end time of each compilation step, warnings and errors generated during the compilation process, etc.
[0090] In this way, the compilation management tool can generate a compilation database based on the project configuration file and directly drive the compilation process of the source file without relying on or using other additional build systems or tools to complete it, thus realizing the unified management of build information and compilation behavior.
[0091] In some embodiments, the compilation management tool is implemented using the Rust language.
[0092] As a result, Rust boasts security, high performance, and powerful cross-platform capabilities, overcoming the limitations of traditional tools like Bear, which only run on specific platforms (such as Linux), achieving true cross-platform support. This means that build management tools written in Rust can run on different operating systems, such as Windows, Linux, and macOS, without requiring extensive code modifications or adaptations. This cross-platform nature greatly enhances the versatility and portability of build management tools, allowing developers to use the same tools for project building and management in a variety of environments.
[0093] In order to more clearly illustrate the above method of generating a compilation database, the present application provides the following specific embodiments.
[0094] In the first embodiment, the compilation management tool is described as a builder tool as an example.
[0095] The compilation database generation method of this embodiment is mainly applied to the integrated development environment IDE based on Visual Studio Code (VS Code), which is divided into four levels as a whole, such as Figure 2 shown.
[0096] Application layer: The user and caller of the builder tool. This can be a VS Code plugin or other integrated development environment that calls the builder tool through a child process to complete the relevant task, or it can be run directly from the command line to complete the relevant task.
[0097] Builder tool layer: implemented in Rust language, exists in the form of a binary executable file, and is integrated into the VS Code plug-in.
[0098] Project configuration file layer: includes data such as compiler path, compilation parameters, and source file list. It serves as the metadata file for the builder tool to parse compilation parameters.
[0099] Tool chain layer: underlying compilation, assembly, and linking tools, such as GCC, Clang, ARM compiler, etc.
[0100] It's important to note that while the Builder tool seamlessly integrates into the VS Code integrated development environment, its operation is not limited to that environment. In other words, users are not restricted to a specific development tool or platform to use the Builder tool. The Builder tool's core dependency is a project configuration file named compile_config.json. As long as a compile_config.json file that conforms to the parsed format exists in the project root directory, the Builder tool will function properly.
[0101] Combine Figure 3 As shown, the process of generating a compilation database is as follows:
[0102] S301. Create a project configuration file named compile_config.json, where the project configuration file includes a compiler path, compilation parameters, and a source file list.
[0103] Specifically, there are two ways to create a project configuration file.
[0104] The first method: create a new project through the plug-in
[0105] When a user creates a new C / C++ project in a supported IDE (such as VS Code) using a specific plug-in, such as the IntelliJ Dev Cloud plug-in, the plug-in automatically generates a project configuration file in the project root directory, which contains the initial configuration parameters.
[0106] The second method: import existing projects from outside
[0107] If the project is an existing project imported from outside, you need to manually copy a template project configuration file to the project's root directory and modify the configuration parameters according to actual needs to ensure that it meets the requirements of the current project.
[0108] After creating a project configuration file, users can modify it in the following two ways:
[0109] Through the configuration interface: Make changes on the graphical configuration interface provided by the plug-in, and the modified settings will be automatically updated to the project configuration file.
[0110] Manually edit the project configuration file: Directly open the project configuration file and manually edit its contents to meet specific compilation requirements.
[0111] S302, calling the builder tool;
[0112] Specifically, there are three ways to call the builder tool.
[0113] The first method: calling through plug-in
[0114] The user only needs to click the "Compile" button on the plug-in interface, and the plug-in background will automatically call the builder tool and pass in the path of the current project as a parameter.
[0115] The second method: call through the command line
[0116] Users can manually navigate to the project root directory in the terminal or command prompt and run commands such as builder-p [projectPath]. [projectPath] represents the project root path, and builder will read the project configuration file in this path.
[0117] The third way: through other integrated development environments
[0118] Execute the builder command through subprocess call.
[0119] S303: The builder tool parses the project configuration file to obtain a list of source files to be compiled, compilation parameters corresponding to each source file, and a compiler path.
[0120] S304: Generate a compilation database using a builder tool according to the source file list, corresponding compilation parameters, and compiler path.
[0121] Among them, each content in the compilation database contains three attributes: directory, file and command;
[0122] The number of entries in the compilation database depends on the number of source files to be compiled. That is, there is a one-to-one correspondence between the number of entries in the compilation database and the number of source files to be compiled. The source file list determines which source files need to be compiled and generates a corresponding compilation command entry for each source file, which is recorded in the compilation database.
[0123] S305: After the compilation database is generated, it is provided to the static scanning tool for use.
[0124] Specifically, the static scanning tool provides auxiliary functions for code writing based on the compilation database, and the auxiliary functions include code completion, code navigation or code error diagnosis during the writing process of the source file code.
[0125] In addition, the compilation database compile_commands.json in this embodiment is further exemplified as follows. The structure of the compile_commands.json file can be composed of multiple arrays in JSON format, each array being an object that describes the compilation information of a source file. Each array (or each object) contains three main properties:
[0126] Directory: The working directory where the compilation command is executed, usually the root path of the project.
[0127] command: The complete compilation command line, including compiler name, options, and parameters.
[0128] file: The path of the compiled source code file.
[0129] Assume that this example is a C++ project located in the / home / user / my_project / directory. The project contains two source files, main.cpp and utils.cpp, and uses external libraries. Therefore, an additional header file path -I / opt / include needs to be specified. The g++ compiler is also specified. This information is recorded in compile_config.json. Based on this information in compile_config.json, compile_commands.json with the following content is generated:
[0130]
[0131] In the compile_commands.json file above, for the main.cpp file, `directory` is ` / home / user / my_project`, representing the compile working directory. `command` contains the complete `g++` compiler call, specifying `-I / opt / include` to include the external library header files and compile `main.cpp` into the target file `main.o`. `file` points to the relative path to the source file `main.cpp`. Similarly, `utils.cpp` follows the same structure and will not be repeated here.
[0132] Second embodiment:
[0133] Based on the first embodiment above, after generating the compilation database in step S305, step S306 may be further executed;
[0134] S306 , the builder tool also calls the corresponding compiler in the compiler path according to the project configuration file, and performs a compilation process on each source file according to the compilation parameters corresponding to each source file to generate an executable binary file.
[0135] It should be noted that the flowchart of the second embodiment is based on the flowchart of the first embodiment, with the addition of step S306, which is not shown in the drawings.
[0136] To summarize the above two embodiments, the compilation management tool can generate a compilation database based on the project configuration file and directly drive the compilation process of the source file without relying on or using other additional build systems or tools to complete it, thereby realizing unified management of build information and compilation behavior.
[0137] The present application also provides a device for generating a compilation database. Figure 4 As shown, including:
[0138] A creation unit 401 is used to create a project configuration file, wherein the project configuration file includes a compiler path, compilation parameters, and a source file list;
[0139] The parsing unit 402 is used to parse the project configuration file through a compilation management tool to obtain a list of source files to be compiled, compilation parameters corresponding to each source file, and a compiler path;
[0140] The generation unit 403 is used to generate a compilation database based on the source file list and corresponding compilation parameters and compiler path through the compilation management tool for use by the static scanning tool, wherein the compilation database records the compilation command line and source file path corresponding to each source file, and the compilation command line is composed of at least the compiler path, compilation parameters and the name of the source file to be compiled.
[0141] The present application also provides an integrated development environment. Figure 5 As shown, including:
[0142] The project management module 501 is used to create a project, wherein the project creation includes creating a project configuration file, wherein the project configuration file includes a compiler path, compilation parameters, and a source file list;
[0143] The code editing module 502 is used to implement the writing of source file codes;
[0144] A compilation management tool 503 is configured to generate a compilation database based on the source file list and corresponding compilation parameters and compiler path, and to call the corresponding compiler under the compiler path to execute a compilation process on each source file according to the compilation parameters corresponding to each source file to generate an executable binary file; wherein the compilation database records the compilation command line and source file path corresponding to each source file, and the compilation command line is composed of at least the compiler path, compilation parameters, and the name of the source file to be compiled;
[0145] The static scanning tool 504 is used to provide auxiliary functions for code writing according to the compilation database, wherein the auxiliary functions include code completion, code navigation or code error diagnosis during the writing process of the source file code.
[0146] In some embodiments, the compilation management tool is integrated into the integrated development environment in a plug-in manner.
[0147] Figure 6 600 is a structural diagram of a computing device 600 provided in an embodiment of the present application. The computing device executes the above method, such as Figure 6 As shown, the computing device 600 includes: a processor 610 , a memory 620 , and a communication interface 630 .
[0148] It should be understood that Figure 6 The communication interface 630 in the computing device 600 shown may be used to communicate with other devices, and may specifically include one or more transceiver circuits or interface circuits.
[0149] The processor 610 may be connected to a memory 620. The memory 620 may be used to store the program code and data. Therefore, the memory 620 may be a storage unit within the processor 610, an external storage unit independent of the processor 610, or a component including both a storage unit within the processor 610 and an external storage unit independent of the processor 610.
[0150] Optionally, the computing device 600 may further include a bus. The memory 620 and the communication interface 630 may be connected to the processor 610 via the bus. The bus may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 A line without an arrow is used to represent the bus, but this does not mean that there is only one bus or one type of bus.
[0151] It should be understood that in the embodiment of the present application, the processor 610 can adopt a central processing unit (CPU). The processor can also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. Alternatively, the processor 610 adopts one or more integrated circuits to execute relevant programs to implement the technical solutions provided in the embodiment of the present application.
[0152] The memory 620 may include a read-only memory and a random access memory, and provides instructions and data to the processor 610. A portion of the processor 610 may also include a non-volatile random access memory. For example, the processor 610 may also store information about the device type.
[0153] When the computing device 600 is running, the processor 610 executes the computer-executable instructions in the memory 620 to perform any operation step of the above method and any optional embodiment thereof.
[0154] It should be understood that the computing device 600 according to the embodiment of the present application can correspond to the corresponding subject in executing the method according to each embodiment of the present application, and the above-mentioned and other operations and / or functions of each module in the computing device 600 are respectively for implementing the corresponding processes of each method of the present embodiment. For the sake of brevity, they will not be repeated here.
[0155] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0156] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0157] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0158] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0159] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0160] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0161] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the program is used to execute the above method, which includes at least one of the solutions described in the above embodiments.
[0162] The computer storage medium of the embodiment of the present application can adopt any combination of one or more computer-readable media.Computer-readable media can be computer-readable signal media or computer-readable storage media.Computer-readable storage media can be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or components, or any combination thereof.More specific examples (non-exhaustive list) of computer-readable storage media include: electrical connection with one or more wires, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination thereof.In this document, computer-readable storage media can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0163] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0164] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0165] The computer program code for performing the operations of the present application can be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0166] In addition, the words "first, second, third, etc." or module A, module B, module C and other similar terms in the specification and claims are only used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that the specific order or sequence can be interchanged where permitted so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0167] In the above description, the numbers representing the steps, such as S110, S120, etc., do not necessarily mean that the steps must be executed in this manner. If permitted, the order of the steps can be interchanged or they can be executed simultaneously.
[0168] The term "comprising" as used in the specification and claims should not be construed as limiting to what is listed thereafter; it does not exclude other elements or steps. Thus, it should be interpreted as specifying the presence of the features, integers, steps, or components mentioned, but not excluding the presence or addition of one or more other features, integers, steps, or components, or groups thereof. Thus, the expression "a device comprising means A and B" should not be limited to a device consisting solely of components A and B.
[0169] References in this specification to "one embodiment" or "an embodiment" mean that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the present application. Therefore, the phrases "in one embodiment" or "in an embodiment" appearing throughout this specification do not necessarily refer to the same embodiment, but may refer to the same embodiment. Furthermore, in one or more embodiments, the particular features, structures, or characteristics can be combined in any suitable manner, as would be apparent to one of ordinary skill in the art from this disclosure.
[0170] Note that the above are only preferred embodiments of the present application and the technical principles employed. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application has been described in more detail through the above embodiments, the present application is not limited to the above embodiments and may include many other equivalent embodiments without departing from the scope of protection of the present application, all of which fall within the scope of protection of the present application.
Claims
1. A method for generating a compilation database, characterized in that: include: Create a project configuration file, which includes a compiler path, compilation parameters, and a source file list; Parsing the project configuration file through a compilation management tool to obtain a list of source files to be compiled, compilation parameters corresponding to each source file, and a compiler path; The compilation management tool generates a compilation database based on the source file list and the corresponding compilation parameters and compiler path for use by the static scanning tool, wherein the compilation database records the compilation command line and source file path corresponding to each source file, and the compilation command line is composed of at least the compiler path, compilation parameters and the name of the source file to be compiled.
2. The method according to claim 1, characterized in that The compilation database is an array in JSON format, where the compilation information of each source file is represented by each array {director, command, file}. Among them, the directory represents the working directory where the compilation command is executed; the command represents the compilation command line, which is composed of at least the compiler path, compilation parameters and the name of the source file to be compiled; and the file represents the path of the source file to be compiled relative to the directory path.
3. The method according to claim 1, characterized in that The step of creating a project configuration file includes: When creating a new project in an integrated development environment, initialize a project configuration file in the project root directory; or, for an existing project imported from outside, copy a project configuration file template to the project root directory; Use the graphical interface or manually edit the file to modify the contents of the initialized project configuration file or the copied project configuration file.
4. The method according to claim 1, wherein Also includes: The compilation management tool also calls the corresponding compiler under the compiler path according to the project configuration file, executes the compilation process on each source file according to the compilation parameters corresponding to each source file, and generates an executable binary file.
5. The method according to claim 1, wherein The compilation management tool is implemented using the Rust language.
6. A device for generating a compilation database, characterized in that: include: A creation unit, configured to create a project configuration file, wherein the project configuration file includes a compiler path, compilation parameters, and a source file list; A parsing unit, configured to parse the project configuration file through a compilation management tool to obtain a list of source files to be compiled, compilation parameters corresponding to each source file, and a compiler path; A generation unit is configured to generate a compilation database based on the source file list and corresponding compilation parameters and compiler path through the compilation management tool for use by the static scanning tool, wherein the compilation database records the compilation command line and source file path corresponding to each source file, and the compilation command line is composed of at least the compiler path, compilation parameters, and the name of the source file to be compiled.
7. An integrated development environment, characterized in that: include: A project management module is used to create a project, wherein the project creation includes creating a project configuration file, wherein the project configuration file includes a compiler path, compilation parameters, and a source file list; Code editing module, used to implement the writing of source file code; A compilation management tool, configured to generate a compilation database based on the source file list and corresponding compilation parameters and compiler path, and to call the corresponding compiler under the compiler path to execute a compilation process on each source file according to the compilation parameters corresponding to each source file, thereby generating an executable binary file; wherein the compilation database records the compilation command line and source file path corresponding to each source file, and the compilation command line is composed of at least the compiler path, compilation parameters, and the name of the source file to be compiled; A static scanning tool is used to provide auxiliary functions for code writing based on the compilation database, wherein the auxiliary functions include code completion, code navigation or code error diagnosis during the writing process of the source file code.
8. The integrated development environment according to claim 7, wherein: The compilation management tool is integrated into the integrated development environment in a plug-in manner.
9. A computing device, characterized in that include: processor, and A memory having program instructions stored thereon, wherein when the program instructions are executed by the processor, the processor is caused to perform the method according to any one of claims 1 to 5.
10. A storage medium, characterized in that: Program instructions are stored thereon, and when the program instructions are executed by a computer, the computer is caused to execute the method according to any one of claims 1 to 5.