Project file indexing method and device, storage medium and computer equipment
By compiling the target project to generate dependency files and symbol indexes, it solves the problem of redundant index results of traditional code search tools in large software projects, enables rapid search and location of source code files, and improves index accuracy.
Patent Information
- Application Number
- CN202410865096.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-18
AI Technical Summary
Traditional code search tools encounter difficulties in large and complex software projects, especially when supporting multiple hardware platforms and parallel projects. The same file name or identifier results in redundant index results, requiring developers to manually determine the target file.
By compiling the target project to generate dependency files, determine the source code files that the intermediate target files depend on, generate a project code list based on relative paths, perform file deduplication, and generate symbol indexes to improve index accuracy.
It realizes quick search and location of source code files, reduces the time of manual search and distinguishing files with the same name, and improves the accuracy of index results.
Smart Images

Figure CN118796767A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a project file indexing method, device, storage medium and computer equipment. Background Art
[0002] In contemporary large-scale software projects, the amount of code often exceeds billions of lines, and the number of files involved is huge, even exceeding millions, so code search and browsing tools become essential. These tools can understand multiple programming languages and version control systems, helping developers to easily find code, definitions, functions, variables, etc., and compare between different versions.
[0003] However, for large and complex projects, especially those that support multiple hardware platforms and multiple parallel projects, traditional code search tools may encounter some limitations. Specifically, different projects may use the same file name or identifier. Even in the same project, there may be a large number of functions and variables with the same name because the projects support different hardware platforms. Traditional source code file retrieval methods usually only provide text-based keyword search functions, resulting in a large number of source code files being indexed, requiring R&D personnel to further determine the target files. Summary of the invention
[0004] The purpose of this application is to solve at least one of the above-mentioned technical defects, especially the technical defect that the prior art only provides a text-based keyword search function, resulting in a large number of source code files indexed, requiring R&D personnel to further determine the target file.
[0005] The present application provides a project file indexing method, the method comprising:
[0006] Obtain a target project to be indexed, and compile the target project to generate a dependent file corresponding to each intermediate target file in the target project;
[0007] Determine the source code file that each intermediate target file depends on based on each dependent file, and generate a project code list based on the relative path of each source code file;
[0008] De-duplicate the project code list to obtain a project index directory, and generate a symbol index for the project index directory;
[0009] File indexing is performed from a software code repository using the symbol index to obtain a source code file corresponding to the target project.
[0010] Optionally, compiling the target project to generate a dependency file corresponding to each intermediate target file in the target project includes:
[0011] Compiling the target project using a build system to generate a compilation file; the compilation file records the dependency relationship between the intermediate target files in the target project;
[0012] Relationship analysis is performed on the compiled files to generate dependent files corresponding to each intermediate target file.
[0013] Optionally, performing relationship parsing on the compiled file to generate a dependency file corresponding to each intermediate target file includes:
[0014] Construct an empty dictionary for each intermediate object file;
[0015] Traversing the compiled file, reading the source file and resource file of each intermediate target file, and determining the header file of each intermediate target file through the compiler;
[0016] For each intermediate target file, a mapping relationship between the intermediate target file and the source file, resource file and header file is created, and each mapping relationship is written into a corresponding empty dictionary to form a dependent file.
[0017] Optionally, determining the source code file that each intermediate target file depends on based on each dependent file includes:
[0018] For each dependent file, determine each file name in the dependent file, and determine the file path and extension corresponding to the file name based on the target project;
[0019] The relative path of each file name is determined based on the file path and the extension, and the source code file that the intermediate target file depends on is obtained based on each relative path.
[0020] Optionally, the project code list is deduplicated to obtain a project index directory, including:
[0021] The project code list is deduplicated through a collection structure to obtain a project list collection, and each source code file in the project list collection is copied to a preset empty directory according to the initial result of the project code list to form a project index directory.
[0022] Optionally, generating the symbol index of the project index directory includes:
[0023] Determine the code type and index position of the target project, and create a configuration file of the project index directory based on the code type and the index position;
[0024] The configuration file is run to store each source code file in the project index directory to the index location and generate a symbol index.
[0025] Optionally, the method further comprises:
[0026] A scheduled task is constructed, and the symbol index of the target project is regularly updated based on the scheduled task.
[0027] The present application also provides a project file indexing device, comprising:
[0028] A project compilation module is used to obtain a target project to be indexed, compile the target project, and generate a dependency file corresponding to each intermediate target file in the target project;
[0029] A list generation module, used to determine the source code files that each intermediate target file depends on based on each dependent file, and generate a project code list based on the relative path of each source code file;
[0030] An index generation module, used to perform file deduplication on the project code list, generate a project index directory, and determine a symbol index of the project index directory;
[0031] The file indexing module is used to perform file indexing from the software code repository using the symbol index to obtain a source code file corresponding to the target project.
[0032] The present application also provides a storage medium, in which computer-readable instructions are stored. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the project file indexing method described in any of the above embodiments.
[0033] The present application also provides a computer device, comprising: one or more processors, and a memory;
[0034] The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the steps of the project file indexing method described in any one of the above embodiments are performed.
[0035] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0036] The project file indexing method, device, storage medium and computer equipment provided by the present application, when the user needs to index the relevant files in the project, can first obtain the target project to be indexed, and then compile the project to generate the dependency files corresponding to each intermediate target file in the target project, where the dependency files record the dependency relationship between each file, so the source code file that each intermediate target file depends on can be determined based on each dependency file, and the project code list can be generated based on the relative path of each source code file, so that it can be quickly searched and located when the file is indexed; then the project code list can be deduplicated to obtain the project index directory, and the accuracy of the index result can be improved by filtering out the files that do not participate in the operation; finally, the symbol index of the project index directory is generated as the unique identifier of the target project index, so that the file index corresponding to the target project can be obtained by using the symbol index to perform file indexing from the software code warehouse. The present application filters out the files that do not participate in the operation through the dependency files generated by the compilation of the target project, and then generates the symbol index of the target project, so that the files obtained by this index are highly accurate, reducing the time of manual search and distinguishing files with the same name. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0038] Figure 1 A flowchart of a project file indexing method provided in an embodiment of the present application;
[0039] Figure 2 A flowchart of a dependency file generation process provided in an embodiment of the present application;
[0040] Figure 3 A schematic diagram of the structure of a project file indexing device provided in an embodiment of the present application;
[0041] Figure 4 A schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0042] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0043] For large and complex projects, especially those that support multiple hardware platforms and multiple parallel projects, traditional code search tools may encounter some limitations. Specifically, different projects may use the same file name or identifier. Even in the same project, there may be a large number of functions and variables with the same name because the project supports different hardware platforms. Traditional source code file retrieval methods usually only provide text-based keyword search functions, resulting in a large number of source code files being indexed, requiring R&D personnel to further identify the target files.
[0044] Based on this, this application proposes the following technical solutions, see below for details:
[0045] In one embodiment, Figure 1 As shown, Figure 1 A schematic diagram of a process flow of a project file indexing method provided in an embodiment of the present application; the present application provides a project file indexing method, which specifically includes the following:
[0046] S110: Obtain a target project to be indexed, compile the target project, and generate a dependent file corresponding to each intermediate target file in the target project.
[0047] In this embodiment, when the user needs to index related source code files in a project, the computer device can first obtain the file data of the project to form a target project, and then compile the target project to generate dependent files corresponding to each intermediate target file in the target project. In this way, the computer device can quickly search and locate through the dependent files when indexing files later.
[0048] The target project refers to a complete software development project, which contains a set of source files, header files, resource files and other related source code files used to create the final software product. In this application, the target project can refer to the object used for analysis and indexing, and the source code files obtained by indexing belong to the target project. The target project here can be a parallel project containing multiple sub-projects, or it can be one of the sub-projects under the parallel project, which is not limited here.
[0049] In addition, the intermediate target file refers to the machine code or bytecode file generated by the compiler after compiling the source code. It has a specific file extension, such as .o, .obj, etc. These files contain the binary representation of the source code, making the code of the target project modular, and each module can be compiled and tested independently, thereby improving the compilation efficiency. The dependency file records the dependency relationship between each source code file, that is, which source code files are used to compile the corresponding intermediate target file. The dependency relationship here can be direct or indirect.
[0050] Specifically, when the user determines the project that needs to be indexed, the computer device can obtain the target project by cloning the Git repository or downloading the project code, and then use the corresponding compiler to compile the target project under the directory structure of the target project to generate multiple intermediate target files. During the compilation process, the compiler can perform operations such as lexical analysis, syntax analysis, semantic analysis, intermediate code generation and code optimization, and compile each source code file into assembly code or machine code to form an intermediate target file; in addition, during this process, the computer device can also generate dependency files corresponding to each intermediate target file. These dependency files usually contain rules for identifying which files are intermediate target files, which files are source code files, and the dependency relationship between them. The extension is usually .d.
[0051] S120: Determine the source code file that each intermediate target file depends on based on each dependent file, and generate a project code list based on the relative path of each source code file.
[0052] In this embodiment, after obtaining the dependent files corresponding to each intermediate target file through step S110, the computer device can also determine the source code files that each intermediate file depends on based on each dependent file, and then generate a project code list based on the relative path of each source code file to filter out source code files that are not related to the target project.
[0053] It can be understood that a relative path refers to the path of a file or directory relative to the current working directory or a certain base directory. It usually does not contain the complete directory from the root directory of the file system to the corresponding source code file. Instead, it only contains the path components required to get from the current location or base location to the target location. Therefore, the project code list formed does not depend on a specific file system structure or root directory. Even if the target project is moved or copied to a new location, the project code list reference usually does not need to be updated, thereby reducing the risk of configuration errors.
[0054] Specifically, since the dependency files are usually in text format, the computer device can use a script or program to parse each dependency file, first determine which source code files each intermediate target file is compiled from, and then determine the file paths of these source code files, where the file paths can be relative paths or absolute paths. If it is an absolute path, the computer device can convert it into a relative path relative to the root directory of the target project, so that the project code list can be generated based on the relative paths of each source code file.
[0055] S130: De-duplicate files in the project code list to obtain a project index directory, and generate a symbol index for the project index directory.
[0056] In this embodiment, after generating the project code list through step S120, the computer device can deduplicate the files of the project code list and generate a project index directory to filter out the source code files that are repeatedly referenced and depended on in the target project; finally, the computer device can generate a symbol index of the project index directory to obtain a unique identifier of the target project index.
[0057] The symbol index refers to the result of indexing the symbols used to define the target project in project management, such as variables, functions, classes, etc. Through the symbol index, the computer device can quickly find and locate the location of the source code file in the target project, thereby improving the accuracy of the index result.
[0058] It is understandable that due to the need to support different hardware platforms, such as X86, ARM, MIPS, RISC-V, etc., there may be a large number of functions and variables with the same name in the target project. For example, in the hardware abstraction layer (HAL) of Linux, in order to be compatible with various CPUs, each CPU needs to implement functions with the same name, which results in a large number of results being returned when indexing a specific function or variable. Therefore, after generating the project code list, this application can also perform file deduplication on the project code list to improve the accuracy of subsequent file indexing.
[0059] S140: Using the symbol index to perform file indexing from the software code repository, and obtaining a source code file corresponding to the target project.
[0060] In this embodiment, after obtaining the symbol index of the target project through step S130, the computer device can use the symbol index to perform file indexing from the software code repository to obtain the source code file corresponding to the target project. The source code file obtained by this index has high accuracy, reducing the time for manual searching and distinguishing files with the same name.
[0061] Among them, the software code repository refers to a centralized or distributed system used to store, manage and maintain source code in software development. It allows multiple people to collaborate and stores source code files of multiple projects, resulting in the possibility that the software code repository may store files with the same name for multiple projects. Therefore, this application can use symbolic indexes to perform file indexing to obtain the source code file corresponding to the target project.
[0062] Furthermore, when the user only uses the symbol index to index files from the software code repository, all source code files in the corresponding target project can be obtained; if the user needs to index the target file in the target project, the user can first determine the file name of the target file and other related symbols, and then perform file indexing through the symbol index combined with the file name, so that the target file in the target project can be directly indexed, greatly reducing the time for users to distinguish files with the same name.
[0063] In the above embodiment, when the user needs to index the relevant files in the project, the target project to be indexed can be obtained first, and then the project can be compiled to generate the dependency files corresponding to each intermediate target file in the target project. The dependency files here record the dependency relationship between each file, so the source code file that each intermediate target file depends on can be determined based on each dependency file, and the project code list can be generated based on the relative path of each source code file, so that it can be quickly searched and located when the file is indexed; then the project code list can be deduplicated to obtain the project index directory, and the accuracy of the index result can be improved by filtering out the files that do not participate in the operation; finally, the symbol index of the project index directory is generated as the unique identifier of the target project index, so that the file index corresponding to the target project can be obtained by using the symbol index to perform file indexing from the software code warehouse. The present application filters out the files that do not participate in the operation through the dependency files generated by the compilation of the target project, and then generates the symbol index of the target project. The files obtained by this index are highly accurate, which reduces the time of manual search and distinction of files with the same name.
[0064] In one embodiment, the target project is compiled in step S110 to generate a dependency file corresponding to each intermediate target file in the target project, which may include:
[0065] S111: Use the build system to compile the target project and generate a compilation file.
[0066] S112: Perform relationship analysis on the compiled files to generate dependent files corresponding to each intermediate target file.
[0067] In this embodiment, when the computer compiles the target project, it can use the build system to compile the target project and generate a compiled file. Then, it can perform relationship analysis on the compiled file to generate a dependency file corresponding to each intermediate target file; wherein the compiled file records the dependency relationship between each intermediate target file in the target project.
[0068] It is understood that a build system refers to an automated tool used to generate user-usable targets from source code, which may include the Ninja build system, the CMake build system, etc. Among them, since the Ninja build system is a small, speed-focused build system, which is usually used to handle large projects to reduce build time, the compilation process of this application can use the Ninja build system, and the compiled Ninja file is a configuration file of the Ninja build system, which defines the rules and dependencies of each step in the build process, and its extension is usually .ninja or .ninja.d.
[0069] Specifically, the build system can generate compilation files based on other build tools, such as CMake, GYP, GN, etc. These build tools can analyze the source code, header files, resource files and other files in the target project to determine the compilation rules, dependencies of source files, header files and intermediate target files, and generate configuration files that the build system can understand.
[0070] Furthermore, the compilation file may include rules, framework statements, and variables. Among them, the rules define how to generate intermediate target files from source code files, each rule has a unique name, and specifies the commands and dependencies required to generate intermediate target files; the build statement specifies the intermediate target files to be built, and the rules used to build these files, and each build statement references a rule; and variables can be used to store commonly used paths, file names, or flags to reference other parts of the file. Therefore, in the process of building and generating a compilation file, the present application can obtain the dependency relationship of each intermediate target file, and by parsing the dependency relationship of these files, the dependent files corresponding to each intermediate target file can be obtained.
[0071] In one embodiment, Figure 2 As shown, Figure 2 A flowchart of a dependency file generation process provided in an embodiment of the present application; Figure 2 In step S112, the relationship between the compiled files is parsed to generate the dependent files corresponding to each intermediate target file, which may include:
[0072] S1121: Build an empty dictionary for each intermediate target file.
[0073] S1122: traverse the compilation file, read the source file and resource file of each intermediate target file, and determine the header file of each intermediate target file through the compiler.
[0074] S1123: For each intermediate target file, create a mapping relationship between the intermediate target file and the source file, resource file and header file, and write each mapping relationship into a corresponding empty dictionary to form a dependent file.
[0075] In one embodiment, when parsing a compiled file, the computer device may first construct an empty dictionary for each intermediate target file, then traverse the compiled file, read the source file and resource file of each intermediate target file, and determine the header file of each intermediate target file through the compiler. Finally, for each intermediate target file, the computer device may create a mapping relationship between the intermediate target file and the source file, resource file, and header file, and write each mapping relationship into a corresponding empty dictionary to form a dependency file.
[0076] Among them, the source code files of the target project can include source files, resource files and header files. To elaborate, source files refer to program code files that implement software functions, which contain all the logic, algorithms and data structures required to implement the software. They are usually written in a specific programming language, such as C, C++, Java, Python, etc., and have file extensions specific to the language, such as .c, .cpp, .java, .py, etc.; resource files are used to improve support and auxiliary functions when the software is running, and can contain various non-code resources required for program operation, such as pictures, audio, video, translation strings, user interface layouts, etc., and their extensions can be .json, .xml, .yaml, .ini, etc.; header files implement code modularization, so that different source files can share the same declarations and definitions, and contain declarations, definitions, constants, variables, function prototypes, etc. in the program, and their extensions can be .h, .hpp, .hxx, etc.
[0077] It is understandable that during the compilation of the compiled file, since the source file directly contains the program logic, it can be directly traversed and parsed through the compiled file, while the resource file usually does not directly participate in the compilation process, and it can be directly copied or embedded in the compiled file, so it can also be directly traversed through the compiled file. However, the header file provides the required interface and declaration for the source file, so it does not need to be put into the compiled file, and the computer device cannot directly traverse the compiled file to obtain it. Based on this, the computer device can determine the header file of each intermediate target file through the compiler.
[0078] Specifically, the computer device can use a parser to parse the build statements in the compiled file, where each build statement usually defines a rule that describes how to generate an intermediate target file from a source code file. For each build statement, the computer device can directly extract the source files and resource files in the intermediate target file and the source code file. However, for compiled languages such as C / C++, the dependencies of the intermediate target file usually also include header files, so it is necessary to use a compiler such as GCC or Clang's dependency scanning function to generate its dependent header files. Finally, for the target project, the computer device can create a key-value pair set for it, where the key is the name of the intermediate target file and the value is a list of all dependent files.
[0079] For example, the computer device can create an empty dictionary of key-value pairs for the intermediate target file: all_targets; where key is a string, i.e., the name of the target, and value is a list containing all its dependencies. The computer device can then scan the compiled file named build.ninjia from top to bottom, and parse the target blocks at the beginning of each build. For example, in one of the target blocks called build obj / main.o:link src / main.c, a new key-value item can be parsed: all_targets[obj / main.o]=[src / main.c]. In this key-value pair, i.e., the dependent file, obj / main.o is the intermediate target file, and src / main.c is the source code file that the intermediate target file depends on.
[0080] In one embodiment, determining the source code file that each intermediate target file depends on based on each dependent file in step S120 may include:
[0081] S121: For each dependent file, determine each file name in the dependent file, and determine the file path and extension corresponding to the file name based on the target project.
[0082] S122: Determine the relative path of each file name based on the file path and the extension, and obtain the source code file that the intermediate target file depends on based on each relative path.
[0083] In this embodiment, when the computer device determines the source code files included in the dependent files, for each dependent file, the computer device can first determine the various file names contained in the dependent file, and determine the file path and extension corresponding to the file name based on the target project, and then determine the relative path of each file name based on the file path and extension, and obtain the source code file that the intermediate target file depends on based on each relative path.
[0084] It is understandable that the dependent file is formed by a key-value pair containing multiple file names, such as all_targets[obj / main.o]=[src / main.c], where src / main.c is the file name of the source code file. Based on this, the computer device can use string functions to extract the file path and extension in each file name. For example, in Python, the computer device can use os.path.split to split the file path and extension, and then use os.path.splitext to obtain the file path and extension, where the file path of src / main.c is src / and the extension is .c.
[0085] Furthermore, since each source code file is under the directory structure of the target project, the computer device can also parse each file name based on the directory structure of the target project, and determine whether the file path and extension in each file name conform to the directory structure of the target project, and when the file name conforms to the directory structure of the target project, determine the relative path of each file name based on the file path and extension, so that the computer device can obtain the source code file that the intermediate target file depends on based on each relative path, so as to improve the accuracy of file acquisition.
[0086] In one embodiment, in step S130, the project code list is deduplicated to obtain a project index directory, which may include:
[0087] S131: De-duplicate files in the project code list through the collection structure to obtain a project list collection, and copy each source code file in the project list collection to a preset empty directory according to the initial result of the project code list to form a project index directory.
[0088] In this embodiment, when the computer device deduplicates the project code list, it can use a set structure to deduplicate files in the project code list, that is, convert the project code list into a set format to obtain a deduplicated project list set. Then, the computer device can copy each source code file in the project list set to a preset empty directory according to the initial result of the project code list to form a project index directory to ensure that the order of each source code file in the project index directory is correct.
[0089] It is understandable that since sets do not allow duplicate elements, after the computer device converts the project code list into a set format, the project list set will automatically remove duplicate dependencies. However, the elements of the set are unordered, so after removing duplicates from the source code files, the computer device also needs to copy each source code file in the project list set to a preset empty directory in the order of the initial results of the project code list to maintain the original order of the project code list, thereby ensuring the efficiency and accuracy of subsequent file indexing.
[0090] In one embodiment, generating the symbol index of the project index directory in step S130 may include:
[0091] S132: Determine the code type and index location of the target project, and create a configuration file of the project index directory based on the code type and index location.
[0092] S133: Run the configuration file to store each source code file in the project index directory to the index location and generate a symbol index.
[0093] In this embodiment, when the present application generates a symbol index for a project index directory, the computer device may first determine the code type and index position of the target project, and create a configuration file for the project index directory based on the code type and index position. The computer device may then run the configuration file to store each source code file in the project index directory to the index position and generate a symbol index.
[0094] Specifically, the computer device can use the OpenGrok service to generate a symbol index for the project index directory. The computer device can first create an index location for the target project, that is, the storage directory of the source code files of the target project in the OpenGrok service, and determine the code type of the target project, that is, the programming language used to develop the target project. In this way, the computer device can create a configuration file for the project index directory based on the index location and the code type. At this time, after the computer device runs the configuration file in the OpenGrok service, the computer device can copy each source code file in the project index directory to the index location, and after the copying is completed, analyze each source code file in the storage location through the OpenGrok service, and then generate a symbol index based on the analysis results.
[0095] Furthermore, after generating the symbol index of the target project, if the user needs to index the relevant files in the target project, he can directly access the OpenGrok service and use the symbol index to browse and index the source code files in the target project. At this time, other files not related to the target project have been filtered out, thereby ensuring the targetedness of the index.
[0096] In one embodiment, the method may further include:
[0097] S150: Construct a scheduled task, and regularly update the symbol index of the target project based on the scheduled task.
[0098] In this embodiment, the computer device can also construct a scheduled task. Whenever the scheduled task is started, the computer device can update the symbol index of the target project. In this way, when the structural directory of the target project changes, its symbol index can be updated in time, thereby ensuring the accuracy of the file index.
[0099] The project file indexing device provided in an embodiment of the present application is described below. The project file indexing device described below and the project file indexing method described above can be referenced to each other.
[0100] In one embodiment, Figure 3 As shown, Figure 3 A schematic diagram of a project file indexing device provided in an embodiment of the present application; the present application also provides a project file indexing device, including a project compilation module 210, a list generation module 220, an index generation module 230 and a file indexing module 240, specifically including the following:
[0101] The project compilation module 210 is used to obtain the target project to be indexed, compile the target project, and generate a dependent file corresponding to each intermediate target file in the target project.
[0102] The list generation module 220 is used to determine the source code files that each intermediate target file depends on based on the various dependent files, and to generate a project code list based on the relative paths of the various source code files.
[0103] The index generation module 230 is used to perform file deduplication on the project code list, generate a project index directory, and determine the symbol index of the project index directory.
[0104] The file indexing module 240 is used to perform file indexing from the software code repository using the symbol index to obtain the source code file corresponding to the target project.
[0105] In the above embodiment, when the user needs to index the relevant files in the project, the target project to be indexed can be obtained first, and then the project can be compiled to generate the dependency files corresponding to each intermediate target file in the target project. The dependency files here record the dependency relationship between each file, so the source code file that each intermediate target file depends on can be determined based on each dependency file, and the project code list can be generated based on the relative path of each source code file, so that it can be quickly searched and located when the file is indexed; then the project code list can be deduplicated to obtain the project index directory, and the accuracy of the index result can be improved by filtering out the files that do not participate in the operation; finally, the symbol index of the project index directory is generated as the unique identifier of the target project index, so that the file index corresponding to the target project can be obtained by using the symbol index to perform file indexing from the software code warehouse. The present application filters out the files that do not participate in the operation through the dependency files generated by the compilation of the target project, and then generates the symbol index of the target project. The files obtained by this index are highly accurate, which reduces the time of manual search and distinction of files with the same name.
[0106] In one embodiment, the project compilation module 210 may include:
[0107] The compilation file generation submodule is used to compile the target project using the build system to generate a compilation file; the compilation file records the dependency relationship of each intermediate target file in the target project.
[0108] The dependency file generation submodule is used to parse the relationship between the compiled files and generate the dependency files corresponding to each intermediate target file.
[0109] In one embodiment, the dependency file generation submodule may include:
[0110] Dependency file building unit, used to build an empty dictionary for each intermediate target file.
[0111] The source code file reading unit is used to traverse the compilation file, read the source file and resource file of each intermediate target file, and determine the header file of each intermediate target file through the compiler.
[0112] The key-value pair writing unit is used to create a mapping relationship between each intermediate target file and the source file, resource file and header file, and write each mapping relationship into a corresponding empty dictionary.
[0113] In one embodiment, the list generation module 220 may include:
[0114] The data extraction submodule is used to determine, for each dependent file, each file name in the dependent file, and to determine the file path and extension corresponding to the file name based on the target project.
[0115] The source code file acquisition submodule is used to determine the relative path of each file name based on the file path and extension, and to acquire the source code file that the intermediate target file depends on based on each relative path.
[0116] In one embodiment, the index generation module 230 may include:
[0117] The source code file deduplication submodule is used to deduplicate files in the project code list through the collection structure to obtain a project list set, and copy each source code file in the project list set to a preset empty directory according to the initial result of the project code list to form a project index directory.
[0118] In one embodiment, the index generation module 230 may further include:
[0119] The configuration file configuration submodule is used to determine the code type and index location of the target project, and create a configuration file for the project index directory based on the code type and index location.
[0120] The symbol index generation submodule is used to run the configuration file to store each source code file in the project index directory to the index location and generate a symbol index.
[0121] In one embodiment, the apparatus may further include:
[0122] The symbol index updating module is used to construct a scheduled task and regularly update the symbol index of the target project based on the scheduled task.
[0123] In one embodiment, the present application further provides a storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the project file indexing method as described in any of the above embodiments.
[0124] In one embodiment, the present application also provides a computer device having computer-readable instructions stored therein. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the project file indexing method as described in any one of the above embodiments.
[0125] Indicatively, Figure 4 As shown, Figure 4 This is a schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. The computer device 300 may be provided as a server. Figure 4The computer device 300 includes a processing component 302, which further includes one or more processors, and a memory resource represented by a memory 301 for storing instructions executable by the processing component 302, such as an application. The application stored in the memory 301 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 302 is configured to execute instructions to perform the project file indexing method of any of the above embodiments.
[0126] The computer device 300 may further include a power supply component 303 configured to perform power management of the computer device 300, a wired or wireless network interface 304 configured to connect the computer device 300 to a network, and an input / output (I / O) interface 305. The computer device 300 may operate based on an operating system stored in the memory 301, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, Free BSD TM, or the like.
[0127] Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0128] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0129] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can refer to each other.
[0130] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A project file indexing method, characterized in that: The method comprises: Obtain a target project to be indexed, and compile the target project to generate a dependent file corresponding to each intermediate target file in the target project; Determine the source code file that each intermediate target file depends on based on each dependent file, and generate a project code list based on the relative path of each source code file; De-duplicate the project code list to obtain a project index directory, and generate a symbol index for the project index directory; File indexing is performed from a software code repository using the symbol index to obtain a source code file corresponding to the target project.
2. The project file indexing method according to claim 1, characterized in that: The compiling of the target project to generate a dependency file corresponding to each intermediate target file in the target project includes: Compiling the target project using a build system to generate a compilation file; the compilation file records the dependency relationship between the intermediate target files in the target project; Relationship analysis is performed on the compiled files to generate dependent files corresponding to each intermediate target file.
3. The project file indexing method according to claim 2, characterized in that: The performing relationship analysis on the compiled file to generate a dependency file corresponding to each intermediate target file includes: Construct an empty dictionary for each intermediate object file; Traversing the compiled file, reading the source file and resource file of each intermediate target file, and determining the header file of each intermediate target file through the compiler; For each intermediate target file, a mapping relationship between the intermediate target file and the source file, resource file and header file is created, and each mapping relationship is written into a corresponding empty dictionary to form a dependent file.
4. The project file indexing method according to claim 1, characterized in that: The step of determining the source code file that each intermediate target file depends on based on each dependent file includes: For each dependent file, determine each file name in the dependent file, and determine the file path and extension corresponding to the file name based on the target project; The relative path of each file name is determined based on the file path and the extension, and the source code file that the intermediate target file depends on is obtained based on each relative path.
5. The project file indexing method according to claim 1, characterized in that: Deduplication of the project code list is performed to obtain a project index directory, including: The project code list is deduplicated through a collection structure to obtain a project list collection, and each source code file in the project list collection is copied to a preset empty directory according to the initial result of the project code list to form a project index directory.
6. The project file indexing method according to claim 1, characterized in that: The generating of the symbol index of the project index directory comprises: Determine the code type and index position of the target project, and create a configuration file of the project index directory based on the code type and the index position; The configuration file is run to store each source code file in the project index directory to the index location and generate a symbol index.
7. The project file indexing method according to claim 1, characterized in that: The method further comprises: A scheduled task is constructed, and the symbol index of the target project is regularly updated based on the scheduled task.
8. A project file indexing device, characterized in that: include: A project compilation module is used to obtain a target project to be indexed, compile the target project, and generate a dependency file corresponding to each intermediate target file in the target project; A list generation module, used to determine the source code files that each intermediate target file depends on based on each dependent file, and generate a project code list based on the relative path of each source code file; An index generation module, used to perform file deduplication on the project code list, generate a project index directory, and determine a symbol index of the project index directory; The file indexing module is used to perform file indexing from the software code repository using the symbol index to obtain a source code file corresponding to the target project.
9. A storage medium, characterized in that: The storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the project file indexing method as described in any one of claims 1 to 7.
10. A computer device, characterized in that: include: one or more processors, and memory; The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the steps of the project file indexing method according to any one of claims 1 to 7 are performed.
Citation Information
Cited By
Code map construction method and device, electronic equipment and computer storage medium
CN119149757A
Construction method and equipment of C + + code knowledge base and medium
CN119918641A
Animation file processing method and system
CN120689471A
Compilation method, compilation system and apparatus
WO2026194581A1
