Disclosure of Invention
The embodiment of the disclosure at least provides a compiling method and a compiling device.
In a first aspect, an embodiment of the present disclosure provides a compiling method, including:
acquiring an object code to be compiled, and determining dependency description information required by compiling the object code;
determining a compiling identification of the object code based on the dependency description information and the attribute information of the object code;
and inquiring the compiling product matched with the compiling identification from a database, and taking the inquired compiling product as the compiling result of the target code.
In an optional embodiment, the determining the compilation identification of the object code based on the dependency description information and the attribute information of the object code includes:
determining a hash value corresponding to the dependency description information and the attribute information based on the dependency description information and the attribute information of the target code;
and taking the determined hash value as the compiling identification of the object code.
In an alternative embodiment, the determining the dependency description information required for compiling the object code includes:
performing pre-compiling processing on the object code to obtain a dependency description file of the object code; the dependency description file comprises header file information of each dependency required for compiling the object code;
and taking each piece of header file information in the dependency description file as the dependency description information.
In an optional embodiment, the attribute information of the object code includes at least one of:
the system comprises a body file of the object code, a header file of the object code, a compiler version corresponding to the object code and an environment variable corresponding to the object code.
In an optional embodiment, the method further comprises:
and if the compiling product matched with the compiling identifier does not exist in the database, calling a compiler corresponding to the object code to compile the object code to obtain a compiling result of the object code.
In an optional embodiment, the method further comprises:
and storing a compiling result obtained by compiling into the database as a compiling product matched with the compiling identification.
In an alternative embodiment, the querying the database for the compilation product matching the compilation identifier includes:
inquiring a compiling product matched with the compiling identification from a local database; alternatively, the first and second electrodes may be,
and sending a query request aiming at the compiling identification to a server corresponding to a remote database so that the server queries from the database and feeds back a compiling product matched with the compiling identification.
In a second aspect, an embodiment of the present disclosure further provides a compiling apparatus, including:
the device comprises an acquisition module, a compiling module and a compiling module, wherein the acquisition module is used for acquiring an object code to be compiled and determining dependence description information required by compiling the object code;
the determining module is used for determining the compiling identification of the object code based on the dependency description information and the attribute information of the object code;
and the query module is used for querying the compiling product matched with the compiling identifier from the database and taking the queried compiling product as the compiling result of the target code.
In an optional implementation manner, the determining module is specifically configured to:
determining a hash value corresponding to the dependency description information and the attribute information based on the dependency description information and the attribute information of the target code;
and taking the determined hash value as the compiling identification of the object code.
In an alternative embodiment, the obtaining module, when determining the dependency description information required for compiling the object code, is configured to:
performing pre-compiling processing on the object code to obtain a dependency description file of the object code; the dependency description file comprises header file information of each dependency required for compiling the object code;
and taking each piece of header file information in the dependency description file as the dependency description information.
In an optional embodiment, the attribute information of the object code includes at least one of:
the system comprises a body file of the object code, a header file of the object code, a compiler version corresponding to the object code and an environment variable corresponding to the object code.
In an optional embodiment, the apparatus further comprises a compiling module configured to:
and if the compiling product matched with the compiling identifier does not exist in the database, calling a compiler corresponding to the object code to compile the object code to obtain a compiling result of the object code.
In an optional embodiment, the compiling module is further configured to:
and storing a compiling result obtained by compiling into the database as a compiling product matched with the compiling identification.
In an alternative embodiment, the query module, when querying a database for a compilation product matching the compilation identification, is configured to:
inquiring a compiling product matched with the compiling identification from a local database; alternatively, the first and second electrodes may be,
and sending a query request aiming at the compiling identification to a server corresponding to a remote database so that the server queries from the database and feeds back a compiling product matched with the compiling identification.
In a third aspect, an embodiment of the present disclosure further provides an electronic device, including: a processor, a memory and a bus, the memory storing machine-readable instructions executable by the processor, the processor and the memory communicating via the bus when the electronic device is running, the machine-readable instructions when executed by the processor performing the steps of the first aspect described above, or any possible implementation of the first aspect.
In a fourth aspect, this disclosed embodiment also provides a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to perform the steps in the first aspect or any one of the possible implementation manners of the first aspect.
According to the compiling method and device provided by the embodiment of the disclosure, firstly, an object code to be compiled is obtained, and dependency description information required by compiling the object code is determined; then, based on the dependency description information and the attribute information of the object code, determining a compiling identification of the object code; and finally, inquiring the compiling product matched with the compiling identification from the database, and taking the inquired compiling product as the compiling result of the target code. According to the embodiment of the disclosure, the compiling product is matched by depending on the description information and the attribute information of the object code, and the matched compiling product is used as the compiling result of the object code, so that the object code does not need to be compiled, the effect of saving computing resources is realized, and the efficiency of obtaining the compiling product is improved because the object code does not need to be compiled.
In order to make the aforementioned objects, features and advantages of the present disclosure more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, not all of the embodiments. The components of the embodiments of the present disclosure, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure, presented in the figures, is not intended to limit the scope of the claimed disclosure, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the disclosure without making creative efforts, shall fall within the protection scope of the disclosure.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The term "and/or" herein merely describes an associative relationship, meaning that three relationships may exist, e.g., a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B, C, and may mean including any one or more elements selected from the group consisting of A, B and C.
In order to solve the technical problem of computing resource waste caused by repeated compiling of a large number of codes, the disclosure provides a compiling method, compiling products are matched by relying on description information and attribute information of object codes, and the matched compiling products are used as compiling results of the object codes, so that the object codes do not need to be compiled, the effect of saving computing resources is achieved, and the efficiency of obtaining the compiling products is improved as the object codes do not need to be compiled.
To facilitate understanding of the present embodiment, first, a compiling method disclosed in the embodiments of the present disclosure is described in detail, where an execution subject of the compiling method provided in the embodiments of the present disclosure is generally a computer device with certain computing capability, and the computer device includes, for example: terminal equipment or servers or other processing devices. In some possible implementations, the compilation method may be implemented by a processor calling computer-readable instructions stored in a memory.
Referring to fig. 1, a flowchart of a compiling method provided in the embodiment of the present disclosure is shown, where the method includes steps S101 to S103, where:
s101, obtaining an object code to be compiled, and determining dependency description information required by compiling the object code.
In this step, the object code to be compiled may be a complete code of an application program or a partial code. When compiling the object code, information of a file on which the object code depends is usually required, and if the dependent file is different, the compiled executable file is also different, so that the dependency description information required for compiling the object code can be determined.
For example, the object code may be pre-compiled, only codes related to a dependent file in the object code are compiled, and a real dependent file of a file corresponding to the current object code may be generated, where the file corresponding to the object code may be a cpp file, which may be a file directly written by a developer, and the real dependent file may be a d file, that is, a dependent description file, where the dependent description file may include header information of each dependency required for compiling the object code, and the header information is extracted from the dependent description file and may be used as the dependent description information. The header file may be an h file.
S102, determining the compiling identification of the object code based on the dependency description information and the attribute information of the object code.
In this step, the obtained dependency description information and the attribute information of the object code are utilized to determine a compiling identifier of the object code, the compiling identifier may be a unique identifier of the object code and may represent the dependency description information and the attribute information of the object code, if the compiling identifiers of the two codes are completely the same, the two codes themselves may be considered to be completely the same, and the compiling products of the two codes may also be mutually common.
Wherein the attribute information of the object code may include at least one of:
the system comprises a body file of the object code, a head file of the object code, a compiler version corresponding to the object code and an environment variable corresponding to the object code.
The attribute information and the dependency description information describe the characteristics of the object code and the compiling process to a certain extent, for example, the body file contains the code to be compiled, the header file can describe each part in the object code, the compiler version influences the compiling process, and the environment variable influences the compiling process and the compiling product.
Illustratively, the compiled identity of the object code may be determined by:
determining a hash value corresponding to the dependency description information and the attribute information based on the dependency description information and the attribute information of the target code;
and taking the determined hash value as the compiling identification of the object code.
In this step, the hash value of the dependency description information and the attribute information of the object code is calculated, the hash value itself represents the characteristics of the information, and the characteristics of the dependency description information and the attribute information are identified by the hash value, which can also represent the characteristics of the object code and the compiling process.
S103, inquiring a compiling product matched with the compiling identification from the database, and taking the inquired compiling product as a compiling result of the target code.
After the compiling identification of the object code is determined, a compiling product matched with the compiling identification can be inquired in a database, the compiling product in the database can be a compiling product stored after being compiled by local or other terminal equipment, the compiling product can carry the compiling identification of the corresponding source code, matching can be carried out by comparing the object code with the compiling identification of each compiling product, if the compiling identifications of the object code and the compiling product are the same, the source code of the compiling product can be determined to be the same as the compiling process of the object code, the compiling products can be mutually universal, and the inquired compiling product can be used as the compiling result of the object code.
The database may be a local database, or may be a remote database, such as a distributed cache database or a cloud cache database. The query request aiming at the compiling identification can be sent to a remote database, and the remote database can perform query matching on the compiling product according to the compiling identification indicated by the query request and feed back the queried compiling product.
Furthermore, if the database does not have a compilation product matched with the compilation identifier of the object code, a local compiler can be called to compile the object code to obtain a compilation result of the object code.
After the compilation is completed, the obtained compilation result can be stored in the database together with the compilation identifier so as to be used when the object code is compiled again.
Referring to fig. 2, another compiling method provided for the embodiment of the disclosure includes executing a packed instruction xcodebuild on a computer device, where the computer device may run a Continuous building system (CI), and the xcodebuild is an instruction in an Xcode integrated development tool in the CI system, and in a normal case, the Xcode tool may only use a local cache, and may obtain a compiled product stored in a remote database by modifying a default compiler clang and replacing the compiler clang with a compiler dedicated to the remote database, and after the packed instruction is run, the computer device may call a compiler corresponding to a remote processor to determine a compiled identifier of a target code, and then search a compiled product matching the compiled identifier from the local database and/or the remote database, and if the compiled product is found, obtain the matched compiled product, and use the obtained compiled product as a compiling result of the target code, if not, executing the compiling logic to compile the object code.
According to the compiling method provided by the embodiment of the disclosure, firstly, an object code to be compiled is obtained, and dependency description information required by compiling the object code is determined; then, based on the dependency description information and the attribute information of the object code, determining a compiling identification of the object code; and finally, inquiring the compiling product matched with the compiling identification from the database, and taking the inquired compiling product as the compiling result of the target code. According to the embodiment of the disclosure, the compiling product is matched by depending on the description information and the attribute information of the object code, and the matched compiling product is used as the compiling result of the object code, so that the object code does not need to be compiled, the effect of saving computing resources is realized, and the efficiency of obtaining the compiling product is improved because the object code does not need to be compiled.
It will be understood by those skilled in the art that in the method of the present invention, the order of writing the steps does not imply a strict order of execution and any limitations on the implementation, and the specific order of execution of the steps should be determined by their function and possible inherent logic.
Based on the same inventive concept, a compiling device corresponding to the compiling method is also provided in the embodiments of the present disclosure, and since the principle of solving the problem of the device in the embodiments of the present disclosure is similar to that of the compiling method in the embodiments of the present disclosure, the implementation of the device may refer to the implementation of the method, and repeated details are not repeated.
Referring to fig. 3, a schematic diagram of a compiling apparatus provided in the embodiment of the present disclosure is shown, where the apparatus includes:
an obtaining module 310, configured to obtain an object code to be compiled, and determine dependency description information required for compiling the object code;
a determining module 320, configured to determine a compiling identifier of the object code based on the dependency description information and the attribute information of the object code;
and the query module 330 is configured to query the compiled product matching the compiling identifier from the database, and use the queried compiled product as the compiling result of the target code.
In an optional implementation manner, the determining module 320 is specifically configured to:
determining a hash value corresponding to the dependency description information and the attribute information based on the dependency description information and the attribute information of the target code;
and taking the determined hash value as the compiling identification of the object code.
In an alternative embodiment, the obtaining module 310, when determining the dependency description information required for compiling the object code, is configured to:
performing pre-compiling processing on the object code to obtain a dependency description file of the object code; the dependency description file comprises header file information of each dependency required for compiling the object code;
and taking each piece of header file information in the dependency description file as the dependency description information.
In an optional embodiment, the attribute information of the object code includes at least one of:
the system comprises a body file of the object code, a header file of the object code, a compiler version corresponding to the object code and an environment variable corresponding to the object code.
In an optional embodiment, the apparatus further comprises a compiling module configured to:
and if the compiling product matched with the compiling identifier does not exist in the database, calling a compiler corresponding to the object code to compile the object code to obtain a compiling result of the object code.
In an optional embodiment, the compiling module is further configured to:
and storing a compiling result obtained by compiling into the database as a compiling product matched with the compiling identification.
In an alternative embodiment, the query module 330, when querying the database for the compilation product matching the compilation identifier, is configured to:
inquiring a compiling product matched with the compiling identification from a local database; alternatively, the first and second electrodes may be,
and sending a query request aiming at the compiling identification to a server corresponding to a remote database so that the server queries from the database and feeds back a compiling product matched with the compiling identification.
The description of the processing flow of each module in the device and the interaction flow between the modules may refer to the related description in the above method embodiments, and will not be described in detail here.
Corresponding to the compiling method in fig. 1, an electronic device 400 is further provided in the embodiment of the present disclosure, as shown in fig. 4, a schematic structural diagram of the electronic device 400 provided in the embodiment of the present disclosure includes:
a processor 41, a memory 42, and a bus 43; the memory 42 is used for storing execution instructions and includes a memory 421 and an external memory 422; the memory 421 is also referred to as an internal memory, and is used for temporarily storing the operation data in the processor 41 and the data exchanged with the external memory 422 such as a hard disk, the processor 41 exchanges data with the external memory 422 through the memory 421, and when the electronic device 400 operates, the processor 41 communicates with the memory 42 through the bus 42, so that the processor 41 executes the following instructions:
acquiring an object code to be compiled, and determining dependency description information required by compiling the object code;
determining a compiling identification of the object code based on the dependency description information and the attribute information of the object code;
and inquiring the compiling product matched with the compiling identification from a database, and taking the inquired compiling product as the compiling result of the target code.
In an alternative embodiment, the determining the compiled identity of the object code based on the dependency description information and the attribute information of the object code in the instructions executed by the processor 41 includes:
determining a hash value corresponding to the dependency description information and the attribute information based on the dependency description information and the attribute information of the target code;
and taking the determined hash value as the compiling identification of the object code.
In an alternative embodiment, the determining, in the instructions executed by the processor 41, the dependency description information required for compiling the object code includes:
performing pre-compiling processing on the object code to obtain a dependency description file of the object code; the dependency description file comprises header file information of each dependency required for compiling the object code;
and taking each piece of header file information in the dependency description file as the dependency description information.
In an alternative embodiment, in the instructions executed by the processor 41, the attribute information of the object code includes at least one of:
the system comprises a body file of the object code, a header file of the object code, a compiler version corresponding to the object code and an environment variable corresponding to the object code.
In an optional embodiment, the processor 41 is further configured to:
and if the compiling product matched with the compiling identifier does not exist in the database, calling a compiler corresponding to the object code to compile the object code to obtain a compiling result of the object code.
In an optional embodiment, the processor 41 is further configured to:
and storing a compiling result obtained by compiling into the database as a compiling product matched with the compiling identification.
In an alternative embodiment, the processor 41 executes instructions to query the database for the compilation product matching the compilation identifier, including:
inquiring a compiling product matched with the compiling identification from a local database; alternatively, the first and second electrodes may be,
and sending a query request aiming at the compiling identification to a server corresponding to a remote database so that the server queries from the database and feeds back a compiling product matched with the compiling identification.
The embodiments of the present disclosure also provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the computer program performs the steps of the compiling method described in the above method embodiments. The storage medium may be a volatile or non-volatile computer-readable storage medium.
The embodiments of the present disclosure also provide a computer program product, where the computer program product carries a program code, and instructions included in the program code may be used to execute the steps of the compiling method in the foregoing method embodiments, which may be referred to specifically in the foregoing method embodiments, and are not described herein again.
The computer program product may be implemented by hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK), or the like.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working process of the apparatus described above may refer to the corresponding process in the foregoing method embodiment, and is not described herein again. In the several embodiments provided in the present disclosure, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above-mentioned embodiments are merely specific embodiments of the present disclosure, which are used for illustrating the technical solutions of the present disclosure and not for limiting the same, and the scope of the present disclosure is not limited thereto, and although the present disclosure is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive of the technical solutions described in the foregoing embodiments or equivalent technical features thereof within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present disclosure, and should be construed as being included therein. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.