Compiling method, electronic equipment and computer readable storage medium
By detecting source file updates that do not affect the compilation steps in code access control, the affected compilation targets are accurately compiled, and the resource waste and time consumption problems caused by full compilation are solved, and faster code verification and online are achieved.
Patent Information
- Application Number
- CN202510117171.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-24
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2045-01-24
AI Technical Summary
The full compilation method in code access control results in unnecessary compilation processes, wasting compile resources and spending a lot of time.
By detecting that the source file that does not affect the compilation steps is updated, the modification information is obtained and the compilation target affected by the update is accurately compiled to verify whether the modified source file can be compiled.
It reduces the number of targets that are recompiled during the compilation verification process, saves compilation resources, shortens compilation time, and enables source files to pass code access control faster, improving the code online speed.
Smart Images

Figure CN119556941A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a compilation method, an electronic device, and a computer-readable storage medium. Background Art
[0002] Code gate is widely used in the software development process. Code gate is a measure to ensure code quality and security. It requires that the code submitted by developers must meet specific requirements before it can be merged into the main branch. The above specific requirements may include passing compilation, reaching the unit test coverage standard, no warnings in code static inspection, passing all smoke test cases, etc.
[0003] Currently, the compilation method in Code Gate is full compilation, that is, once the code or configuration file is modified, the entire component needs to be recompiled according to the version build method, which involves many unnecessary compilation processes, wastes compilation resources, and takes a lot of time. Summary of the invention
[0004] The embodiments of the present application provide a compilation method, an electronic device, and a computer-readable storage medium, which can shorten the compilation time and save compilation resources by reducing unnecessary compilation processes without affecting the correctness of the verification program.
[0005] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0006] In the first aspect, the present application provides a compilation method, which can obtain modification information when it is detected that a source file that does not affect the compilation step is updated. The above-mentioned source file that does not affect the compilation step can also be called a source file with undefined compilation dependencies, which can include code files and configuration files involved in the compilation, as well as code files and configuration files that do not participate in the compilation, but does not include a build rule file. The above-mentioned modification information includes the updated source file (referred to as a modified file). The electronic device stores dependency information, which includes a dependent file and a compilation target corresponding to the dependent file, and the compilation target corresponding to the dependent file is a compilation target that depends on the dependent file. Then, the electronic device can query the compilation target corresponding to each modified file from the dependency information to obtain a first target, and the compilation target corresponding to the modified file is a compilation target that depends on the modified file. Finally, the electronic device compiles the first target to verify whether the modified source file can pass the compilation. It can be understood that the first target is a compilation target affected by the update, so compiling the first target can verify whether the modified source file can pass the compilation, that is, achieve the same verification effect as compiling the source file in full. In addition, only compiling the first target reduces the number of targets that are recompiled during the compilation verification process compared to the full compilation, so it can save compilation resources and shorten the compilation time.
[0007] In an implementation manner provided in the first aspect, the compilation target corresponding to the above-mentioned dependent file may also include the first-category target among all the compilation targets that depend on the dependent file, and the first-category target is a compilation target that is not depended on by other compilation targets. It can be understood that in the process of compiling the first-category target, all the compilation targets that the first-category target depends on will be compiled. Therefore, the compilation result obtained by compiling all the first-category targets is the same as the compilation result obtained by fully compiling the code file. In other words, there is no dependency relationship between the first targets queried by the dependency information provided by this implementation. Compared with the first targets queried by the above method, there may be dependencies between each other. The number of first targets queried by this method is smaller, which can further save compilation resources and shorten compilation time, so that the source file can pass the code access control faster and improve the speed of code launch.
[0008] In an implementation manner provided in the first aspect, before the electronic device obtains the first target from the dependency information, the electronic device may also obtain a dependency relationship file and generate the above dependency information according to the dependency relationship file, wherein the dependency relationship file is used to indicate the dependency relationship between the compilation targets. That is, if the dependency relationship file is updated, the dependency information will be updated.
[0009] In one implementation provided in the first aspect, when the electronic device generates the above-mentioned dependency information, the effective compilation target can be determined from the actual compilation product according to the dependency file. Among them, the actual compilation product includes the main product and the by-product obtained by the actual compilation, and the effective compilation target includes the main product obtained by the actual compilation, and the main product includes the compilation result defined by the dependency, such as the compilation target obtained by the actual compilation. The by-product is a compilation result that is not defined by the dependency, specifically a compilation result generated in the process of generating the main product. Then, the electronic device can determine the dependent files of each effective compilation target according to the dependency file, and establish a mapping relationship between each dependent file and the effective compilation target that depends on the dependent file to obtain the dependency information. This process of generating dependency information is relatively simple, and can improve the efficiency of the electronic device in generating dependency information.
[0010] In an implementation provided in the first aspect, when the electronic device generates the above-mentioned dependency information, it can also determine the effective compilation target from the actual compilation product according to the dependency file, and then determine the first category of targets from the effective compilation targets according to the dependency file, the first category of targets being compilation targets that are not dependent on other compilation targets, and then determine the dependent files of each first category of targets according to the dependency file, and finally establish a mapping relationship between each dependent file and the first category of targets that depend on the dependent file to obtain the dependency information. In the dependency information generated in this way, the number of compilation targets corresponding to each dependent file is smaller, which can reduce the number of compilation targets verified during the compilation verification process, which is conducive to improving compilation efficiency.
[0011] In an implementation manner provided in the first aspect, when determining the above-mentioned first-category target, the electronic device may establish a dependency correspondence table according to the dependency relationship file, the dependency correspondence table including multiple groups of key-value pairs, each group of key-value pairs using a compilation target as a key and a compilation target of a dependent compilation target as a value. Then, using each valid compilation target as a key, query whether there is a value corresponding to the valid compilation target in the dependency correspondence table, and if there is a value corresponding to the valid compilation target in the dependency correspondence table, determine that the valid compilation target is a first-category target.
[0012] In an implementation provided in the first aspect, when determining the above-mentioned first-category target, the electronic device can use the compilation targets involved in the dependency file as nodes, establish an edge connecting two nodes corresponding to the two compilation targets based on the dependency relationship between the two compilation targets, and obtain a dependency graph; wherein the dependency graph includes leaf nodes, and the compilation targets corresponding to the leaf nodes are not dependent on other compilation targets. Then, the intersection of the compilation targets corresponding to the leaf nodes and the valid compilation targets is determined as the first-category target.
[0013] In an implementation manner provided in the first aspect, when determining the above-mentioned effective compilation target, the electronic device can determine the expected compilation product according to the dependency file, and the expected compilation product includes all the compilation targets involved in the dependency file. Then, the actual compilation product is obtained by querying under the preset compilation product path, and then the intersection of the expected compilation product and the actual compilation product is determined as the effective compilation target.
[0014] In an embodiment provided in the first aspect, the electronic device may determine whether it detects that a source file that does not affect the compilation step has been updated by the following method: when it detects that the source file has been updated, it determines whether the build rule file has been updated; if the build rule file has not been updated, it determines that it detects that a source file that does not affect the compilation step has been updated.
[0015] In a second aspect, an embodiment of the present application provides an electronic device, comprising: a memory and a processor; the processor is coupled to the memory; wherein the memory is used to store computer program code, and the computer program code comprises computer instructions; when the computer instructions are executed by the processor, the electronic device executes the method described in the first aspect and any one of its embodiments.
[0016] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, including computer instructions; when the computer instructions are executed on an electronic device, the electronic device executes the method described in the first aspect and any one of its embodiments.
[0017] In a fourth aspect, an embodiment of the present application provides a computer program product, including computer instructions; when the computer instructions are executed on an electronic device, the electronic device executes the method described in the first aspect and any one of its embodiments.
[0018] Among them, the technical effects brought about by any implementation method in the second to fourth aspects can refer to the technical effects brought about by different design methods in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 A schematic diagram of the structure of a development system provided in an embodiment of the present application;
[0020] Figure 2 A flowchart of a compilation method provided in an embodiment of the present application;
[0021] Figure 3 A flowchart of another compilation method provided in an embodiment of the present application;
[0022] Figure 4 A schematic diagram of the structure of an Android construction system provided in an embodiment of the present application;
[0023] Figure 5 A dependency diagram provided for an embodiment of the present application;
[0024] Figure 6 A flowchart of another compilation method provided in an embodiment of the present application;
[0025] Figure 7 A schematic diagram of the structure of a chip system provided in an embodiment of the present application;
[0026] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this embodiment, unless otherwise specified, "plurality" means two or more.
[0028] Meanwhile, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete manner for ease of understanding.
[0029] In order to facilitate the understanding of this article, the relevant prior art is first introduced below.
[0030] Compilation is the process of converting source code written in one programming language into object code in another programming language or machine language.
[0031] A compiler is a computer program that converts source code into target code (i.e., performs compilation) and builds a software project, such as an executable file, a library file, or an intermediate representation (IR).
[0032] The compilation target is the final output of the compilation, and is also the final product generated by the compiler based on the source code. Depending on the purpose and requirements of the compilation, the compilation target can be the above executable file, library file, or intermediate representation, etc.
[0033] Version building refers to the process of compiling and packaging software according to specific version numbers or version tags during the software development process.
[0034] Dependency refers to the situation where a compilation target needs to rely on other compilation targets or files in the process of building a compilation target. For example, compilation target A depends on compilation target B, which means that compilation target A needs to be compiled after compilation target B, and as long as compilation target B is recompiled, compilation target A also needs to be recompiled. For another example, compilation target B depends on source file C, then as long as source file C is changed, compilation target B needs to be recompiled. For another example, compilation target B depends on compilation target D, and compilation target D depends on source file E. If source file E is changed, the compilation target will be recompiled, which will further cause compilation target B to be recompiled.
[0035] The embodiment of the present application provides a compilation method, which is applied to the compilation verification process, wherein the compilation verification process refers to the process of verifying whether the compilation target can be compiled after the code or configuration file is modified.
[0036] See also Figure 1 , is a schematic diagram of the structure of a development system provided in an embodiment of the present application. Figure 1 As shown, the development system includes a data center and multiple terminals (such as Figure 1 The data center can communicate with the terminals through a network, which can be the Internet or other networks. The network can include one or more network devices, such as a router or a switch.
[0037] A data center consists of one or more servers, such as Figure 1 The server 120 shown is, for example, a server that can provide a compilation function. In an optional scenario, the server 120 refers to a server cluster in which multiple servers are deployed, and the server cluster may have a rack, and the rack may establish communication for the multiple servers through a wired connection, such as a universal serial bus (USB) or a peripheral component interconnect express (PCIe) high-speed bus.
[0038] The server 120 may also obtain a source file from a terminal, compile the source file, and send the compilation result to the corresponding terminal.
[0039] in addition, Figure 1 The data center shown may also include other physical devices with compilation functions, such as mobile phones, tablet computers or other devices.
[0040] The above-mentioned terminal may also be referred to as terminal equipment, user equipment (UE), mobile station (MS), mobile terminal (MT), etc. The terminal may be a mobile phone, tablet computer, desktop, laptop or handheld computer, notebook computer, ultra-mobile personal computer (UMPC), netbook, cellular phone, personal digital assistant (PDA), augmented reality (AR)\virtual reality (VR) equipment and other equipment capable of processing data. The embodiments of the present application do not impose any special restrictions on the specific form of the terminal.
[0041] As a measure to ensure code quality and security, code gate is widely used in the software development process. Code gate requires that the code submitted by the developer must meet the requirements before it can be merged into the code repository. The above requirements may include passing the compilation and meeting the unit test coverage standards. Among them, the compilation method in code gate is full compilation, that is, each compilation needs to recompile the entire component according to the version build method. Components such as system, chipset, modem, recovery, and energy are any one of them. However, this compilation method has the problem of wasting compilation resources during the compilation verification process. The specific reasons are as follows:
[0042] (1) Even when the scope of modification of the newly submitted code is small, for example, only a few lines of code or a few source files are modified, the entire component still needs to be compiled, resulting in many compilation processes that are not related to the modification, a large number of redundant build processes, and a waste of compilation resources.
[0043] (2) When the newly submitted code modifies the configuration file and the configuration file (such as README.txt) does not participate in the compilation process, the configuration file still needs to be compiled, wasting compilation resources.
[0044] To at least solve the above problems, the present application provides a compilation method that can be applied to the above server 120. When the server 120 detects that a source file without a defined compilation dependency is updated, it can accurately compile the compilation target (referred to as the first target) affected by the update.
[0045] It can be understood that since the first target is the compilation target affected by the source file update, compiling the first target can verify whether the modified source file can pass the compilation, that is, it can achieve the same verification effect as compiling the source file in full. In addition, compiling only the first target reduces the number of targets that are recompiled during the compilation verification process compared to compiling in full, so it can save compilation resources and shorten compilation time.
[0046] The following will describe in detail the compilation method provided by the embodiment of the present application with reference to the accompanying drawings.
[0047] See also Figure 2 , which is a flowchart of the compilation method provided in the embodiment of the present application, can be applied to Figure 1 The server 120 in FIG. Figure 2 As shown, the compilation method at least includes S201 to S206.
[0048] S201, update source files.
[0049] The source files include code files, configuration files, and build rule files. Code files include source code for implementing software functions. It should be noted that the format of code files may be different depending on the development environment. For example, if the development environment is the Android® system, the format of the code file may be ".java", ".c", or ".cpp".
[0050] Configuration files are files used to store settings and preferences for software programs. They can be used to adjust the behavior of a program without modifying the code. For example, configuration files can define the environment variables required for the program to run. Build rule files are used to define build logic, which includes build rules, dependencies, compilation options, etc. in the process of building a software project from source code. It can be understood that build rule files are source files that control the compilation steps. In addition, configuration files and build rule files can be manually written by developers.
[0051] The format of the build rule file can be different depending on the compilation framework. For example, in the soong framework, the build rule file can be an Android.bp file; in the CMake framework, the build rule file can be a CMakeLists.txt file; in the make-based framework, the build rule file can be an Android.mk file.
[0052] It should be noted that the update source file may be at least one of an update code file, a configuration file, and a build rule file. Also, the source file may be uploaded to the server 120 by a developer through a terminal, i.e., received by the server 120; or may be generated by a developer using the server 120, which is not specifically limited here.
[0053] S202, determining whether the build rule file is updated.
[0054] If the build rule file is not updated, S203 is executed; if the build rule file is updated, S206 is executed.
[0055] It is understandable that if the build rule file is updated, it means that the update of the source file will change the compilation steps and / or rules, and the source file needs to be fully compiled according to the steps and rules indicated by the updated build rule file, so S206 is executed. If the build rule file is not updated, it means that the update of the source file will not affect the compilation steps and rules, and only the compilation targets affected by the update can be recompiled, so S203 is executed.
[0056] In a possible design, when the timestamp of the build rule file is later than the timestamp of the compilation target obtained by compiling based on the build rule file, the server 120 may determine that the build rule file is updated.
[0057] S203, obtaining modification information, where the modification information includes an updated source file (which may be referred to as a modified file).
[0058] In one possible design, server 120 may compare source files before and after the update to obtain modified files.
[0059] In another possible design, for each file in the source file, the server 120 can compare the timestamp 1 of the file with the timestamp 2 of the compilation target that depends on the file. If the timestamp 1 is later than the timestamp 2, it can be determined that the file is updated, that is, the file is a modified file. For example, target a depends on source file 1. If the timestamp of source file 1 is later than the timestamp of target a, it can be determined that source file 1 is updated, that is, source file 1 is a modified file. This method only requires comparing the timestamps of the two files, which saves more computing resources and improves processing efficiency compared to comparing the source files before and after the update.
[0060] S204, querying the compilation target corresponding to each modified file from the dependency information to obtain a first target, wherein the dependency information includes the dependent files and the compilation targets corresponding to the dependent files.
[0061] Among them, the dependent file includes a source file that is dependent on at least one compilation target. The compilation target corresponding to the dependent file includes the compilation target that depends on the dependent file. It should be noted that the compilation target corresponding to the dependent file may include the compilation target that directly depends on the dependent file, and the compilation target that indirectly depends on the dependent file. For example, the dependent file is an ac file, where target 1 depends on the ac file, target 2 depends on target 1, and target 3 depends on target 2. Then, target 1 directly depends on the ac file, and target 2 and target 3 indirectly depend on the ac file. Target 1, target 2 and target 3 are all compilation targets corresponding to the ac file.
[0062] It can be understood that modification of a dependent file will cause its corresponding compilation target to be recompiled during the compilation verification process.
[0063] In a possible implementation, the dependency information may be presented in a table. For example, the dependency information may be as shown in Table 1.
[0064] Table 1
[0065]
[0066] According to Table 1 above, the dependent files include source files such as ac, b.cpp and c.cpp. Among them, the compilation targets corresponding to source file ac include target 1, target 2 and target 3. The compilation targets corresponding to source file b.cpp include target 4. The compilation targets corresponding to source file c.cpp include target 5 and target 6.
[0067] Taking the example that the modification information indicates that the modified files include source file b.cpp and source file c.cpp, the server 120 may determine, based on Table 1 above, that the first target includes target 4, target 5, and target 6.
[0068] It should be noted that the dependency information shown in Table 1 is only an example, and the actual dependency information may include more content than that shown in Table 1. In other embodiments, the dependency information may also be presented in other ways, for example, the dependency information may also exist in the form of a hash table. In the above hash table, the hash value of the dependency file is the key, and the hash value of the compilation target is the value. Presenting the above dependency information in the form of a hash table can increase the query speed and improve the efficiency of the server 120 in determining the first target.
[0069] S205, compile the first target.
[0070] In the process of compiling the first target, the server can compile the source files that the first target depends on in the correct order.
[0071] S206, compile source files.
[0072] The server 120 may fully compile the source file according to the compilation process indicated by the build rule file.
[0073] The compilation method provided in the embodiment of the present application can compile only the compilation target affected by the update (i.e., the first target mentioned above), reducing the number of targets to be recompiled during the compilation verification process, thereby saving compilation resources and shortening compilation time.
[0074] For example, when the user modifies the source files b.cpp and c.cpp in Table 1 and then performs compilation verification, the solution provided by the prior art is to compile the source files a.cpp, b.cpp, and c.cpp (i.e., perform full compilation), which requires recompiling targets 1 to 6. In the solution provided by the present application, the server 120 only needs to recompile targets 4, 5, and 6, which reduces the number of targets to be recompiled, saves compilation resources, and shortens compilation time.
[0075] In an optional implementation, the compilation targets corresponding to the above-mentioned dependent file include compilation targets that are not dependent on any compilation target among all compilation targets that depend on the file.
[0076] Still taking the above Table 1 as an example, target 1 depends on source file ac, target 2 depends on target 1, target 3 depends on target 2; target 5 depends on source file c.cpp, and target 6 depends on target 5. Therefore, the compilation targets that depend on source file ac include target 1, target 2, and target 3, wherein target 1 is dependent on target 2, target 2 is dependent on target 3, and target 3 is not dependent on any compilation target, so the compilation targets corresponding to source file ac include target 3. And, the compilation targets that depend on source file c.cpp include target 5 and target 6, wherein target 5 is dependent on target 6, and target 6 is not dependent on any compilation target, so the second target corresponding to source file c.cpp includes target 6. In this case, the dependency information can be shown in Table 2.
[0077] Table 2
[0078]
[0079] Still taking the example that the modification information indicates that the modified files include source file b.cpp and source file c.cpp, the server 120 can determine, according to Table 2, that the first target includes target 4 and target 6.
[0080] It is understandable that changes in source file ac will directly affect target 1, changes in target 1 will affect target 2, and changes in target 2 will affect target 3. Therefore, during compilation verification, recompiling target 3 will also lead to recompiling targets 1 and 2, and recompiling target 2 will also lead to recompiling target 1. In other words, recompiling target 3 can achieve the effect of recompiling source file ac. Similarly, recompiling target 6 will also lead to recompiling target 5, that is, recompiling target 6 can achieve the effect of recompiling source file c.cpp.
[0081] That is, the server 120 can achieve the same verification effect as compiling targets 4, 5, and 6 by compiling targets 4 and 6. In this way, the number of targets to be recompiled during the compilation verification process can be further reduced, compiling resources can be saved, and compiling time can be shortened, so that source files can pass the code gate faster, and the speed of code launch can be improved.
[0082] In order to improve the efficiency of compiling and verifying the server 120, the server 120 may generate dependency information in advance before executing S201 to S206. Figure 3-Figure 6 The specific process of the server 120 generating dependency information is introduced.
[0083] See also Figure 3 , is a flowchart of another compilation method provided in an embodiment of the present application, applied to Figure 1 The server 120 shown in FIG. 1 specifically introduces the specific process of the server 120 generating dependency information. Figure 3 As shown, the compilation method also includes S301~S305.
[0084] S301, generating a dependency relationship file based on the build rule file.
[0085] The dependency file includes the build rules, commands, build process and required parameters of the compilation target, which are used to indicate the dependencies between the compilation targets. The compiler can determine the compilation order and execute the build task according to the dependencies between the compilation targets.
[0086] The dependency file can be generated by the build system of the server 120 based on the build rule file. It should be noted that the process of generating the dependency file is different under different build systems. In the embodiment of the present application, the build system of the server 120 is an Android (Android®) build system as an example to exemplarily illustrate the process of the server 120 generating the dependency file based on the build rule file.
[0087] See also Figure 4 , a schematic diagram of the structure of the Android® building system. Figure 4 As shown, the Android build system includes components such as blueprint, soong, kati, and ninja. In the embodiment of the present application, the build rule file may include an Android.bp file and an Android.mk file, and the description languages and description methods used by the Android.bp file and the Android.mk file are different.
[0088] The blueprint component can parse the format of the Android.bp file, convert the declarations in the Android.bp file into a structure that the soong component can understand, and obtain the parsed Android.bp file (for example, called Android1.bp file). The soong component can parse the content of the Android1.bp file and generate a ninja file 1, which contains all the build rules and dependencies defined in the Android1.bp file.
[0089] The kati component is a make (build) cloning tool specifically used for the Android build system. The kati component can parse the contents of the Android.mk file and generate a ninja file 2, which contains all the build rules and dependencies defined by the Android.mk file. Optionally, the kati component can be replaced with the Ckati component. The difference between the kati component and the Ckati component is that the kati component is written in Go language, while the Ckati component is written in C++ language.
[0090] The ninja component can merge the above ninja file 1 and ninja file 2 to obtain a dependency file (for example, combined-xxx.ninja), and compile source code based on the dependency file to build a compilation target. It should be noted that in other implementations, other components of the Android build system can also merge the above ninja file 1 and ninja file 2 to obtain a dependency file.
[0091] Exemplarily, the dependency file may include the following content 1:
[0092] cflags=-Wall
[0093] rule cc
[0094] command=gcc $cflags-c$in-o$out
[0095] build foo.o:cc foo.c
[0096] Among them, cflags is a global parameter, which is assigned to -Wall. rule cc defines the build rule cc. command defines the specific command of rule cc, that is, compiles the input variable ($in) and generates the output variable ($out). buildfoo.o:cc foo.c is used to define the build process, which means that when building foo.o, foo.c needs to be compiled according to rule cc. In other words, according to the dependency file of the above example: when rule cc is triggered, the compiler of server 120 needs to compile the input variable foo.c to obtain the compilation target foo.o (that is, the output variable).
[0097] The server 120 can identify the dependency from the dependency file. According to the definition of the dependency in the dependency file, the dependency can be divided into explicit dependency and implicit dependency. Accordingly, the files that the compilation target depends on (which can be referred to as dependency files) can be divided into explicit dependency files and implicit dependency files.
[0098] Among them, explicit dependency files can be listed in the build line and can act as $in variables (input variables) in the rules. A build line can refer to a line of code used to define the build process, such as the "build foo.o:ccfoo.c" mentioned above. In addition, "build foo.o:cc foo.c" indicates that when building foo.o, foo.c needs to be compiled according to the rule cc, that is, foo.c is the file listed in the build line. Therefore, foo.c is an explicit dependency file of foo.o, or it can be expressed as: foo.o depends on foo.c, and the dependency relationship is an explicit dependency.
[0099] Implicit dependencies can be obtained from the depfile property in a rule, or from the syntax at the end of a build line. Implicit dependencies are not used as $in variables.
[0100] Exemplarily, the dependency file may also include the following content 2:
[0101] rule rule1
[0102] depfile=out / target / product / abc.d
[0103] deps=gcc
[0104] command=xxxxx
[0105] build out / target / product / abc.o:rule1 foo.c
[0106] A simple comparison between content 1 and content 2 shows that both content 2 and content 1 define the rules, instructions, and processes for building compilation targets. The difference is that content 2 also includes a depfile line. The depfile line is used to specify the storage path for storing depfile. Depfile is a dependency file generated during the compilation process, which records the dependencies between source files and the various compiler flags and preprocessing options required to compile each source file. When the depfile changes, it means that the dependencies between source files have changed, and the compilation target also needs to be recompiled. In addition, depfile (i.e., abc.d) will not be used as the $in variable. In other words, the compilation target abc.o in content 2 not only has an explicit dependency file (i.e., foo.c), but also an implicit dependency file (i.e., abc.d). It should be noted that the "xxxxx" in the command line above is only for reference and has no real meaning.
[0107] As another example, the dependency file may also include the following content 3:
[0108] rule rule2
[0109] command=xxxxx
[0110] build $
[0111] out / soong / intermediates / java1.jar $
[0112] : g.java.turbine$
[0113] out / soong / intermediates / P.java $
[0114] $(g.android.soong.java.config.TurbineJar) $
[0115] $(g.android.soong.java.config.ZipTime) $
[0116] out / soong / intermediates / modules $
[0117] out / soong / intermediates / Q.jar $
[0118] out / soong / intermediates / release $
[0119] build out / target / product / abcd.o:rule2 foo.c
[0120] According to the above content 3, modules, Q.jar, release and other files are all dependent files in the process of building the compilation target abcd.o, but these files will not be used as the $in variable of the commmd command when compiling the commmd line. Therefore, modules, Q.jar, release and other files are implicit dependent files of the compilation target abcd.o.
[0121] It should be noted that no matter which of the above methods is used to define the dependency relationship, once the dependency file of the compilation target changes, the compilation target needs to be recompiled during the compilation verification process.
[0122] It should also be noted that the server 120 can generate a dependency file according to the build rule file when it detects that the build rule file has changed. That is to say, every time the user updates the build rule file, the server 120 can generate a dependency file once.
[0123] S302. Determine valid compilation targets from the actual compilation products according to the dependency file.
[0124] In the embodiments of the present application, the compilation products include main products and by-products. Among them, the main products include the compilation results clearly defined in the dependency file, that is, the above-mentioned compilation targets. For example, the foo.o file, abc.o file, and abcd.o file defined by the build instruction in the above-mentioned dependency file. The by-products include the compilation results other than the main products generated incidentally during the process of building the main products, and there is no clear definition of them in the dependency file.
[0125] Exemplarily, during the execution of the compilation command of the jar package, in addition to generating the main product ".jar" file, ".class" files and dynamically generated source code files will also be generated, where the ".class" files and dynamically generated source code files are both by-products.
[0126] Another example is that during the Javac compilation, the following instructions can be used to generate by-products not defined by any dependencies. Among them, Javac is the compiler of the Java programming language.
[0127] -d <directory>, used to specify the directory for storing the generated class files. For example, -d <out / soong / .intermediates / class> indicates that the generated class files will be stored in the out / soong / .intermediates / class directory.
[0128] -s <directory>, used to specify the directory for storing the generated source files. For example, -s <out / soong / .intermediates / source> indicates that the generated source files will be stored in the out / soong / .intermediates / source directory.
[0129] -h <directory>, used to specify the directory for storing the generated local header files. For example, -h <out / soong / .intermediates / header> indicates that the generated local header files will be stored in the out / soong / .intermediates / header directory.
[0130] In addition to the above examples, class files dynamically generated by resource files (such as R.java), interface definition files such as Android interface definition language (AIDL) source files, dynamically generated header files (suffixed with ".h"), temporary files generated during the compilation of JAVA source files (suffixed with ".tmp"), depfile dependency header files (suffixed with ".d") generated during the compilation of C / C++ source files, and description files (suffixed with ".txt") generated by commands such as echo are all by-products.
[0131] It should be noted that the main product and the by-product are relative to the dependency relationship, and have no necessary connection with whether they are packaged into the final version compilation package. Both the main product and the by-product can be packaged or not packaged into the final version compilation package according to actual needs. In addition, the by-product cannot be compiled separately, but can only be compiled together with its corresponding main product when it is compiled. The deletion or change of the by-product will not affect the main product. For example, compiling the source file A.cpp can obtain the main product Bo and the by-product Cd. Among them, deleting the by-product Cd will not affect the main product Bo, and modifying the source file A.cpp will cause the main product Bo to be recompiled during the compilation verification process, and the by-product Cd will be recompiled.
[0132] The actual compilation product includes the main product and the by-product actually constructed during the compilation process, and can be stored in a preset compilation product directory. In this way, the server 120 can query the actual compilation product in the compilation product directory. It should be noted that the actual compilation product does not include the cached product temporarily generated during the compilation process.
[0133] For example, in the Android build system, the compilation product directory includes out / target and out / host, and the cache product directory is out / soong / .intermediates, so the server 120 can query and obtain the actual compilation product under out / target and out / host.
[0134] It should be noted that not all main products are stored in the compiled product directory. Some main products may also be stored in other directories (such as out / soong). Such main products are not related to the source code and will not affect the version building.
[0135] The effective compilation target includes the main product actually built during the compilation process. In other words, the effective compilation target is the compilation target that is built during the actual compilation process.
[0136] It can be understood that since all by-products will be compiled together when all valid compilation targets are compiled, the compilation result obtained by compiling all valid compilation targets is the same as the compilation result obtained by fully compiling the source file, that is, all valid compilation targets plus all by-products.
[0137] When determining the above-mentioned effective compilation target, the server 120 may first determine the expected compilation product according to the dependency file, and the expected compilation product includes all the compilation targets involved in the dependency file, that is, all the main products that should be generated in theory. Since some main products may not be built during the compilation process, the expected compilation product includes the main products actually built during the compilation process and some main products that are not built. Then, the server 120 takes the intersection of the expected compilation product and the actual compilation product as the main product actually built during the compilation process, that is, the effective compilation target.
[0138] S303, determining a first category of targets from valid compilation targets according to the dependency relationship file, where the first category of targets are compilation targets in the valid compilation targets that are not dependent on other compilation targets.
[0139] In a possible design, when determining the above-mentioned first-category target, the server 120 may first construct a dependency graph based on the dependency file. The server 120 uses the compilation target as a node, and constructs an edge connecting the corresponding two nodes based on the dependency relationship between the two compilation targets to obtain a dependency graph. The dependency graph includes leaf nodes, and the compilation target corresponding to the leaf node is not dependent on any compilation target. Then, the server 120 may determine the intersection of the compilation target corresponding to the leaf node in the dependency graph and the valid compilation target as the first-category target.
[0140] For example, taking the dependency file indicating that target A depends on source file a.cpp, target D depends on target A, target E depends on source file b.cpp, target B depends on target E, target D depends on target B, and target C depends on source file c.cpp as an example, the server 120 can construct the following according to the dependency file: Figure 5 The dependency diagram shown in Figure 1 is as follows. Figure 5 As shown, the dependency graph includes 8 nodes, namely, node 1 to node 3 and node A to node E, wherein node 1 corresponds to a.cpp, node 2 corresponds to b.cpp, node 3 corresponds to c.cpp, node A to node E correspond to targets A to target E respectively, node 1 is connected to node A, node A is connected to node D, node 2 is connected to node E, node E is connected to node B, node B is connected to node D, and node 3 is connected to node C. It can be seen that node C and node D are leaf nodes. Taking the above-mentioned targets A to target E as valid compilation targets as an example, the server 120 can determine that target C and target D are first-class targets.
[0141] In another possible design, the server 120 may also Figure 6 The process shown identifies the first type of targets mentioned above. Figure 6 , is a flow chart of a compilation method provided by an embodiment of the present application, which specifically shows another process of determining a first-category target from valid compilation targets according to a dependency relationship file. Figure 6 As shown, the compilation method includes S3031~S3034.
[0142] S3031, establishing a dependency correspondence table according to the dependency file, the dependency correspondence table including multiple sets of key-value pairs, each set of key-value pairs having a compilation target as a key and a compilation target that depends on the compilation target as a value.
[0143] When a compilation target is simultaneously dependent on multiple compilation targets, key-value pairs corresponding to the multiple compilation targets may be established. For example, if compilation target A and compilation target B both depend on compilation target C, server 120 may establish a key-value pair with compilation target C as the key and compilation target A as the value, and a key-value pair with compilation target C as the key and compilation target B as the value.
[0144] When a compilation target is not dependent on any target, the server 120 may also create a key-value pair with the compilation target as the key, but the value in the key-value pair is empty.
[0145] For example, Figure 5 Taking the dependency graph shown in FIG. 1 as an example, the server 120 may establish a dependency correspondence table as shown in Table 3.
[0146] Table 3
[0147]
[0148] According to the above Table 3, the value corresponding to target A is target D, and the values corresponding to targets C and D are empty.
[0149] In a possible design, the server 120 may perform hash processing on the key and value in the dependency correspondence table to obtain a hash table, which may improve the efficiency of querying data in the dependency correspondence table.
[0150] S3032, using each valid compilation target as a key, query whether there is a corresponding value in the dependency correspondence table.
[0151] If the value corresponding to the valid compilation target does not exist in the dependency correspondence table, execute S3033; if the value corresponding to the valid compilation target exists in the dependency correspondence table, execute S3034.
[0152] It should be noted that if the value corresponding to the valid compilation target is found to be empty, it means that the value corresponding to the valid compilation target does not exist in the dependency correspondence table.
[0153] S3033, determining that the valid compilation target is a first-category target.
[0154] It can be understood that if there is no value corresponding to the valid compilation target in the dependency correspondence table, it means that the valid compilation target is not dependent on other compilation targets, so it is determined to be a first-category target.
[0155] S3044, determining that the valid compilation target is a second type target.
[0156] It can be understood that if there is a value corresponding to a valid compilation target in the dependency correspondence table, it means that the valid compilation target is dependent on other compilation targets, so it is determined to be a second-category target.
[0157] It can be understood that when the dependency correspondence table is a hash table, the server 120 can effectively compile the hash value of the target as the key to query whether there is a corresponding value in the dependency correspondence table, and obtain a corresponding judgment based on the query result. The judgment process is the same as Figure 6 The process shown is similar and will not be repeated here.
[0158] Below Figure 5 As an example, the dependency diagram shown in FIG. Figure 6 The process shown in the figure determines the process of determining the first type of target. First, the server 120 can determine that the actual compilation product includes target A to target E, and determine that the expected compilation product includes target A to target E according to the dependency file, thereby determining that the valid compilation target includes target A to target E. Then, the server 120 establishes a dependency correspondence table as shown in Table 3 according to the dependency file, and queries the values of target A to target E in the dependency correspondence table respectively. Since the values corresponding to target C and target D are both empty, it is determined that target C and target D are the first type of targets among the valid compilation targets.
[0159] It can be understood that in the process of compiling the first type of target, all the compilation targets that the first type of target depends on will be compiled. Therefore, the compilation result obtained by compiling all the first type of targets is the same as the compilation result obtained by compiling all valid compilation targets, that is, the same as the compilation result obtained by compiling the code file in full, which is all valid compilation targets plus all by-products.
[0160] For example, when compiling Figure 5The target D shown will compile the targets A, B and E on which it depends, as well as all related by-products. That is, compiling target D can achieve the same compilation result as compiling source files a.cpp and b.cpp.
[0161] S304: Determine the dependent files of each first-category target according to the dependency relationship file.
[0162] The dependent files of the compilation target include the source files that the compilation target depends on. It should be noted that the dependent files of the compilation target can be one or more. For example Figure 5 The target D shown in the figure depends on both source file a.cpp and source file b.cpp, so the dependent files of target D include source file a.cpp and source file b.cpp. For another example, Figure 5 The target C shown depends on the source file c.cpp, so the dependent files of target C include the source file c.cpp.
[0163] S305 , using each dependent file as a key and the first type of target corresponding to the dependent file as a value to generate dependency information.
[0164] For example, the server 120 determines in S304 that the dependent files of compilation target 1 include source file 1, and the dependent files of compilation target 2 include source file 1 and source file 2, then the server 120 may generate dependency information indicating that the value corresponding to source file 1 includes compilation target 1 and compilation target 2, and the value corresponding to source file 2 includes compilation target 1. In other words, modifying source file 1 may cause compilation target 1 and compilation target 2 to be recompiled, and modifying source file 2 may cause compilation target 2 to be recompiled.
[0165] For another example, the dependency information generated by the server 120 may be as shown in Table 2 above.
[0166] It is understandable that by generating dependency information, the compilation targets affected by each dependent file can be quickly queried. Also, by using the dependency information generated in the above manner, the compilation targets corresponding to each dependent file can be reduced, so that the server 120 compiles fewer compilation targets during the compilation verification process, reducing the consumption of compilation resources.
[0167] In a possible design, the server 120 may not execute S303, but directly determine the dependent files of each valid compilation target according to the dependency relationship file, and then generate dependency information with each dependent file as a key and the valid compilation target corresponding to the dependent file as a value, and the dependency information may be as shown in the above Table 1. Although this method will increase the compilation targets corresponding to each dependent file, it can simplify the process of generating dependency information by the server 120 and improve the efficiency of generating dependency information by the server 120.
[0168] In the embodiment of the present application, the dependency information may be updated. For example, the server 120 may regenerate the dependency information when detecting that the build rule file is updated.
[0169] In summary, the compilation method provided in the embodiment of the present application can reduce the targets to be compiled during the compilation verification process, save compilation resources, and shorten the compilation time.
[0170] The present application also provides a chip system, such as Figure 7 As shown, the chip system 700 includes at least one processor 701 and at least one interface circuit 702. The processor 701 and the interface circuit 702 can be interconnected through lines. For example, the interface circuit 702 can be used to receive signals from other devices (such as the memory of an electronic device). For another example, the interface circuit 702 can be used to send signals to other devices (such as the processor 701). Exemplarily, the interface circuit 702 can read the instructions stored in the memory and send the instructions to the processor 701. When the instructions are executed by the processor 701, the electronic device or server can execute the various steps in the above embodiments. Of course, the chip system can also include other discrete devices, which are not specifically limited in the embodiments of the present application.
[0171] The present application also provides an electronic device. Figure 8 , is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. Figure 8 As shown, the electronic device 800 may include a processor 810 and a memory 820 .
[0172] Among them, the processor 810 can be used to read and execute computer-readable instructions. In a specific implementation, the processor 810 may mainly include a controller, an operator and a register. Among them, the controller is mainly responsible for instruction decoding and issuing control data for the operation corresponding to the instruction. The operator is mainly responsible for saving register operands and intermediate operation results temporarily stored during the execution of instructions. In a specific implementation, the hardware architecture of the processor 810 can be an application-specific integrated circuit (ASIC) architecture, a microprocessor without interlocked pipelined stages (MIPS) architecture, an advanced reduced instruction set machine (ARM) architecture or a network processor (NP) architecture, etc., without specific restrictions here.
[0173] The memory 820 is coupled to the processor 810 and is used to store various software programs (such as the above-mentioned compiler) and / or multiple sets of instructions. In a specific implementation, the memory 820 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more disk storage devices, flash memory devices or other non-volatile solid-state storage devices. The memory 820 can store an operating system, such as uCOS, VxWorks, RTLinux and other embedded operating systems.
[0174] It is to be understood that the structure shown in the embodiment of the present application does not constitute a specific limitation on the electronic device 800. In other embodiments, the electronic device 800 may include Figure 8 More or fewer components, or combining some components, or splitting some components, or different component arrangements. The components shown in the figure can be implemented in hardware, software, or a combination of software and hardware.
[0175] This embodiment also provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes each function or step in the above method embodiment.
[0176] This embodiment also provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute each function or step in the above method embodiment.
[0177] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory so that the chip executes each function or step performed by the mobile phone in the above method embodiment.
[0178] Among them, the electronic device, computer-readable storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above and will not be repeated here.
[0179] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0180] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0181] The unit described as a separate component may or may not be physically separated, and the component shown as a unit may be one physical unit or multiple physical units, that is, it may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiment.
[0182] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0183] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program code.
[0184] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present application and are not intended to limit it. Although the present application has been described in detail with reference to the preferred embodiments, a person of ordinary skill in the art should understand that the technical solution of the present application may be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present application.
Claims
1. A compiling method, characterized in that: The method comprises: When it is detected that a source file that does not affect the compilation step is updated, modification information is obtained; wherein the modification information includes a modification file, and the modification file is the updated source file; Querying the compilation target corresponding to each of the modified files from the dependency information to obtain a first target; wherein the dependency information includes dependent files and compilation targets corresponding to the dependent files, the dependent files are source files that are dependent on at least one compilation target, and the compilation targets corresponding to the dependent files include compilation targets that depend on the dependent files; Compile the first target.
2. The method according to claim 1, characterized in that The compilation targets corresponding to the dependent files include first-category targets among all the compilation targets that depend on the dependent files, where the first-category targets are compilation targets that are not depended on by other compilation targets.
3. The method according to claim 1 or 2, characterized in that: Before querying the compilation target corresponding to each modified file from the dependency information to obtain the first target, the method further includes: Obtain a dependency file, wherein the dependency file is used to indicate dependencies between compilation targets; The dependency information is generated according to the dependency relationship file.
4. The method according to claim 3, characterized in that The step of generating the dependency information according to the dependency relationship file includes: Determining a valid compilation target from actual compilation products according to the dependency relationship file; wherein the actual compilation products include a main product and a by-product obtained by actual compilation, the valid compilation target includes the main product obtained by actual compilation, the main product includes a compilation result defined by the dependency relationship, and the by-product is a compilation result not defined by the dependency relationship; Determine the dependency file of each of the valid compilation targets according to the dependency relationship file; A mapping relationship between each of the dependent files and a valid compilation target that depends on the dependent file is established to obtain the dependency information.
5. The method according to claim 4, characterized in that The step of generating the dependency information according to the dependency relationship file includes: Determining a valid compilation target from actual compilation products according to the dependency relationship file; wherein the actual compilation products include a main product and a by-product obtained by actual compilation, the valid compilation target includes the main product obtained by actual compilation, the main product includes a compilation result having the dependency relationship, and the by-product is a compilation result not having the dependency relationship; Determine a first category of targets from the valid compilation targets according to the dependency relationship file, where the first category of targets are compilation targets that are not dependent on other compilation targets; Determine the dependency file of each of the first-category targets according to the dependency relationship file; A mapping relationship between each of the dependent files and the first-category target that depends on the dependent files is established to obtain the dependency information.
6. The method according to claim 5, characterized in that Determining the first category of targets from the valid compilation targets according to the dependency relationship file includes: Establishing a dependency correspondence table according to the dependency relationship file, wherein the dependency correspondence table includes a plurality of key-value pairs, each key-value pair having a compilation target as a key and a compilation target that depends on the compilation target as a value; Using each of the valid compilation targets as a key, querying whether there is a value corresponding to the valid compilation target in the dependency correspondence table; If the dependency correspondence table contains a value corresponding to the valid compilation target, it is determined that the valid compilation target is the first type of target.
7. The method according to claim 5, characterized in that Determining the first category of targets from the valid compilation targets according to the dependency relationship file includes: Taking the compilation targets involved in the dependency relationship file as nodes, establishing an edge connecting two nodes corresponding to the two compilation targets based on the dependency relationship between the two compilation targets, and obtaining a dependency relationship graph; wherein the dependency relationship graph includes leaf nodes, and the compilation targets corresponding to the leaf nodes are not dependent on other compilation targets; An intersection of the compilation target corresponding to the leaf node and the valid compilation target is determined as the first type of target.
8. The method according to any one of claims 4 to 7, characterized in that: The determining of a valid compilation target from actual compilation products according to the dependency relationship file includes: Determine an expected compilation product according to the dependency relationship file, wherein the expected compilation product includes all compilation targets involved in the dependency relationship file; Querying and obtaining the actual compilation product from a preset compilation product path; An intersection of the expected compilation product and the actual compilation product is determined as the valid compilation target.
9. The method according to claim 1 or 2, characterized in that: Before obtaining the modification information, the method further includes: When it is detected that the source file is updated, it is determined whether the build rule file is updated; If the build rule file is not updated, it is determined that a source file that does not affect the compilation step is updated.
10. An electronic device, characterized in that: The electronic device comprises: a memory and a processor; the processor is coupled to the memory; wherein the memory is used to store computer program code, the computer program code comprises computer instructions; when the computer instructions are executed by the processor, the electronic device executes the method as described in any one of claims 1-9.
11. A computer-readable storage medium, characterized in that: The method comprises computer instructions; when the computer instructions are executed on an electronic device, the electronic device is caused to execute the method as claimed in any one of claims 1 to 9.
Citation Information
Patent Citations
Compilation processing method and apparatus, and electronic device
CN107608677A
Compiling method and device
CN108304184A
Incremental compiling method and device based on source code detection
CN115113876A
Code incremental compiling method and device, computer equipment and storage medium
CN117149209A
PLC software incremental compiling method and device
CN117806651A