A method for determining a compilation directory, a computer device and a storage medium

By automatically identifying the programming language and storage paths and determining the compiled directory, the problem of artificially determining the efficiency and accuracy of the compiled directory in the prior art is solved, and the success rate of the compiled command is improved.

CN114296738BActive Publication Date: 2025-04-15SUZHOU DAJIAYING INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111625768.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-28
Publication Date
2025-04-15
Estimated Expiration
2041-12-28

AI Technical Summary

Technical Problem

In the prior art, the way of artificially determining the compiled directory leads to loss of time and labor costs, and it is easy to introduce subjective errors, reducing the success rate of the execution of the compiled command.

Method used

通过获取原始目录中的数据结构定义文件,自动查找并识别编程语言描述文件,确定每个编程语言描述文件对应的编程语言类型,并根据存储路径和语言类型识别编译目录,确保同一编译目录中所有数据结构定义文件使用相同的编程语言。

Benefits of technology

It realizes automatic and accurate determination of the compilation directory, avoids time and cost loss in the process of artificial determination, reduces the occurrence of subjective errors, and improves the execution success rate of compilation commands.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114296738B_ABST
    Figure CN114296738B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a method for determining a compilation directory, a computer device and a storage medium, the method comprising: obtaining an original directory; the original directory includes at least one data structure definition file, the data structure definition file is used to compile under a set programming language to obtain a compilation result; searching for programming language description files in the original directory, obtaining all programming language description files included in the original directory, and determining the programming language type corresponding to each programming language description file; identifying the compilation directory in the original directory according to the storage path and programming language type corresponding to each programming language description file, wherein the same compilation directory includes at least one data structure definition file for compiling under the same programming language. The method provides a new way to automatically and accurately determine the compilation directory corresponding to the same project or the same microservice, and improves the execution success rate of the compilation command.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to computer communication technology, and in particular to a method for determining a compilation directory, a computer device, and a storage medium. Background Art

[0002] In computer communication, in application scenarios such as network communication and general data exchange, the method of serializing structured data is often used to achieve data transmission. For example, when A sends target data to B, before A sends the structured target data, it can generate serialized data through the data serialization method and send the serialized data to B. When B receives the serialized data, it deserializes it to obtain the target data sent by A.

[0003] In order to realize the transmission of serialized structured data, the prior art needs to first manually determine the compilation directory corresponding to a project or microservice, and then, according to the type of programming language used to develop the project or microservice, define files for all data structures under the above compilation directory, and manually construct matching compilation commands to form matching compilation results.

[0004] However, manually determining the compilation directory will not only lead to the loss of time and labor costs, but also, if the compilation directory is not properly selected, it is easy to introduce subjective errors when constructing the compilation command later, which will lead to a low success rate of executing the compilation command. For example, if two microservices developed in different programming languages ​​are manually divided into a compilation directory, the developer may mistakenly construct compilation commands for each data structure definition file in the compilation directory according to one programming language type, which will cause the execution error of the compilation command of the data structure definition file corresponding to another programming language type. Summary of the invention

[0005] The embodiment of the present invention provides a method for determining a compilation directory, a computer device and a storage medium, so as to provide a new way to automatically and accurately determine the compilation directory and improve the execution success rate of the compilation command.

[0006] In a first aspect, an embodiment of the present invention provides a method for determining a compilation directory, the method comprising:

[0007] Acquire an original directory; the original directory includes at least one data structure definition file, and the data structure definition file is used to compile in a set programming language to obtain a compilation result;

[0008] Searching for programming language description files in the original directory, obtaining all programming language description files included in the original directory, and determining the programming language type corresponding to each programming language description file;

[0009] According to the storage path and programming language type corresponding to each programming language description file, a compilation directory is identified in the original directory, wherein the same compilation directory includes at least one data structure definition file for compiling in the same programming language.

[0010] In a second aspect, an embodiment of the present invention further provides a device for determining a compilation directory, the device comprising:

[0011] An original directory acquisition module is used to acquire an original directory; the original directory includes at least one data structure definition file, and the data structure definition file is used to compile in a set programming language to obtain a compilation result;

[0012] A programming language type determination module, used to search for programming language description files in the original directory, obtain all programming language description files included in the original directory, and determine the programming language type corresponding to each programming language description file;

[0013] The compilation directory identification module is used to identify the compilation directory in the original directory according to the storage path and programming language type corresponding to each programming language description file, wherein the compilation directory includes at least one data structure definition file for compiling under the same programming language.

[0014] In a third aspect, an embodiment of the present invention further provides a computer device, the device comprising:

[0015] one or more processors;

[0016] a storage device for storing one or more programs,

[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement a method for determining a compilation directory as described in any embodiment of the present invention.

[0018] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method for determining a compilation directory as described in any embodiment of the present invention.

[0019] The embodiment of the present invention obtains an original directory; the original directory includes at least one data structure definition file, and the data structure definition file is used to compile under a set programming language to obtain a compilation result; the programming language description file is searched in the original directory, all the programming language description files included in the original directory are obtained, and the programming language type corresponding to each programming language description file is determined; according to the storage path and programming language type corresponding to each programming language description file, a compilation directory is identified in the original directory, wherein the same compilation directory includes at least one data structure definition file for compiling under the same programming language. The technical solution of the embodiment of the present invention provides a new method for automatically and accurately determining the compilation directory corresponding to the same project or the same microservice, which completely avoids the loss of time and labor cost when manually determining the compilation directory. At the same time, it also completely avoids the subjective errors that are easily introduced when constructing compilation commands, and guarantees the execution success rate of compilation instructions to the greatest extent. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 A flowchart of a method for determining a compilation directory provided in Embodiment 1 of the present invention;

[0021] Figure 2a is a flowchart of a method for determining a compilation directory provided in Embodiment 2 of the present invention;

[0022] Figure 2b is a schematic diagram of a process for screening a first programming language description file provided by Embodiment 2 of the present invention;

[0023] Figure 3 is a flowchart of a method for determining a compilation directory provided in Embodiment 3 of the present invention;

[0024] Figure 4 It is a structural diagram of a device for determining a compilation directory provided by a fourth embodiment of the present invention;

[0025] Figure 5 A schematic diagram of the structure of a computer device provided in Embodiment 5 of the present invention. DETAILED DESCRIPTION

[0026] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0027] First, for the convenience of description below, the main inventive concepts of various embodiments of the present invention are briefly described.

[0028] Generally speaking, for one or more data structure definition files included in the same microservice, a compilation result corresponding to the same programming language type needs to be generated. Accordingly, a project folder corresponding to a microservice generally contains one or more programming language description files corresponding to the same programming language type.

[0029] The programming language description file refers to a file used to characterize the type of programming language used to develop a project or a microservice in the project. Generally speaking, when a developer generates a project or a microservice in a project using a set type of programming language, he or she will introduce (or automatically generate) files that match the programming language type in one or more folders under the project or microservice, that is, the programming language description file.

[0030] In addition, the inventors discovered through analyzing the project directory that in a project folder corresponding to a microservice, the storage path of the data structure definition file is generally located below the storage path of the programming language description file. Generally speaking, the programming language description file is located in the first-level subdirectory of the project folder.

[0031] In the prior art, developers manually determine the compilation directory corresponding to the project folder corresponding to the microservice, manually search for the programming language description file in the compilation directory, and determine the type of programming language used to develop the microservice based on the programming language description file. Then, based on the determined programming language type, compilation commands corresponding to each data structure definition file under the programming directory are generated. By executing each of the compilation commands, a matching compilation result can be obtained.

[0032] In the process of implementing the present invention, the inventors found that the entire process from manually determining the compilation directory to manually constructing the compilation command will not only cause a loss of time and labor costs, but also, if the compilation directory is improperly selected, it is easy to introduce subjective errors when constructing the compilation command later, thereby making the execution success rate of the compilation command low. At the same time, the above process is also difficult to find abnormal storage errors of some data structure definition files or programming language description files.

[0033] For example, an abnormal storage error occurs in the project folder of the same microservice, and the programming language description files corresponding to different programming language types. As mentioned above, the same microservice should be developed using the same programming language. Therefore, in the project folder of a microservice, there are and only programming language description files corresponding to the same programming language type. Therefore, once programming language description files corresponding to different programming language types appear, when the compilation command is used to compile the data structure definition files in the project folder of the microservice, the data structure definition files in the project folder of the microservice may not be compiled normally. Alternatively, after the executable file is generated for the project folder and uploaded to the server, errors such as the entire microservice cannot be called normally may occur;

[0034] Another example is an abnormal storage problem in which no data structure definition file is placed in the project folder of a microservice. In order to implement a remote procedure call for a microservice, it is necessary to generate matching compilation results for the data structure definition file defined in the microservice in advance. If the project folder does not include any data structure definition file, the interface for remote procedure call cannot be generated, and the entire microservice cannot be called normally.

[0035] Based on this, the inventor analyzed the causes of the above errors and found that there are two conditions that the compilation directory needs to meet: one is that the programming language type corresponding to the programming language description file included in the compilation directory is unique, and the other is that the compilation directory must include at least one data structure definition file. By using the above two conditions as the compilation directory identification conditions, the inventor creatively proposed a new method of automatically and accurately determining the compilation directory that meets the compilation directory identification conditions. Furthermore, after automatically determining the compilation directory, the compilation command corresponding to each data structure definition file can also be automatically generated according to the specific file content in the programming language description file under the compilation directory and each data structure definition file, which completely avoids the loss of time and labor costs when manually determining the compilation directory and constructing the compilation command. At the same time, it also completely avoids the subjective errors that are easily introduced when constructing the compilation command. In addition, multiple types of abnormal storage errors can be found, which guarantees the execution success rate of the compilation instruction to the greatest extent.

[0036] Embodiment 1

[0037] Figure 1This is a flow chart of a method for determining a compilation directory provided in the first embodiment of the present invention. This embodiment can be applied to the case where a compilation directory that meets the compilation requirements is automatically determined before a data structure definition file is compiled, so that the data structure definition file is automatically compiled under the compilation directory. The method can be executed by a compilation directory determination device, and specifically includes the following steps:

[0038] Step 110: Get the original directory.

[0039] The original directory includes at least one data structure definition file, and the data structure definition file is used to compile in a set programming language to obtain a compilation result.

[0040] In an embodiment of the present invention, the number of projects or items included in the original directory may be various. For example, the original directory may be an aggregated project directory containing multiple projects, or a single project directory containing only one project, or a lower subdirectory of the directory where one or more projects are located; or, it may be a lower subdirectory of the directory where one or more microservices under a project are located, etc.

[0041] As described above, in this embodiment, the user does not need to manually identify, and can automatically and accurately determine the compiled directory. After roughly locating a potential upper directory of the compiled directory, the upper directory can be determined as the original directory to achieve automatic identification of the compiled directory.

[0042] A project can be understood as an aggregated project that integrates one or more projects. Different projects are used to implement different independent functions, such as payment function, authentication function or identity verification function. Generally speaking, when a developer wants to write an application that integrates multiple functions, he or she can create a target project for the application, and then, by creating multiple projects in the target project, implement different microservice functions integrated in the application.

[0043] That is, for a project folder where a target project is located, it can contain project folders corresponding to one or more microservices. The project folder generally includes source code files for implementing microservice functions, data structure definition files, and various pictures, voice or video files, etc. Microservice can be understood as a functional implementation of a target project. Generally speaking, a microservice corresponds to a project folder in an aggregation project, and the project folder includes one or more data structure definition files. The above one or more data structure definition files are used to generate matching compilation results under the set programming language to enable other users or terminals to call the microservice.

[0044] The data structure definition file can be understood as a file defined when converting structured data or objects into a format that can be stored and transmitted (such as network transmission). The data structure definition file can be understood as a definition of the data format of a message transmitted in the network, that is, the data form of the message before serialization or after deserialization. The data structure definition file can be a ".proto" file, a ".json" file, or a ".xml" file, etc.

[0045] Each data structure definition file in the same target project can correspond to the same or different programming language types. Usually, the same microservice is implemented in the same programming language.

[0046] In the embodiment of the present invention, since the original directory is a directory roughly determined by the user, it can be a storage directory of a project folder in the target project, and thus, the data structure definition file under the original directory may correspond to one or more programming languages. In addition, in the actual application of project file management, since the source code files or folders in the project folders corresponding to different microservices or the project folders corresponding to different projects may have storage path setting errors, even if the original directory selected by the user is the storage directory of the project folder corresponding to a microservice in the target project, there may be programming language description files corresponding to multiple programming languages ​​in the original directory, so that the data structure definition file under the original directory may correspond to one or more programming languages.

[0047] Based on this, the embodiments of the present invention can automatically identify and determine the implementation method of the compilation directory according to the compilation directory identification conditions that the compilation directory needs to meet as described above, and can also discover abnormal errors in the above storage path.

[0048] In an embodiment of the present invention, the programming language may be go language, java language, C language, C++ language or Python language, etc. Exemplarily, when developing a project using go language, the project may be constructed using go language in the development process to implement one or more microservices under the project; if the microservice wants to be called by other users or terminals, a data structure definition file may be created to define the request format and response format when being called, etc.; further, when the microservice is called by a remote procedure call (RPC), a compilation result may be generated according to the data structure definition file, such as a "*.pb.go" file. Among them, the "*.pb.go" file is the result obtained by compiling with go language. After generating the "*.pb.go" file, you can package the go language project, data structure definition file and "*.pb.go" file and upload it to the operation and maintenance personnel, who will compile and package it to form an executable file (typically, a file in the form of *.exe), and upload the corresponding compilation and packaging results to the server for storage, so that other users or terminals can call one or more microservice remote procedures for the executable files in the compilation and packaging results.

[0049] Step 120: Search for programming language description files in the original directory, obtain all programming language description files included in the original directory, and determine the programming language type corresponding to each programming language description file.

[0050] Among them, the programming language description file refers to a file used to characterize the target project, or a certain microservice of the target project, using a certain type of programming language to develop the file. Generally speaking, when developers use a set type of programming language to generate a target project or a certain microservice in the target project, they must introduce (or automatically generate) files that match the programming language type in one or more folders under the target project or the microservice. Similarly, when generating a compilation command for the data structure definition file in the target project or the microservice, it is also necessary to add the above-mentioned programming language type as a compilation parameter to the compilation command.

[0051] By analyzing the project directory, the inventor discovered that by analyzing the various files included in the target project or a microservice in the target project by computer, the programming language description file can be automatically searched for, and then the corresponding programming language type can be automatically determined by analyzing the programming language description file (for example, the specific file content or the file suffix), and then an important compilation parameter in the compilation command can be obtained by automatic determination.

[0052] It can be understood that the embodiment of the present invention converts the files that appear in the project and are used to objectively reflect the type of programming language used to develop the project or microservice into files that are used to specify the type of programming language used when compiling the data structure definition file.

[0053] When using a compilation command to compile data structure definition file A, the compilation parameters included in the compilation command can be set. Furthermore, after specifying programming language type B by setting the compilation parameters, the compilation result based on programming language type B can be generated for the data structure definition file A by executing the compilation command.

[0054] Different programming language types use different compilation parameters in the compilation command. When the compilation command is executed, different compilation methods correspond to them, and thus the compilation results generated after the compilation is completed are also different.

[0055] As mentioned above, when a user needs to compile a data structure definition file in an original directory to obtain a matching compilation result, it is necessary to first manually determine one or more programming language types existing in the original directory, and then manually determine one or more compilation directories that meet the compilation directory identification conditions based on the one or more programming language types existing in the original directory. Under the manually determined compilation directory, matching compilation commands are generated for one or more data structure definition files, and in each compilation command, according to the programming language type corresponding to the compilation directory, the compilation parameters corresponding to the programming language type in the compilation command are set for compilation.

[0056] Based on this, the inventor creatively proposed to automatically determine the programming language type existing in the original directory, and automatically determine the compilation directory that meets the compilation directory identification conditions based on the programming language type existing in the original directory, so as to completely avoid the loss of time and manpower costs brought by manually determining the compilation directory.

[0057] Furthermore, under the compilation directory, matching compilation parameters can be automatically determined according to the programming language type corresponding to the compilation directory; based on the compilation parameters, a technical solution for automatically generating compilation commands for compilation can completely avoid the loss of time and labor costs caused by manually constructing compilation commands.

[0058] In an embodiment of the present invention, the original directory includes one or more programming language description files, and each programming language description file can only have a unique programming language type corresponding to it. Among them, multiple programming language description files can all correspond to the same programming language type, or one (or part) of the multiple programming language description files corresponds to a first programming language type, and another (or another part) of the multiple programming language description files corresponds to a second programming language type, or each programming language description file can correspond to a different programming language type.

[0059] The above-mentioned programming language description file can be used to describe what programming language each data structure definition file in the storage path corresponding to the programming language description file needs to use, and generate a matching compilation result. Accordingly, the programming language description file in the original directory can be searched, and the corresponding programming language type can be determined according to the programming language description file, and the storage path corresponding to the programming language description file can be determined according to the specific search situation.

[0060] Step 130: Identify the compilation directory in the original directory according to the storage path and programming language type corresponding to each programming language description file.

[0061] Among them, the same compilation directory includes at least one data structure definition file for compilation in the same programming language. The compilation directory can be understood as a directory that meets the compilation directory identification conditions, that is, all data structure definition files under the compilation directory are compiled using the same programming language; in other words, the compilation directory only contains one or more programming language description files corresponding to one programming language. The above-mentioned one programming language can be used as the programming language used when all data structure definition files under the compilation directory are compiled, so that the type of the programming language can be used to set the compilation parameters in the compilation command, and the data structure definition file is compiled in the compilation directory using the programming language, and then the compilation directory and programming language can be automatically determined without manual determination, while completely avoiding the loss of time and labor costs caused by manual determination of the compilation directory, while improving the execution success rate of the compilation command.

[0062] As mentioned above, each data structure definition file in the same compilation directory corresponds to the same programming language, that is, the programming language type corresponding to the programming language description file detected in the compilation directory is the programming language type corresponding to all the data structure definition files in the compilation directory. Furthermore, for at least one determined compilation directory, in combination with the programming language type, compilation commands corresponding to each data structure definition file in the compilation directory can be generated in batches, avoiding artificial generation of similar compilation commands for different data structure definition files multiple times, and completely avoiding subjective errors that are easily introduced when constructing compilation commands.

[0063] The technical solution of this embodiment is as follows: an original directory is obtained; the original directory includes at least one data structure definition file, and the data structure definition file is used to compile under a set programming language to obtain a compilation result; a programming language description file is searched in the original directory to obtain all programming language description files included in the original directory, and the programming language type corresponding to each programming language description file is determined; a compilation directory is identified in the original directory according to a storage path and a programming language type corresponding to each programming language description file, wherein the same compilation directory includes at least one data structure definition file for compiling under the same programming language, thereby completely avoiding the loss of time and labor costs caused by manually determining the compilation directory and constructing the compilation command, and at the same time, it also completely avoids the subjective errors that are easily introduced when constructing the compilation command. In addition, multiple types of abnormal storage errors can also be discovered, thereby ensuring the execution success rate of the compilation instruction to the greatest extent.

[0064] Embodiment 2

[0065] Figure 2a This is a flow chart of a method for determining a compilation directory provided in Embodiment 2 of the present invention. This embodiment is a further refinement of the above technical solution, and the technical solution in this embodiment can be combined with various optional solutions in one or more of the above embodiments.

[0066] Specifically, in an optional implementation of an embodiment of the present invention, a search for programming language description files is performed in the original directory to obtain all programming language description files included in the original directory, and the programming language type corresponding to each programming language description file is determined, including: traversing each file included in the original directory; matching the file name of each file obtained by the traversal with each programming language description file name in a programming language description file name set; determining a file whose file name matches the programming language description file name set as a programming language description file; and determining the programming language type corresponding to each programming language description file according to the programming language description file name matching each programming language description file and the mapping relationship between the programming language description file name and the programming language type.

[0067] In an optional implementation of the embodiment of the present invention, a compilation directory is identified in an original directory according to a storage path and a programming language type corresponding to each programming language description file, including: screening out a first programming language description file from all programming language description files according to the storage path and the programming language type corresponding to each programming language description file; wherein there is no same-level or dependency relationship between the storage paths corresponding to the first programming language description file and other programming language description files of different programming language types; screening out a programming language description file having a data structure definition file under the corresponding storage path from among each first programming language description file as a second programming language description file; and determining a compilation directory according to the storage directory corresponding to the second programming language description file.

[0068] like Figure 2a As shown, the method includes:

[0069] Step 210: Get the original directory.

[0070] The original directory includes at least one data structure definition file, and the data structure definition file is used to compile in a set programming language to obtain a compilation result.

[0071] Step 220: traverse each file included in the original directory.

[0072] Usually, in a project folder corresponding to a microservice, a programming language description file that reflects the programming language type is generally stored in the first-level subdirectory. However, as mentioned above, since the number of projects or projects contained in the original directory may correspond to multiple situations, it is impossible to accurately locate the specific location of the programming language description file in the original directory, or in which subdirectory it is located. Furthermore, it is necessary to traverse the files included in the original directory to locate the storage path where the programming language description file is located.

[0073] Step 230: Match the file names of the traversed files with the programming language description file name set.

[0074] Among them, the programming language description file name set can be a set composed of the file names of the programming language description files supported by the data structure definition file. Specifically, the data structure definition file can be a proto file. The proto file can support multiple languages ​​such as Go, Java, C++, Python, swift, etc. The programming language description file name set can be a set composed of programming language description file names such as "main.go", "go.sum", "go.mod", "main.py", "*init*.py", "*.swift", "*.Delegate.m", "*java" and "*.cpp". "*" can be a fuzzy symbol, such as "*init*.py" means a "py" file with "init" in the middle of the file name; and "*.java" means a "java" file of any file name.

[0075] Step 240: Determine the file whose file name matches the programming language description file name set as the programming language description file.

[0076] Specifically, it can be determined whether at least one of "main.go", "go.sum", "go.mod", "main.py", "*init*.py", "*.swift", "*.Delegate.m", "*java" or "*.cpp" exists in the file names of the obtained files. If yes, the matching files are selected as the programming language description files.

[0077] Step 250: Determine the programming language type corresponding to each programming language description file according to the programming language description file name that matches each programming language description file and the mapping relationship between the programming language description file name and the programming language type.

[0078] Among them, there is a mapping relationship between the programming language description file name and the target programming language type. For example, when the programming language description file name is "main.go", "go.sum" or "go.mod", the programming language type is go language. For another example, when the programming language description file name is "*java", the programming language type is java language. For another example, when the programming language description file name is "*.swift", the programming language type is swift language. For another example, when the programming language description file name is "*.Delegate.m", the programming language type is Object-C language. For another example, when the programming language description file name is "main.py" or "*init*.py", the programming language type is Python language. For another example, when the programming language description file name is "*.cpp", the programming language type is C++ language.

[0079] Step 260: Filter out the first programming language description file from all programming language description files according to the storage path and programming language type corresponding to each programming language description file.

[0080] There is no same-level or dependency relationship between the storage paths corresponding to the first programming language description file and other programming language description files of different programming language types.

[0081] Specifically, the existence of a peer relationship between storage paths can be understood as the first programming language description file and other programming language description files of different programming language types are located at the next level of the same storage path. For example, the storage path of the first programming language description file (such as corresponding to the go language) is "D: / git.woda.ink / jifanfei / go.sum", and the storage path of the above other programming language description files (such as corresponding to the Java language) is "D: / git.woda.ink / jifanfei / *.java". The first programming language description file and the above other programming language description files are both under the storage path "D: / git.woda.ink / jifanfei", and further, there is a peer relationship between the storage paths of the first programming language description file and the above other programming language description files.

[0082] Correspondingly, the dependency relationship between storage paths can be understood as the existence of a hierarchical relationship between the storage paths of the first programming language description file and other programming language description files corresponding to different programming language types, that is, the common part between the storage paths of the first programming language description file and other programming language description files corresponding to different programming language types (that is, the intersection of the two storage paths) is the same as the storage path of one of the programming language description files.

[0083] For example, the storage path of the first programming language description file is "D: / git.woda.ink / jifanfei / language1 / go.sum", and the storage path of the other programming language description files is "D: / git.woda.ink / jifanfei / language1". The common part of the storage paths corresponding to the first programming language description file and the other programming language description files is "D: / git.woda.ink / jifanfei / language1". The common part is the same as the storage path "D: / git.woda.ink / jifanfei / language1" of the other programming language description files. Therefore, there is a dependency relationship between the storage paths of the first programming language description file and the other programming language description files.

[0084] For another example, the storage path of the first programming language description file is “D: / git.woda.ink / jifanfei / language2”, and the storage path of the other programming language description files is “D: / git.woda.ink / jifanfei / language2 / go.mod”. The common part of the storage paths corresponding to the first programming language description file and the other programming language description files is “D: / git.woda.ink / jifanfei / language2”. The common part is the same as the storage path “D: / git.woda.ink / jifanfei / language2” of the first programming language description file. Therefore, there is a dependency relationship between the storage paths of the first programming language description file and the other programming language description files.

[0085] Figure 2b 1 is a schematic diagram of a process for screening a first programming language description file provided by Embodiment 2 of the present invention. Figure 2b As shown, in an optional implementation of an embodiment of the present invention, step 260: based on the storage path and programming language type corresponding to each programming language description file, screening out the first programming language description file from all programming language description files may include steps 261 to 268; or may include steps 261 to 269.

[0086] Step 261: Based on the original directory, determine the storage level corresponding to each storage path.

[0087] The storage hierarchy can be understood as the hierarchy formed by each subdirectory in the storage path. For example, if the storage path is "D: / git.woda.ink / jifanfei / go.sum", the storage hierarchy may include "D:", "D: / git.woda.ink", "D: / git.woda.ink / jifanfei" and "D: / git.woda.ink / jifanfei / go.sum".

[0088] Step 262: Obtain an unprocessed programming language description file as a current processing file in order from a high level to a low level of the storage hierarchy.

[0089] The closer a storage path is to the original directory, the higher the storage level of the storage path.

[0090] For example, if the original directory is "D:", the storage path of a programming language description file 1 is "D: / git.woda.ink / jifanfei", and the storage path of another programming language description file 2 is "D: / git.woda.ink / jifanfei / go.sum". Obviously, the storage path of programming language description file 1 is closer to the original directory, and the storage level of programming language description file 1 is higher than that of programming language description file 2.

[0091] In the embodiment of the present invention, in order to ensure the accuracy of determining the programming language type and the compilation directory, the programming language description file can be marked with a processing status. Initially, the processing status of all programming language description files can be defaulted to unprocessed.

[0092] It should be noted that determining the current processing file in the order from high to low levels of the storage hierarchy and thereby selecting the first programming language description file is only an optional implementation of the embodiment of the present invention. Under the conception of the present invention, there may also be other orders to determine the current processing file and then select the first programming language description file. For example, the current processing file may be determined in the order from the bottom to the top of the storage hierarchy, or the current processing file may be obtained randomly, etc. Different programming language description files may result in different ways of subsequently selecting the first programming language description file. The embodiments of the present invention are described in detail only by taking the order from the top to the bottom of the storage hierarchy to sequentially obtain an unprocessed programming language description file as the current processing file as an example.

[0093] Step 263: Obtain the current storage path of the currently processed file, use the storage paths corresponding to other unprocessed programming language description files as comparison storage paths, and detect whether the current storage path has a same level or dependency relationship with each comparison storage path.

[0094] After executing step 263, you can choose to execute step 264 or step 265 according to the specific situation.

[0095] Specifically, in an optional implementation of an embodiment of the present invention, detecting whether the current storage path has a same-level or dependent relationship with each comparison storage path includes: in each comparison storage path, obtaining the target comparison storage path in turn; obtaining the upper-level path corresponding to the current storage path and the target comparison storage path respectively; if it is determined that the upper-level path corresponding to the current storage path and the target comparison storage path are not the same, then determining that there is no same-level relationship between the current storage path and the target comparison storage path; otherwise, determining that there is a same-level relationship between the current storage path and the target comparison storage path; obtaining the path intersection of the current storage path and the target storage path; if it is determined that the path intersection is not the same as the current storage path, then determining that there is no dependency relationship between the current storage path and the target comparison storage path; otherwise, determining that there is a dependency relationship between the current storage path and the target comparison storage path.

[0096] The parent path can be understood as the path formed by removing the last layer of subdirectories in the storage path. For example, the parent path of the current storage path "D: / git.woda.ink / jifanfei / go.sum" can be "D: / git.woda.ink / jifanfei", and the parent path of the target comparison storage path "D: / git.woda.ink / jifanfei / *.java" can be "D: / git.woda.ink / jifanfei". At this time, the current storage path is the same as the parent path of the target comparison storage path, and there is a peer relationship between the current storage path and the target comparison storage path.

[0097] Correspondingly, the path intersection can be understood as the common part between storage paths. For example, the current storage path is "D: / git.woda.ink / jifanfei / go.sum", the target comparison storage path is "D: / git.woda.ink / jifanfei / go.sum / *.java", and the path intersection of the current storage path and the target comparison storage path is "D: / git.woda.ink / jifanfei / go.sum". At this time, the current storage path "D: / git.woda.ink / jifanfei / go.sum" is the same as the path intersection "D: / git.woda.ink / jifanfei / go.sum", and there is a dependency relationship between the current storage path and the target comparison storage path.

[0098] Step 264: If it is determined that there is no same-level or dependency relationship between the current storage path and any compared storage path, the current processing file is determined to be a first programming language description file, and the processed status of the current processing file is marked.

[0099] Specifically, when no other programming language description files corresponding to other programming language types exist in all subordinate paths under the current storage path corresponding to the currently processed file, the currently processed file may be determined as the first programming language description file.

[0100] Among them, considering that in the process of obtaining an unprocessed programming language description file as the current processing file for processing in order from high level to low level of the storage hierarchy, if a current processing file (assuming it is named file 1) is processed, when an unprocessed programming language description file at the same storage level as file 1 is obtained again for the same processing, it is not necessary to compare the storage path with file 1. Therefore, it is necessary to mark the processing status of the current processing file after each processing as the processed status to avoid the extra workload caused by repeated comparison.

[0101] After executing step 264, step 268 may be executed.

[0102] Step 265: If it is determined that there is a peer or dependency relationship between the current storage path and at least one comparison storage path, obtain a target programming language description file corresponding to the comparison storage path with the peer or dependency relationship.

[0103] Step 266: Continue to detect whether the current processing file has the same programming language type as the programming language types corresponding to the target programming language description files.

[0104] If the currently processed file is of the same programming language type as the programming language description files corresponding to each target programming language description file, then step 267 is executed; otherwise, step 269 may be executed.

[0105] Step 267: determine the current processing file as the first programming language description file, and mark the processed status of the current processing file and each target programming language description file.

[0106] Among them, other programming language description files may exist in the lower-level or same-level path of the storage path corresponding to the currently processed file. However, when the other programming language description file corresponds to the same programming language as the currently processed file, it can also meet the aforementioned compilation directory identification conditions. Therefore, the currently processed file can be determined as the first programming language description file.

[0107] After the current processing file is processed, the corresponding target programming language description file corresponds to the same programming language as the current processing file. There is no need to process the target programming language description file again. The processing status of the target programming language description file can be directly marked as processed, thereby reducing the number of programming language description files to be processed, achieving the effect of quickly determining the first programming language description file, and improving file processing speed and efficiency.

[0108] It should be noted that, in an optional implementation of an embodiment of the present invention, when determining the programming language used for compiling the data structure definition file under the storage path of the first programming language description file, it can be determined based on the programming language type corresponding to any file in the first programming language description file and its corresponding target programming language description file. However, since the first programming language description file has a higher storage level than the corresponding target programming language description file, in order to improve the speed of programming language determination and reduce unnecessary file processing, the programming language type corresponding to the first programming language description file can be used to determine the programming language used for compiling the data structure definition file under the storage path of the first programming language description file.

[0109] Step 268, return to execute the operation of obtaining one unprocessed programming language description file as the current processing file in order from high level to low level of the storage path, until the processing of all unprocessed programming language description files is completed.

[0110] Based on the above implementation, optionally, after step 266, that is, after continuing to detect whether the current processing file is of the same programming language type as the programming language type corresponding to each target programming language description file, the following steps are further included:

[0111] Step 269: construct a prompt of abnormal storage of the programming language description file according to the current processing file and each target programming language description file, and mark the processed status of the current processing file and each target programming language description file.

[0112] Among them, when the current processing file and the target programming language description file correspond to different programming language types, it indicates that there are other programming language description files corresponding to different programming language types in the subordinate or same-level path of the storage path corresponding to the current processing file, and the compilation directory identification conditions specified above are not met. Therefore, the programming language description file may have abnormal storage problems, and abnormal storage prompts can be given to facilitate developers to quickly find problems and make improvements, so as to identify possible risks in the project or microservice, so that the data structure definition file can be normally compiled under the corresponding programming language.

[0113] After executing step 269, the process may return to execute step 268.

[0114] Step 270: Filter out the programming language description files having data structure definition files in the corresponding storage paths from among the first programming language description files as the second programming language description files.

[0115] The ultimate purpose of determining the programming language description file is to compile the data structure definition file in the corresponding programming language. Therefore, in an embodiment of the present invention, if the data structure definition file does not exist in the storage path corresponding to the first programming language description file, the first programming language description file can be directly filtered out.

[0116] In an optional implementation of the embodiment of the present invention, in each first programming language description file, a programming language description file in which a data structure definition file exists under a corresponding storage path is screened out as a second programming language description file, including: searching for the data structure definition file under the storage path corresponding to each first programming language description file; determining the first programming language description file in which the data structure definition file is found as the second programming language description file; and prompting the first programming language description file in which the data structure definition file is not found that the data structure definition file is abnormally stored.

[0117] As mentioned above, according to the existing engineering or microservice construction method, there is usually a data structure definition file under the storage path corresponding to the programming language description file. In an embodiment of the present invention, if there is no data structure definition file under the storage path corresponding to the first programming language description file, a prompt for abnormal storage of the data structure definition file can be constructed to facilitate developers to quickly discover problems and verify whether there are omissions in the data structure definition file or the storage location is set incorrectly.

[0118] Step 280: Determine a compilation directory according to the storage directory corresponding to the second programming language description file.

[0119] Among them, the data structure definition file to be compiled needs to exist in the compilation directory, and it is clear that there is only one programming language type used when the data structure definition file is compiled. Therefore, in an embodiment of the present invention, the compilation directory can specifically be a directory corresponding to the upper-level path of the storage directory corresponding to the second programming language description file. Exemplarily, the storage path corresponding to the second programming language description file is "D: / git.woda.ink / jifanfei / go.sum", and the upper-level path corresponding to the compilation directory can be "D: / git.woda.ink / jifanfei / ".

[0120] The technical solution of the embodiment of the present invention obtains the original directory; traverses each file included in the original directory; matches the file name of each file obtained by traversal with each programming language description file name in the programming language description file name set; determines the file whose file name matches the programming language description file name set as the programming language description file; determines the programming language type corresponding to each programming language description file according to the programming language description file name matching each programming language description file and the mapping relationship between the programming language description file name and the programming language type; selects the first programming language description file from all programming language description files according to the storage path and programming language type corresponding to each programming language description file; selects the programming language description file with a data structure definition file under the corresponding storage path in each first programming language description file as the second programming language description file; determines the compilation directory according to the storage directory corresponding to the second programming language description file. The technical solution of the embodiment of the present invention provides a new method for automatically and accurately determining the compilation directory corresponding to the same project or the same microservice, which completely avoids the loss of time and labor cost when manually determining the compilation directory, and at the same time, completely avoids the subjective errors that are easily introduced when constructing the compilation command, and guarantees the execution success rate of the compilation instruction to the greatest extent.

[0121] Embodiment 3

[0122] Figure 3 1 is a flow chart of a method for determining a compilation directory provided by Embodiment 3 of the present invention. This embodiment is a further refinement of the above technical solution, and the technical solution in this embodiment can be combined with various optional solutions in one or more of the above embodiments. Figure 3 As shown, the method includes:

[0123] Step 310: Get the original directory.

[0124] The original directory includes at least one data structure definition file, and the data structure definition file is used to compile in a set programming language to obtain a compilation result.

[0125] Step 320: Search for programming language description files in the original directory, obtain all programming language description files included in the original directory, and determine the programming language type corresponding to each programming language description file.

[0126] Step 330: Identify the compilation directory in the original directory according to the storage path and programming language type corresponding to each programming language description file.

[0127] The same compilation directory includes at least one data structure definition file for compiling in the same programming language.

[0128] Step 340: parse each data structure definition file in the compilation directory to determine the cross-file dependency description information corresponding to each data structure definition file.

[0129] The cross-file dependency description information can be understood as information indicating the dependency relationship in the current data structure definition file when the current data structure definition file depends on one or more other data structure definition files. For example, when data structure definition file A depends on data structure definition file B, data structure definition file A can be indicated to depend on data structure definition file B through the cross-file dependency description information.

[0130] Exemplarily, data structure definition file A can indicate that data structure definition file A depends on data structure definition file B through the cross-file dependency description information "import "git.woda.ink / jifanfei / common_proto / ComMsg / data structure definition file B"". That is, when compiling the data structure definition file A, all the contents of data structure definition file B need to be introduced.

[0131] The fact that data structure definition file A depends on data structure definition file B can be understood as the request format and response format defined in data structure definition file B can be applied (or called) in data structure definition file A.

[0132] In the prior art, before a user compiles each data structure definition file in a compilation directory and obtains a matching compilation result, it is necessary to manually determine the cross-file dependency description information corresponding to each data structure definition file, for example, by manually reading the file content of the data structure definition file, and identifying the cross-file dependency description information corresponding to each data structure definition file, that is, the other data structure definition files introduced. Then, a matching compilation command can be generated for each data structure definition file. Accordingly, when generating a compilation command, the cross-file dependency description information obtained manually needs to be added to the compilation command as a compilation parameter.

[0133] Based on this, the inventor creatively proposed a technical solution of automatically determining the cross-file dependency description information corresponding to the data structure definition file, automatically determining the matching compilation parameters based on the cross-file dependency description information, and automatically generating a compilation command based on the compilation parameters to implement the data structure definition file compilation, so as to minimize manual operations. Moreover, since the compilation command has strict requirements on each part of the parameters and parameter types, if one or more parameters (or parameter types) determined manually are set incorrectly, the compilation command cannot be executed. Therefore, the technical solution of automatically generating compilation commands proposed by the present invention also avoids the error of the compilation command being unable to be executed due to manual operations.

[0134] Step 350: Compile each data structure definition file according to the cross-file dependency description information corresponding to each data structure definition file and the programming language type corresponding to the programming language description file in the compilation directory to obtain a matching compilation result.

[0135] Compilation can be understood as using a compilation tool to generate a compilation result that can be used for remote procedure calls under specified parameters (for example, programming language type and cross-file dependency description information) for a specified data structure definition file. When generating a compilation command corresponding to each data structure definition file, it is necessary to add a compilation parameter corresponding to the programming language type. In addition, if cross-file dependency description information is introduced in the data structure definition file, it is also necessary to add a compilation parameter that matches the cross-file dependency description information. If the compilation parameter that matches the cross-file dependency description information in the compilation command is empty, it means that the current data structure definition file does not depend on any other data structure definition file.

[0136] As mentioned above, for a data structure definition file, a compilation command can be constructed, in which the programming language type corresponding to the data structure definition file and the customized compilation parameters corresponding to the cross-file dependency description information are included. Then, after executing the compilation command, a compilation result corresponding to the data structure definition file can be formed accordingly.

[0137] In this embodiment, computer technology is used to automatically obtain the programming language type and cross-file dependency description information corresponding to each data structure definition file included in a compilation directory, and compilation commands corresponding to each data structure definition file can be automatically generated to realize a fully automatic compilation process.

[0138] Exemplarily, the programming language type corresponding to the data structure definition file is go language, and the generated compilation result can be a "*.pb.go" file; the target programming language type corresponding to the data structure definition file is C++ language, and the generated compilation result can be a pair of "*.pb.h" and "*.pb.cc" files.

[0139] The technical solution of the embodiment of the present invention obtains the original directory; searches for programming language description files in the original directory to obtain all programming language description files included in the original directory, and determines the programming language type corresponding to each programming language description file; identifies the compilation directory in the original directory according to the storage path and programming language type corresponding to each programming language description file; parses each data structure definition file under the compilation directory to determine the cross-file dependency description information corresponding to each data structure definition file; compiles each data structure definition file according to the cross-file dependency description information corresponding to each data structure definition file and the programming language type corresponding to the programming language description file in the compilation directory to obtain a matching compilation result, thereby solving the problem that the compilation directory, programming language and cross-file dependency description information need to be manually determined when constructing the compilation command of the data structure definition file, and the data structure definition file can meet the compilation directory identification condition and generate the compilation file of the corresponding programming language without manually determining the programming language type, the compilation directory and the cross-file dependency description information, while completely avoiding the loss of time and labor cost caused by manually determining the compilation directory, and improving the execution success rate of the compilation command.

[0140] On the basis of the above implementation, optionally, each data structure definition file in the compilation directory is parsed to determine the cross-file dependency description information corresponding to each data structure definition file, including: obtaining the target data structure definition file in the compilation directory; parsing the file content of the target data structure definition file line by line to determine whether there is a target content line containing the target key field in the target data structure definition file; if so, determining the cross-file dependency description information corresponding to the target data structure definition file based on each target content line.

[0141] Among them, the target data structure definition file can be stored in the first-level subdirectory of the compilation directory, or in other subdirectories located under the first-level subdirectory. For example, for a microservice project written in go language (corresponding to the compilation directory), it can be specifically recursively searched from the first-level subdirectory in the folder where the microservice project is located to obtain the target data structure definition file, which can ensure the comprehensiveness of the obtained target data structure definition file and avoid the problem of missing compilation of the data structure definition file. The storage path formed by the first-level subdirectory of the compilation directory to the directory where the target data structure definition file is found can be used as the storage path corresponding to the target data structure definition file. In a compilation directory, there can be one or more target data structure definition files.

[0142] In an embodiment of the present invention, the target key field may be a field declared when the target data structure definition file depends on other data structure definition files. The target content may specifically indicate the specific content of other data structure definition files on which the target data structure definition file depends. A target data structure definition file may depend on one or more other data structure definition files. Each time a target data structure definition file depends on another data structure definition file, a cross-file dependency description information may be generated through a target content line containing the target key field to indicate the dependency relationship. By determining the cross-file dependency description information through the target key field, the accuracy and efficiency of determining the cross-file dependency description information may be improved.

[0143] For example, there is a target content line in the target data structure definition file A (A.proto), and the recorded content is: "import "git.woda.ink / jifanfei / common_proto / ComMsg / B.proto"", indicating that A.proto depends on the data structure definition file B (B.proto); among them, "import" can be the target key field.

[0144] Among them, all the content, part of the content, or the content supplemented according to the recorded content recorded in the target content line can be used as the cross-file dependency description information corresponding to the target data structure definition file.

[0145] In an optional implementation of an embodiment of the present invention, cross-file dependency description information corresponding to the target data structure definition file is determined based on each target content row, including: filtering out the target key field contained in each target content row to obtain the dependency file storage path corresponding to each target content row; and determining each dependency file storage path as the cross-file dependency description information corresponding to the target data structure definition file.

[0146] The cross-file dependency description information may specifically record the data structure definition file on which the target data structure definition file depends, and content related to the storage path of the dependent data structure definition file.

[0147] For example, the target content line containing the target key field "import" in A.proto records the content: "import "git.woda.ink / jifanfei / common_proto / ComMsg / B.proto"", indicating that A.proto depends on B.proto. Among them, the target key field can be "import", and the remaining content "git.woda.ink / jifanfei / common_proto / ComMsg / B.proto" after filtering out the target key field is the dependent file storage path of B.proto. "git.woda.ink / jifanfei / common_proto / ComMsg / B.proto" can be used as the cross-file dependency description information corresponding to A.proto.

[0148] In some specific embodiments, if the target data structure definition file and the dependent data structure definition file are in the same directory, the content in the target content line may exist in at least one corresponding simplified form, such as the storage path of A.proto is "git.woda.ink / jifanfei / common_proto / ComMsg / A.proto"; the storage path of B.proto is "git.woda.ink / jifanfei / common_proto / ComMsg / B.proto", and the target content line containing the target key field "import" in A.proto may record the content: "import "B.proto"", indicating that A.proto and B.proto are two files of the same level in the same directory.

[0149] When A.proto depends on B.proto, the abbreviated storage path corresponding to B.proto can be determined as "." according to the content recorded in the target content line and the storage path of A.proto, where "." means the same as the storage path of A.proto; the full storage path of B.proto can also be determined as "git.woda.ink / jifanfei / common_proto / ComMsg / B.proto". When the storage path of B.proto is used as the cross-file dependency description information, the abbreviated storage path or the full storage path corresponding to B.proto can be used as the cross-file dependency description information.

[0150] In another optional implementation of the embodiment of the present invention, cross-file dependency description information corresponding to the target data structure definition file is determined based on each target content line, including: filtering out the target key field contained in each target content line to obtain the dependent file storage path corresponding to each target content line; obtaining the upper-level storage directory corresponding to each dependent file storage path; and determining each upper-level storage directory as the cross-file dependency description information corresponding to the target data structure definition file.

[0151] For example, the target content line containing the target key field "import" in A.proto records the content: "import "git.woda.ink / jifanfei / common_proto / ComMsg / B.proto"", indicating that A.proto depends on B.proto. Among them, the target key field may be "import", and the remaining content "git.woda.ink / jifanfei / common_proto / ComMsg / B.proto" after filtering out the target key field is the dependent file storage path of B.proto. The parent storage directory of the dependent file storage path may be "git.woda.ink / jifanfei / common_proto / ComMsg / ", which can be used as the cross-file dependency description information corresponding to A.proto.

[0152] It should be noted that the cross-file dependency description information can be empty, one or more. When the cross-file dependency description information is empty, it means that the target data structure definition file does not have a dependent data structure definition file. The cross-file dependency description information can be the complete dependent file storage path of the file that the target data structure definition file depends on; or it can be a simplified form of the dependent file storage path. For example, the cross-file dependency description information is represented by the upper-level storage directory corresponding to the dependent file storage path. When the target data structure definition file depends on multiple other data structure definition files, this method can simplify the code, improve the efficiency of code execution, and facilitate subsequent reading and problem finding.

[0153] In an optional implementation of an embodiment of the present invention, the data structure definition file includes: a proto file; compiling each data structure definition file according to the cross-file dependency description information corresponding to each data structure definition file, and the programming language type corresponding to the programming language description file in the compilation directory, to obtain a matching compilation result, including: constructing a protoc compilation command corresponding to each proto file according to the cross-file dependency description information corresponding to each proto file, and the programming language type corresponding to the programming language description file in the compilation directory; and obtaining a compilation result corresponding to each proto file by executing each protoc compilation command.

[0154] In the proto file, data structured definition and encapsulation are generally implemented through syntax such as message, import, and embedded message to specify the serialized structured data format used in network communication and general data exchange. It has the advantages of being language-independent, platform-independent, efficient, scalable, and compatible.

[0155] In an embodiment of the present invention, when the data structure definition file is a proto file, the compilation tool used for compilation may be protoc. protoc is a command line compilation tool provided by ProtocolBuffer. There are multiple options in the command format in protoc. Among them, the options may include cross-file dependency description information and target programming language type, etc. The above information may be filled in to generate a protoc compilation command, and the protoc compilation tool may be used to compile to obtain a compilation result.

[0156] On the basis of the above implementation, optionally, according to the cross-file dependency description information corresponding to each proto file, and the programming language type corresponding to the programming language description file in the compilation directory, a protoc compilation command corresponding to each proto file is constructed, including: obtaining a standardized filling template that matches the protoc compilation command, the standardized filling template including multiple positions to be filled; obtaining a target string corresponding to the programming language type; filling the cross-file dependency description information, file name, file storage path, and target string corresponding to each proto file in the matching positions to be filled in the standardized filling template, to obtain the protoc compilation command corresponding to each proto file.

[0157] Among them, when protoc is used for compilation, a protoc compilation command needs to be generated. The protoc compilation command may correspond to a standardized filling template, and the optional information may be filled in the position to be filled in the standardized filling template. Specifically, the information related to the target data structure definition file, the cross-file dependency description information, and the programming language type may be filled in the position to be filled in the standardized filling template to generate the protoc compilation command. The method of generating the protoc compilation command through the standardized filling template can standardize the generation of the protoc compilation command, avoid the artificial logical judgment required when artificially constructing the protoc compilation command, and on the basis of reducing the compilation command generation time, it can also effectively avoid the omission of information when the protoc compilation command is generated, and avoid the occurrence of subjective errors. Exemplarily, the standardized filling template corresponding to the protoc compilation command may be: "protoc--proto_path=IMPORT_PATH--Programing_Language=DST_DIRpath / to / file.proto".

[0158] Among them, "proto_path" is equivalent to the -I option, which is mainly used to specify the directory where the data structure definition file to be compiled is located. This option can be specified multiple times at the same time. "IMPORT_PATH" corresponds to a position to be filled, which is used to fill in the cross-file dependency description information. "Programming_Language" corresponds to a position to be filled, which is used to fill in the target string corresponding to the target programming language type. For example, the target string corresponding to the C++ programming language can be "cpp_out", the target string corresponding to the Java programming language can be "java_out", or the target string corresponding to the Python programming language can be "python_out", etc. The directory after "Programming_Language" (i.e., DST_DIR) corresponds to a position to be filled, which is used to fill in the directory where the compilation results generated by the compilation are stored. For example, the compilation results corresponding to the C++ programming language can be stored in ". / GenFileCpp", and the compilation results corresponding to the Python programming language can be stored in ". / GenFilePython", etc. "path / to / file.proto" corresponds to a position to be filled, which is used to fill in the file name of the data structure definition file to be compiled.

[0159] As another example, the standardized filling template corresponding to the protoc compilation command may be "protoc -I$PROTO_DIR -I$LINK_DIR --Programming_Language=grpc:$PBGO_OUTPUT_DIR*.proto".

[0160] Among them, "$PROTO_DIR" corresponds to a position to be filled, which is used to fill in the storage path of the target data structure definition file; "*.proto" corresponds to a position to be filled, which is used to fill in the file name of the target data structure definition file; "$LINK_DIR" corresponds to a position to be filled, which is used to fill in the cross-file dependency description information, that is, to fill in the storage path of other data structure definition files that the target data structure definition file depends on (import). "Programming_Language" corresponds to a position to be filled, which is used to fill in the target string corresponding to the target programming language type, for example, "--go_out=plugins= "grpc" means based on the grpc framework; "$PBGO_OUTPUT_DIR" corresponds to a position to be filled, which is used to fill in the path where the compilation results are stored.

[0161] It can be seen that when compiling a data structure definition file, it is necessary to determine the compilation directory, determine the data structure definition file under the compilation directory, and determine the storage path of the data structure definition file. At the same time, it is also necessary to determine the type of programming language used for compilation in the compilation directory, and determine the storage path of the compilation result (which can be specified according to actual conditions). In addition, it is also necessary to determine the cross-file dependency description information corresponding to other data structure definition files that the data structure definition file depends on. Based on the above determined information, a protoc compilation command can be generated to compile the target data structure definition file.

[0162] On the basis of the above implementation, optionally, after compilation, the compilation result can be returned. Among them, the compilation result can be the corresponding return file when the compilation is successful. For example, in the go language, the "pb.go" file and the numerical value or string corresponding to the successful compilation can be returned. The compilation result can also be the numerical value or string corresponding to the failed expression when the compilation fails. The error type and specific prompt content can be returned synchronously to facilitate the developer to confirm the problem.

[0163] The technical solution of this embodiment determines the cross-file dependency description information in the above-mentioned manner and compiles the data structure definition file, thereby solving the problem that in the existing process of manually constructing the compilation command of the data structure definition file, the compilation directory, programming language and cross-file dependency description information need to be manually determined. The compilation file can be generated without manually determining the programming language type or the cross-file dependency description information. This completely avoids the loss of time and labor costs caused by manually determining the compilation directory, while improving the execution success rate of the compilation command.

[0164] Embodiment 4

[0165] Figure 4 1 is a schematic diagram of a structure of a device for determining a compilation directory provided by Embodiment 4 of the present invention. Figure 4 The device includes: an original directory acquisition module 410, a programming language type determination module 420 and a compilation directory identification module 430. Among them:

[0166] The original directory acquisition module 410 is used to acquire the original directory; the original directory includes at least one data structure definition file, and the data structure definition file is used to compile in a set programming language to obtain a compilation result;

[0167] A programming language type determination module 420 is used to search for programming language description files in the original directory, obtain all programming language description files included in the original directory, and determine the programming language type corresponding to each programming language description file;

[0168] The compilation directory identification module 430 is used to identify the compilation directory in the original directory according to the storage path and programming language type corresponding to each programming language description file, wherein the same compilation directory includes at least one data structure definition file for compiling under the same programming language.

[0169] The embodiment of the present invention obtains an original directory; the original directory includes at least one data structure definition file, and the data structure definition file is used to compile under a set programming language to obtain a compilation result; the programming language description file is searched in the original directory, all the programming language description files included in the original directory are obtained, and the programming language type corresponding to each programming language description file is determined; according to the storage path and programming language type corresponding to each programming language description file, a compilation directory is identified in the original directory, wherein the same compilation directory includes at least one data structure definition file for compiling under the same programming language. The technical solution of the embodiment of the present invention provides a new method for automatically and accurately determining the compilation directory corresponding to the same project or the same microservice, which completely avoids the loss of time and labor cost when manually determining the compilation directory. At the same time, it also completely avoids the subjective errors that are easily introduced when constructing compilation commands, and guarantees the execution success rate of compilation instructions to the greatest extent.

[0170] Optionally, the programming language type determination module 420 includes:

[0171] A file traversal unit, used for traversing each file included in the original directory;

[0172] A file name matching unit, used for matching the file names of the traversed files with the programming language description file names in the programming language description file name set;

[0173] A programming language description file determination unit, used to determine a file whose file name matches the programming language description file name set as a programming language description file;

[0174] The programming language type determination unit is used to determine the programming language type corresponding to each programming language description file according to the programming language description file name matching each programming language description file and the mapping relationship between the programming language description file name and the programming language type.

[0175] Optionally, the compilation directory identification module 430 includes:

[0176] A first programming language description file screening unit, configured to screen out the first programming language description file from all programming language description files according to a storage path and a programming language type corresponding to each programming language description file;

[0177] There is no same-level or dependency relationship between the storage paths corresponding to the first programming language description file and other programming language description files of different programming language types;

[0178] A second programming language description file screening unit is used to screen out, from among the first programming language description files, a programming language description file having a data structure definition file in a corresponding storage path as the second programming language description file;

[0179] The compiling directory determining unit is used to determine the compiling directory according to the storage directory corresponding to the second programming language description file.

[0180] Optionally, the first programming language description file screening unit includes:

[0181] A storage level determination subunit, used to determine the storage level corresponding to each storage path based on the original directory;

[0182] The current processing file determination subunit is used to sequentially obtain an unprocessed programming language description file as the current processing file in the order of storage levels from high level to low level;

[0183] The path relationship detection subunit is used to obtain the current storage path of the currently processed file, use the storage paths corresponding to other unprocessed programming language description files as comparison storage paths, and detect whether the current storage path has a same level or dependency relationship with each comparison storage path;

[0184] A first programming language description file determination subunit is used to determine the current processing file as the first programming language description file and mark the processed status of the current processing file if it is determined that there is no same level or dependency relationship between the current storage path and any compared storage path;

[0185] a target programming language description file acquisition subunit, for acquiring a target programming language description file corresponding to the comparison storage path having the same level or dependency relationship if it is determined that the current storage path has a same level or dependency relationship with at least one comparison storage path;

[0186] A programming language detection subunit, used to continue to detect whether the currently processed file has the same programming language type as the programming language types corresponding to each target programming language description file;

[0187] A first programming language description file determination subunit is used to determine the current processing file as the first programming language description file if the current processing file and the programming language types corresponding to the target programming language description files are the same, and mark the processed status of the current processing file and the target programming language description files;

[0188] The return execution subunit is used to return the execution and sequentially obtain an unprocessed programming language description file as the current processing file in the order of the storage path from high level to low level until the processing of all unprocessed programming language description files is completed.

[0189] Optionally, the path relationship detection subunit is specifically used to:

[0190] In each comparison storage path, obtain the target comparison storage path;

[0191] Get the parent path corresponding to the current storage path and the target comparison storage path respectively;

[0192] If it is determined that the current storage path is not the same as the upper level path corresponding to the target comparison storage path, it is determined that there is no same level relationship between the current storage path and the target comparison storage path; otherwise, it is determined that there is a same level relationship between the current storage path and the target comparison storage path;

[0193] Get the path intersection of the current storage path and the target storage path;

[0194] If it is determined that the path intersection is not the same as the current storage path, it is determined that there is no dependency relationship between the current storage path and the target comparison storage path; otherwise, it is determined that there is a dependency relationship between the current storage path and the target comparison storage path.

[0195] Optionally, the device further includes:

[0196] An abnormal storage prompt module is used to, after continuing to detect whether the current processing file is the same as the programming language type corresponding to each target programming language description file, if the current processing file is not the same as the programming language type corresponding to each target programming language description file, construct a prompt for abnormal storage of the programming language description file according to the current processing file and each target programming language description file, and mark the processed status of the current processing file and each target programming language description file;

[0197] The return execution module is used to return the execution and sequentially obtain an unprocessed programming language description file as the current processing file in the order of the storage path from high level to low level until the processing of all unprocessed programming language description files is completed.

[0198] Optionally, the second programming language description file screening unit is specifically used to:

[0199] Searching for a data structure definition file in a storage path corresponding to each first programming language description file;

[0200] Determine the first programming language description file of the data structure definition file found as the second programming language description file;

[0201] For the first programming language description file for which no data structure definition file is found, a prompt is given that the data structure definition file is stored abnormally.

[0202] Optionally, the device further includes:

[0203] A cross-file dependency description information determination module is used to parse each data structure definition file under the compilation directory after identifying the compilation directory in the original directory according to the storage path and programming language type corresponding to each programming language description file, and determine the cross-file dependency description information corresponding to each data structure definition file;

[0204] The compilation result acquisition module is used to compile each data structure definition file according to the cross-file dependency description information corresponding to each data structure definition file and the programming language type corresponding to the programming language description file in the compilation directory to obtain a matching compilation result.

[0205] Optionally, the cross-file dependency description information determination module includes:

[0206] A target data structure definition file acquisition unit is used to acquire a target data structure definition file in a compilation directory;

[0207] A target content line query unit is used to parse the file content of the target data structure definition file line by line to determine whether there is a target content line containing a target key field in the target data structure definition file;

[0208] The cross-file dependency description information determining unit is used to determine the cross-file dependency description information corresponding to the target data structure definition file according to each target content line if there are target content lines containing target key fields in the target data structure definition file.

[0209] Optionally, the cross-file dependency description information determination unit includes:

[0210] A first dependent file storage path acquisition subunit is used to filter out the target key field contained in each target content row to obtain the dependent file storage path corresponding to each target content row;

[0211] The first cross-file dependency description information determination subunit is used to determine the storage path of each dependent file as the cross-file dependency description information corresponding to the target data structure definition file.

[0212] Optionally, the cross-file dependency description information determination unit includes:

[0213] The second dependent file storage path acquisition subunit is used to filter out the target key field contained in each target content row to obtain the dependent file storage path corresponding to each target content row;

[0214] The upper level storage directory acquisition unit is used to acquire the upper level storage directories corresponding to the storage paths of the dependent files;

[0215] The second cross-file dependency description information determination subunit is used to determine each upper-level storage directory as the cross-file dependency description information corresponding to the target data structure definition file.

[0216] Optionally, the data structure definition files include: proto files;

[0217] Compilation result acquisition module, including:

[0218] The protoc compilation command construction unit is used to construct the protoc compilation command corresponding to each proto file according to the cross-file dependency description information corresponding to each proto file and the programming language type corresponding to the programming language description file in the compilation directory;

[0219] The compilation result acquisition unit is used to obtain the compilation results corresponding to each proto file by executing each protoc compilation command.

[0220] Optional, protoc compile command build unit, including:

[0221] A standardized filling template acquisition subunit is used to acquire a standardized filling template that matches the protoc compilation command, wherein the standardized filling template includes a plurality of positions to be filled;

[0222] A target string acquisition subunit is used to acquire a target string corresponding to a programming language type;

[0223] The protoc compilation command acquisition subunit is used to fill the cross-file dependency description information, file name, file storage path, and target string corresponding to each proto file in the matching to-be-filled position in the standardized filling template, and obtain the protoc compilation command corresponding to each proto file.

[0224] The apparatus for determining a compilation catalog provided in the embodiment of the present invention can execute the method for determining a compilation catalog provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0225] Embodiment 5

[0226] Figure 5 A schematic diagram of the structure of a computer device provided in Embodiment 5 of the present invention is shown in FIG. Figure 5 As shown, the device includes a processor 510, a memory 520, an input device 530 and an output device 540; the number of processors 510 in the device / terminal / server can be one or more. Figure 5A processor 510 is taken as an example; the processor 510, the memory 520, the input device 530 and the output device 540 in the device / terminal / server can be connected via a bus or other means. Figure 5 The example of connecting through bus is taken in the following.

[0227] The memory 520, as a computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the method for compiling a data structure definition file in an embodiment of the present invention (e.g., the original directory acquisition module 410, the programming language type determination module 420 and the compilation directory identification module 430). The processor 510 executes various functional applications and data processing of the computer device by running the software programs, instructions and modules stored in the memory 520, that is, implements the above-mentioned method for determining the compilation directory.

[0228] The memory 520 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 520 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 520 may further include a memory remotely arranged relative to the processor 510, and these remote memories may be connected to the device / terminal / server via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0229] The input device 530 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the device. The output device 540 may include a display device such as a display screen.

[0230] Embodiment 6

[0231] Embodiment 6 of the present invention further provides a storage medium including computer executable instructions, wherein the computer executable instructions are used to execute a method for determining a compilation directory when executed by a computer processor, the method comprising:

[0232] Acquire an original directory; the original directory includes at least one data structure definition file, and the data structure definition file is used to compile in a set programming language to obtain a compilation result;

[0233] Searching for programming language description files in the original directory, obtaining all programming language description files included in the original directory, and determining the programming language type corresponding to each programming language description file;

[0234] According to the storage path and programming language type corresponding to each programming language description file, a compilation directory is identified in the original directory, wherein the same compilation directory includes at least one data structure definition file for compiling in the same programming language.

[0235] Of course, the computer executable instructions of the storage medium provided by the embodiment of the present invention are not limited to the method operations described above, and can also perform related operations in the method for compiling a data structure definition file provided by any embodiment of the present invention.

[0236] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0237] It is worth noting that in the embodiment of the compilation device of the above-mentioned data structure definition file, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the various functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0238] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention 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 invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A method for determining a compilation directory, characterized in that: include: Acquire an original directory; the original directory includes at least one data structure definition file, and the data structure definition file is used to compile in a set programming language to obtain a compilation result; Searching for programming language description files in the original directory, obtaining all programming language description files included in the original directory, and determining the programming language type corresponding to each programming language description file; According to the storage path and programming language type corresponding to each programming language description file, identifying a compilation directory in the original directory, wherein the same compilation directory includes at least one data structure definition file for compiling in the same programming language; According to the storage path and programming language type corresponding to each programming language description file, identifying the compilation directory in the original directory includes: Filter out the first programming language description file from all programming language description files according to the storage path and programming language type corresponding to each programming language description file; There is no same-level or dependency relationship between the storage paths corresponding to the first programming language description file and other programming language description files of different programming language types; In each first programming language description file, a programming language description file having a data structure definition file under a corresponding storage path is selected as a second programming language description file; A compile directory is determined according to a storage directory corresponding to the second programming language description file.

2. The method according to claim 1, searching for programming language description files in the original directory, obtaining all programming language description files included in the original directory, and determining the programming language type corresponding to each programming language description file, comprising: Traversing each file included in the original directory; Match the file names of the traversed files with the programming language description file name set; A file whose file name matches the programming language description file name set is determined as a programming language description file; The programming language type corresponding to each programming language description file is determined according to the programming language description file name matching each programming language description file and the mapping relationship between the programming language description file name and the programming language type.

3. The method according to claim 1, characterized in that According to the storage path and programming language type corresponding to each programming language description file, a first programming language description file is screened out from all programming language description files, including: Based on the original directory, determine the storage level corresponding to each storage path; Obtain an unprocessed programming language description file as a current processing file in order from a high level to a low level of the storage hierarchy; Obtaining the current storage path of the currently processed file, taking the storage paths corresponding to other unprocessed programming language description files as comparison storage paths, and detecting whether the current storage path has a same level or dependency relationship with each of the comparison storage paths; If it is determined that there is no same-level or dependency relationship between the current storage path and any compared storage path, the current processing file is determined to be a first programming language description file, and a processed state of the current processing file is marked; If it is determined that there is a peer or dependency relationship between the current storage path and at least one comparison storage path, then obtaining a target programming language description file corresponding to the comparison storage path with the peer or dependency relationship; Continue to detect whether the current processing file and the programming language types corresponding to each of the target programming language description files are all the same; If yes, determining the currently processed file as the first programming language description file, and marking the processed status of the currently processed file and each of the target programming language description files; Return to execute the operation of obtaining one unprocessed programming language description file as the current processing file in sequence according to the storage path from high level to low level, until the processing of all unprocessed programming language description files is completed.

4. The method according to claim 3, characterized in that Detecting whether the current storage path has a peer or dependency relationship with each of the compared storage paths includes: In each of the comparison storage paths, obtaining a target comparison storage path; Obtain the upper level paths corresponding to the current storage path and the target comparison storage path respectively; If it is determined that the current storage path is not the same as the upper level path corresponding to the target comparison storage path, it is determined that there is no same level relationship between the current storage path and the target comparison storage path; otherwise, it is determined that there is a same level relationship between the current storage path and the target comparison storage path; Obtaining a path intersection of the current storage path and the target storage path; If it is determined that the path intersection is not the same as the current storage path, it is determined that there is no dependency relationship between the current storage path and the target comparison storage path; otherwise, it is determined that there is a dependency relationship between the current storage path and the target comparison storage path.

5. The method according to claim 3, characterized in that: After continuing to detect whether the current processing file has the same programming language type as the programming language types corresponding to the target programming language description files, the method further includes: If not, constructing a prompt of abnormal storage of the programming language description file according to the current processing file and each of the target programming language description files, and marking the processed status of the current processing file and each of the target programming language description files; Return to execute the operation of obtaining one unprocessed programming language description file as the current processing file in sequence according to the storage path from high level to low level, until the processing of all unprocessed programming language description files is completed.

6. The method according to claim 3, characterized in that In each first programming language description file, a programming language description file having a data structure definition file under a corresponding storage path is selected as a second programming language description file, including: Searching for a data structure definition file in a storage path corresponding to each first programming language description file; Determine the first programming language description file of the data structure definition file found as the second programming language description file; For the first programming language description file for which no data structure definition file is found, a prompt is given that the data structure definition file is stored abnormally.

7. The method according to any one of claims 1 to 6, characterized in that: After identifying the compilation directory in the original directory according to the storage path and programming language type corresponding to each programming language description file, the method further includes: Parse each data structure definition file in the compilation directory to determine the cross-file dependency description information corresponding to each data structure definition file; According to the cross-file dependency description information corresponding to each data structure definition file and the programming language type corresponding to the programming language description file in the compilation directory, each data structure definition file is compiled to obtain a matching compilation result.

8. A computer device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Method and apparatus for increasing compilation speed of android system

    CN107656736A

  • Multi-language code compiling method and distribute method, device and system

    CN107943486A