A compiling method, electronic equipment and computer readable storage medium
By detecting source file updates in the code gate and only compiling the affected compilation targets, the problem of resource waste and excessive time caused by full compilation is solved, and an efficient compilation and verification process is achieved.
Patent Information
- Application Number
- CN202510117171.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-24
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2045-01-24
AI Technical Summary
In existing technologies, code gates are compiled using a full compilation method, which leads to a waste of compilation resources and excessive time consumption. In particular, when there are minor modifications to the code or configuration files, the entire component still needs to be compiled, resulting in a redundant build process.
When a source file with undefined compilation dependencies is updated, modification information is obtained, and only the affected compilation target (the first target) is compiled. Dependency information is generated by querying dependency information and dependency files, reducing the number of targets that are recompiled during the compilation verification process.
It saves compilation resources, shortens compilation time, improves code deployment speed, and achieves the same verification effect as full compilation.
Smart Images

Figure CN119556941B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a compiling method, an electronic device and a computer readable storage medium. BACKGROUND
[0002] In the software development process, the application of code gatekeeper is very wide. Code gatekeeper is a measure to ensure code quality and security, which requires the code submitted by the developer to meet certain requirements before being merged into the main branch. The above-mentioned certain requirements can include compilation pass, unit test coverage, code static check without warning, and smoke test case pass.
[0003] At present, the compilation method in code gatekeeper is full compilation, that is, once the code or configuration file is modified, the entire component needs to be recompiled according to the version construction method, which involves many unnecessary compilation processes, wastes compilation resources, and takes a lot of time. SUMMARY
[0004] The embodiment of the present application provides a compiling method, an electronic device and a computer readable storage medium, which can reduce unnecessary compilation processes without affecting the correctness of the verification program, thereby shortening the compilation time and saving the compilation resources.
[0005] To achieve the above-mentioned purpose, the embodiment of the present application adopts the following technical solution:
[0006] In a first aspect, the present application provides a compiling method, which can obtain modification information when detecting that a source file which does not affect the compilation step is updated. The above-mentioned source file which does not affect the compilation step can also be called a source file which does not define the compilation dependency relationship, and can include code files and configuration files involved in the compilation, and code files and configuration files not involved in the compilation, and does not include the build rule file. The above-mentioned modification information includes the updated source file (called modified file). The electronic device stores dependency information, which includes dependency files and the compilation targets corresponding to the dependency files, and the compilation target corresponding to the dependency file is the compilation target which depends on the dependency file. Then, the electronic device can query the compilation target corresponding to each modified file from the dependency information to obtain the first target, and the compilation target corresponding to the modified file is the compilation target which 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 the compilation target affected by the update, so that compiling the first target can verify whether the modified source file can pass the compilation, that is, achieve the same verification effect as full compilation of the source file. In addition, compared with full compilation, compiling only the first target reduces the number of targets recompiled in the compilation verification process, so that the compilation resources can be saved and the compilation time can be shortened.
[0007] In an implementation of the first aspect, the compiling target corresponding to the dependency file can also include first-type targets among all the compiling targets dependent on the dependency file, the first-type target being a compiling target not dependent on other compiling targets. It can be understood that in the process of compiling the first-type target, all the compiling targets dependent on the first-type target are compiled. Therefore, the compiling result obtained by compiling all the first-type targets is the same as the compiling result obtained by full compiling the code file. That is, the first-type targets queried by the dependency information provided by the implementation have no mutual dependency, compared with the first-type targets queried by the method described above which can have mutual dependency, the number of the first-type targets queried by the implementation is less, and the compiling resources can be further saved and the compiling time can be shortened, so that the source file can pass through the code gate faster, and the online speed of the code is improved.
[0008] In an implementation of the first aspect, before the electronic device queries the first-type targets from the dependency information, the electronic device can also acquire a dependency relationship file and generate the dependency information according to the dependency relationship file, the dependency relationship file being used to indicate the dependency relationship among the compiling targets. That is, when the dependency relationship file is updated, the dependency information is also updated.
[0009] In an implementation of the first aspect, when the electronic device generates the dependency information, the electronic device can determine effective compiling targets from actual compiling products according to the dependency relationship file. The actual compiling products include main products and by-products obtained by actual compiling, and the effective compiling targets include the main products obtained by actual compiling, the main products including compiling results defined by the dependency relationship, for example, the compiling targets obtained by actual compiling. The by-products are compiling results not defined by the dependency relationship, and are specifically compiling results generated in the process of generating the main products. Then, the electronic device can determine the dependency file of each effective compiling target according to the dependency relationship file, and establish the mapping relationship between each dependency file and the effective compiling target dependent on the dependency file, to obtain the dependency information. This process of generating the dependency information is relatively simple, and the efficiency of the electronic device in generating the dependency information can be improved.
[0010] In an implementation of the first aspect, when the electronic device generates the dependency information, the electronic device can also determine effective compiling targets from actual compiling products according to the dependency relationship file, then determine first-type targets from the effective compiling targets according to the dependency relationship file, the first-type target being a compiling target not dependent on other compiling targets, then determine the dependency file of each first-type target according to the dependency relationship file, and finally establish the mapping relationship between each dependency file and the first-type target dependent on the dependency file, to obtain the dependency information. In the dependency information generated by this method, the number of the compiling targets corresponding to each dependency file is less, the number of the compiling targets verified in the compiling verification process can be reduced, and the compiling efficiency can be improved.
[0011] In an implementation form of the first aspect, when determining the first type of target, the electronic device can establish a dependency correspondence table according to the dependency file, the dependency correspondence table including a plurality of groups of key-value pairs, each group of key-value pairs taking one compilation target as a key and taking a compilation target dependent on the compilation target as a value. Then, taking each valid compilation target as a key, the electronic device queries whether there is a value corresponding to the valid compilation target in the dependency correspondence table. If there is no value corresponding to the valid compilation target in the dependency correspondence table, the electronic device determines that the valid compilation target is the first type of target.
[0012] In an implementation form of the first aspect, when determining the first type of target, the electronic device can take the compilation targets involved in the dependency file as nodes, and establish an edge connecting two nodes corresponding to two compilation targets according to the dependency relationship between the two compilation targets, to obtain a dependency graph. The dependency graph includes leaf nodes, and the compilation targets corresponding to the leaf nodes are not dependent on other compilation targets. Then, the electronic device determines the intersection of the compilation targets corresponding to the leaf nodes and the valid compilation targets as the first type of target.
[0013] In an implementation form of the first aspect, when determining the valid compilation target, the electronic device can determine an expected compilation product according to the dependency file, the expected compilation product including all the compilation targets involved in the dependency file. Then, the electronic device queries an actual compilation product from a preset compilation product path, and determines the intersection of the expected compilation product and the actual compilation product as the valid compilation target.
[0014] In an implementation form of the first aspect, the electronic device can determine whether the source file that does not affect the compilation step is updated by: determining whether the build rule file is updated when detecting that the source file is updated, and determining that the source file that does not affect the compilation step is updated if the build rule file is not updated.
[0015] In the second aspect, the embodiments of the present application provide an electronic device, which comprises a memory and a processor, wherein the processor is coupled with the memory; the memory is configured to store computer program code, the computer program code comprising computer instructions; and when the computer instructions are executed by the processor, the electronic device performs the method according to the first aspect and any one of the implementation forms thereof.
[0016] In the third aspect, the embodiments of the present application provide a computer readable storage medium, which comprises computer instructions; and when the computer instructions are executed on an electronic device, the electronic device performs the method according to the first aspect and any one of the implementation forms thereof.
[0017] In a fourth aspect, an embodiment of the present application provides a computer program product, including computer instructions; when the computer instructions run on an electronic device, the electronic device executes the method according to the first aspect and any one of the implementation forms thereof.
[0018] The technical effects brought by the implementation forms of the second aspect to the fourth aspect can refer to the technical effects brought by the different design forms of the first aspect, which will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS
[0019] Figure 1 A structural schematic diagram of a development system is provided for the embodiment of the present application.
[0020] Figure 2 A flowchart of a compiling method is provided for the embodiment of the present application.
[0021] Figure 3 A flowchart of another compiling method is provided for the embodiment of the present application.
[0022] Figure 4 A structural schematic diagram of an Android build system is provided for the embodiment of the present application.
[0023] Figure 5 A dependency relationship diagram is provided for the embodiment of the present application.
[0024] Figure 6 A flowchart of still another compiling method is provided for the embodiment of the present application.
[0025] Figure 7 A structural schematic diagram of a chip system is provided for the embodiment of the present application.
[0026] Figure 8 A structural schematic diagram of an electronic device is provided for the embodiment of the present application. DETAILED DESCRIPTION
[0027] Hereinafter, the terms "first" and "second" are only used for description purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined with "first" and "second" can explicitly or implicitly include one or more of the features. In the description of the embodiments, unless otherwise specified, the meaning of "a plurality of" is two or more.
[0028] In this application, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" or "for example" in this application should not be construed as being better or more advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner to facilitate understanding.
[0029] To facilitate understanding of this article, the relevant existing technologies will be introduced first.
[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 object code (i.e., performs compilation) and builds software projects. These software projects can be, for example, executable files, library files, or intermediate representations (IRs).
[0032] A compilation target is the final output of compilation, the final product generated by the compiler from the source code. Depending on the purpose and requirements of compilation, the compilation target can be an executable file, a library file, or an intermediate representation, etc.
[0033] Version building refers to the process of compiling and packaging software according to a specific version number or version tag during software development.
[0034] Dependency refers to the situation where a build target depends on other build targets or files during the build process. For example, if build target A depends on build target B, it means that build target A must be compiled after build target B, and if build target B is recompiled, build target A also needs to be recompiled. As another example, if build target B depends on source file C, then if source file C is changed, build target B needs to be recompiled. Yet another example is if build target B depends on build target D, and build target D depends on source file E, then changing source file E will cause build targets to be recompiled, which in turn will cause build target B to be recompiled.
[0035] This application provides a compilation method applied to a compilation verification process. The compilation verification process refers to the process of verifying whether the compilation target can be compiled successfully after the code or configuration file has been modified.
[0036] Referring to Figure 1 , a structural schematic diagram of a development system provided in an embodiment of the present application is shown. As Figure 1 shown, the development system includes a data center and a plurality of terminals (such as Figure 1 terminal 111 and terminal 112 shown), 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 routers or switches, etc.
[0037] The data center includes one or more servers, such as Figure 1 server 120 shown, which can provide a server that provides a compilation function. In an alternative case, server 120 refers to a server cluster deployed with a plurality of servers, which can have a rack, and the rack can establish communication for the plurality of servers through a wired connection, such as a universal serial bus (USB) or a peripheral component interconnect express (PCIe) high-speed bus, etc.
[0038] Server 120 can also obtain a source file from a terminal, and after compiling the source file, send the compilation result to the corresponding terminal.
[0039] In addition, Figure 1 the data center shown can also include other physical devices with a compilation function, such as a mobile phone, a tablet computer, or other devices, etc.
[0040] The above terminal can also be referred to as a terminal device, user equipment (UE), a mobile station (MS), a mobile terminal (MT), etc. The terminal can be a mobile phone, a tablet computer, a desktop, laptop or handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), and an augmented reality (AR) \ virtual reality (VR) device, etc. The terminal has a data processing capability, and the specific form of the terminal is not specially limited in the embodiment of the present application.
[0041] Code gate, as a measure to ensure code quality and security, is widely used in the software development process. Code gate requires that the code submitted by the developer needs to meet the requirements to be merged into the code repository. The above requirements can include compilation passing, unit test coverage meeting the standard, etc. Among them, the compilation method in code gate is full compilation, that is, each time the compilation needs to recompile the entire component according to the version construction method. The component is, for example, any one of system, chipset, modem, recovery, energy. However, this compilation method has the problem of wasting compilation resources in the compilation verification process, and the specific reasons are as follows:
[0042] (1) In the case where the modification range of the newly submitted code is small, such as only modifying a few lines of code or a few source files, the entire component still needs to be compiled, resulting in a lot of compilation processes unrelated to the modification, a large number of redundant build processes, and waste of compilation resources.
[0043] (2) In the case where the newly submitted code modifies a 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 embodiment provides a compilation method which can be applied to the above-mentioned server 120. The server 120 can accurately compile the compilation target (which can be referred to as the first target) affected by the update when detecting that the source file with undefined compilation dependency relationship is updated.
[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, achieve the same verification effect as full compilation of the source file. In addition, compared with full compilation, compiling only the first target reduces the number of targets recompiled in the compilation verification process, so it can save compilation resources and shorten the compilation time.
[0046] The compilation method provided by the present application embodiment will be described in detail below with reference to the accompanying drawings.
[0047] Please refer to Figure 2 , the flowchart of the compilation method provided by the present application embodiment can be applied to Figure 1 the server 120 in Figure 2 . As shown in , the compilation method at least includes S201~S206.
[0048] S201, update the source file.
[0049] The source files include code files, configuration files, and build rule files. The code files include source code for implementing software functions. It should be noted that the format of the code files can be different according to different development environments. For example, if the development environment is an Android system, the format of the code files can be ".java", ".c", or ".cpp".
[0050] The configuration files are files for storing settings and preferences of software programs, which can be used to adjust the behavior of the programs without modifying the code. For example, the configuration files can define environment variables required for program running. The build rule files are used to define build logic, which includes build rules, dependency relationships, compilation options, and the like in the build process from source code to a software project. It can be understood that the build rule files are source files for controlling the compilation steps. In addition, the configuration files and the build rule files can be manually written by developers.
[0051] According to different compilation frameworks, the format of the build rule files can be different. For example, under the soong framework, the build rule files can be Android.bp files; under the CMake framework, the build rule files can be CMakeLists.txt files; and under the make-based framework, the build rule files can be Android.mk files.
[0052] It should be noted that updating the source files can be updating at least one of the code files, the configuration files, and the build rule files. In addition, the source files can be uploaded to the server 120 by the developer through a terminal, i.e., received by the server 120; or generated by the 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 performed; if the build rule file is updated, S206 is performed.
[0055] It can be understood that if the build rule file is updated, it indicates that the update of the source files this time will change the compilation steps and / or rules, and the source files need to be fully compiled according to the steps and rules indicated by the updated build rule file. Therefore, S206 is performed. If the build rule file is not updated, it indicates that the update of the source files this time will not affect the compilation steps and rules, and only the compilation target affected by this update needs to be recompiled. Therefore, S203 is performed.
[0056] In a possible design, the server 120 can determine that the build rule file is updated in a case where a timestamp of the build rule file is later than a timestamp of a compilation target obtained based on the build rule file.
[0057] S203, acquire modification information, the modification information including an updated source file (which can be referred to as a modified file).
[0058] In a possible design, the server 120 can compare the source file before and after the update to obtain the modified file.
[0059] In another possible design, for each file in the source file, the server 120 can compare a timestamp 1 of the file and a timestamp 2 of a compilation target dependent on the file, and 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, the target a is dependent on the source file 1, and if the timestamp of the source file 1 is later than the timestamp of the target a, it can be determined that the source file 1 is updated, that is, the source file 1 is a modified file. This way only needs to compare the timestamps of two files, and is more economical in terms of computing resources and improves processing efficiency compared with comparing the source file before and after the update.
[0060] S204, query a compilation target corresponding to each modified file from dependency information to obtain a first target, the dependency information including a dependent file and a compilation target corresponding to the dependent file.
[0061] The dependent file includes a source file dependent on at least one compilation target. The compilation target corresponding to the dependent file includes a compilation target dependent on the dependent file. It should be noted that the compilation target corresponding to the dependent file can include a compilation target directly dependent on the dependent file and a compilation target indirectly dependent on the dependent file. For example, the dependent file is an a.c file, the target 1 is dependent on the a.c file, the target 2 is dependent on the target 1, and the target 3 is dependent on the target 2, wherein the target 1 directly depends on the a.c file, the target 2 and the target 3 indirectly depend on the a.c file, and the target 1, the target 2 and the target 3 are all the compilation targets corresponding to the a.c file.
[0062] It can be understood that the modification of the dependent file will cause the corresponding compilation target to be recompiled in the compilation verification process.
[0063] In a possible implementation, the dependency information can be in the form of a table. For example, the dependency information can be as shown in Table 1.
[0064] Table 1
[0065]
[0066] According to the above table 1, the dependent files include source files a.c, b.cpp and c.cpp. The compilation targets corresponding to the source file a.c include target 1, target 2 and target 3. The compilation target corresponding to the source file b.cpp includes target 4. The compilation targets corresponding to the source file c.cpp include target 5 and target 6.
[0067] For example, the modification information indicates that the modified files include the source file b.cpp and the source file c.cpp. The server 120 can determine, based on the above table 1, that the first targets include target 4, target 5 and target 6.
[0068] It should be noted that the dependent information shown in table 1 is only an example, and the actual dependent information can include more content than that shown in table 1. In other embodiments, the dependent information can also be presented in other ways, for example, the dependent information can also exist in the form of a hash table. In the above hash table, the hash value of the dependent file is used as the key, and the hash value of the compilation target is used as the value. Presenting the above dependent information in the form of a hash table can improve the query speed and the efficiency of the server 120 in determining the first target.
[0069] S205, compiling the first target.
[0070] In the process of compiling the first target, the server can compile the source files on which the first target depends in the correct order.
[0071] S206, compiling the source file.
[0072] The server 120 can perform full compilation on the source file according to the compilation process indicated by the build rule file.
[0073] The compilation method provided by the embodiments of the present application can only compile the compilation targets (i.e. the above first targets) affected by the update, reducing the number of targets that need to be recompiled in the compilation and verification process, achieving the effect of saving compilation resources and shortening the compilation time.
[0074] For example, in the case of compiling and verifying after the user modifies the source file b.cpp and the source file c.cpp in table 1, the existing technology provides a solution to compile the source file a.cpp, the source file b.cpp and the source file c.cpp (i.e. full compilation), which is relative to the need to recompile target 1~target 6. In the solution provided by the present application, the server 120 only needs to recompile target 4, target 5 and target 6, reducing the number of targets that need to be recompiled, saving compilation resources and shortening the compilation time.
[0075] In an optional embodiment, the compilation target corresponding to the above dependent file includes a compilation target that is not dependent on any compilation target among all compilation targets dependent on the file.
[0076] Continuing with Table 1 above as an example, target 1 depends on source file ac, target 2 depends on target 1, and 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. Target 1 is depended on by target 2, target 2 is depended on by target 3, and target 3 is not depended on by any compilation target. Thus, the compilation targets corresponding to source file ac include target 3. Similarly, the compilation targets that depend on source file c.cpp include target 5 and target 6. Target 5 is depended on by target 6, and target 6 is not depended on by any compilation target. Therefore, 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] Taking the modification information indicating that the modified files include source file b.cpp and source file c.cpp as an example, server 120 can determine from Table 2 that the first target includes target 4 and target 6.
[0080] Understandably, changes to the source file ac will directly affect target 1, changes to target 1 will then affect target 2, and changes to target 2 will then affect target 3. Therefore, during compilation and verification, recompiling target 3 will also recompile targets 1 and 2, and recompiling target 2 will also recompile target 1. In other words, recompiling target 3 achieves the same effect as recompiling the source file ac. Similarly, recompiling target 6 will also recompile target 5, meaning recompiling target 6 achieves the same effect as recompiling the source file c.cpp.
[0081] In other words, server 120 can achieve the same verification effect as compiling targets 4, 5, and 6 by compiling targets 4 and 6. This further reduces the number of targets that need to be recompiled during the compilation and verification process, saving compilation resources and shortening compilation time. This allows source files to pass through the code gate more quickly, improving the speed of code deployment.
[0082] To improve the efficiency of server 120's compilation and verification, server 120 can pre-generate dependency information before executing S201~S206. The following will combine... Figures 3-6 This section describes the specific process by which server 120 generates dependency information.
[0083] Please see Figure 3 The flowchart illustrates another compilation method provided in this application embodiment, applied to... Figure 1 The diagram of server 120 illustrates the specific process by which server 120 generates dependency information. For example...Figure 3 As shown, the compiling method further includes S301-S305.
[0084] S301, generating a dependency relationship file based on the build rule file.
[0085] It should be noted that the build rule file is introduced in S202, and will not be described herein. The dependency relationship file includes the build rule, command, build process and required parameters of the compiling target, and is used to indicate the dependency relationship between the compiling targets. The compiler can determine the compiling order according to the dependency relationship between the compiling targets, and execute the build task.
[0086] The dependency relationship 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 relationship file is different under different build systems. In the present embodiment, the build system of the server 120 is taken as an Android® build system as an example, and the process of generating the dependency relationship file by the server 120 based on the build rule file is described exemplarily.
[0087] Referring to Figure 4 , it is a structural schematic diagram of the Android® build system. As shown in Figure 4 , the Android® build system includes components such as blueprint, soong, kati and ninja. In the present embodiment, the build rule file can include an Android.bp file and an Android.mk file, and the description language and description manner of 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 declaration in the Android.bp file into a structure that can be understood by the soong component, and obtain a parsed Android.bp file (for example, referred to as an 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 dependency relationships defined by the Android1.bp file.
[0089] The kati component is a make cloning tool, which is specially used for the Android build system. The kati component can parse the content of an Android.mk file to generate a ninja file 2, which contains all the build rules and dependencies defined in the Android.mk file. Optionally, the kati component can be replaced by a Ckati component. The difference between the kati component and the Ckati component is that the kati component is written in Go language, and the Ckati component is written in C++ language.
[0090] The ninja component can combine the ninja file 1 and the ninja file 2 to obtain a dependency file (for example, combined-xxx.ninja), and compile the source code based on the dependency file to build the compilation target. It should be noted that in other embodiments, the ninja file 1 and the ninja file 2 can also be combined by other components of the Android build system to obtain the dependency file.
[0091] Exemplarily, the dependency file can 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] Wherein, the cflags is a global parameter, which is assigned a value of -Wall. The rule cc defines a rule cc of the build. The command defines a specific command of the rule cc, that is, to compile the input variable ($in) and generate the output variable ($out). The build foo.o:cc foo.c is used to define the build process, which indicates that when building foo.o, foo.c needs to be compiled according to the rule cc. That is, according to the dependency file of the above example, it can be known that when the rule cc is triggered, the compiler of the 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 dependencies from the dependency file. According to the definition manner of the dependencies in the dependency file, the dependencies can be divided into explicit dependencies and implicit dependencies. Correspondingly, the files on which the compilation target depends (which can be referred to as dependent files) can be divided into explicit dependent files and implicit dependent files.
[0098] Wherein, the display dependent file can be listed in the build line, and can act as the $in variable (input variable) in the rule. The build line can refer to a line of code for defining the build process, such as the above-mentioned "build foo.o:cc foo.c". 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 the display dependent file of foo.o, or it can be expressed as: foo.o depends on foo.c, and the dependency relationship is display dependency.
[0099] The implicit dependent file can be obtained from the depfile (dependency file) attribute in the rule, or from the syntax at the end of the build line. The implicit dependent file will not be used as the $in variable (input variable).
[0100] Exemplarily, the dependency relationship file can 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] By comparing the above content 1 and content 2, it can be seen that both content 1 and content 2 define the rule, instruction and process of building the compilation target, and the difference lies in that content 2 further includes the depfile line. The depfile line is used to specify the storage path of the depfile, and the depfile is a dependency file generated during the compilation process, which records the dependency relationship between the source files and various compiler flags and preprocessing options required for compiling each source file. When the depfile changes, it indicates that the dependency relationship between the source files changes, and the compilation target also needs to be recompiled. In addition, the depfile (i.e. abc.d) will not be used as the $in variable. That is, the compilation target abc.o in content 2 not only has a display dependent file (i.e. foo.c), but also has an implicit dependent file (i.e. abc.d). It should be noted that "xxxxx" in the above command line is only illustrative and has no real meaning.
[0107] Exemplarily, the dependency relationship file can 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, the modules, the Q.jar, the release and the like are all files needed to be depended in the process of building and compiling the compilation target abcd.o, but these files will not be the $in variable of the commmd command when the commmd line is compiled, so the modules, the Q.jar, the release and the like are the implicit dependent files of the compilation target abcd.o.
[0121] It should be noted that no matter which way the above dependency relationship is defined, once the dependent file of the compilation target changes, the compilation target needs to be recompiled in the compilation and verification process.
[0122] It should be further noted that the server 120 can generate the dependency file according to the build rule file when detecting that the build rule file changes. That is, the server 120 can generate the dependency file once for each time the user updates the build rule file.
[0123] S302, determining 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. The main products include the compilation results defined in the dependency file, i.e., the above-mentioned compilation targets, such as the foo.o file, the abc.o file and the 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 in the process of building the main products, which are not defined in the dependency file.
[0125] For example, in the process of executing the compilation command of the jar package, in addition to the main product ".jar" file, the ".class" file and the dynamically generated source code file are also generated, wherein the ".class" file and the dynamically generated source code file are both by-products.
[0126] For another example, in the process of Javac compilation, the by-products not defined by any dependency can be generated by using the following instruction. The Javac is a compiler of the Java programming language.
[0127] -d<directory (directory)> is used to specify the directory for storing the generated class files. For example, -d<out / soong / .intermediates / class> indicates that the generated class files are stored in the out / soong / .intermediates / class directory.
[0128] -s<directory> is used to specify the directory for storing the generated source files. For example, -s<out / soong / .intermediates / source> indicates that the generated source files are stored in the out / soong / .intermediates / source directory.
[0129] -h<directory> is used to specify the directory for storing the generated native header files. For example, -h<out / soong / .intermediates / header> indicates that the generated native header files are stored in the out / soong / .intermediates / header directory.
[0130] In addition to the above examples, the class files (e.g. R.java) generated dynamically by the resource files, the interface definition files (e.g. Android interface definition language (AIDL) source files), the header files (suffixed with ".h") generated dynamically, the temporary files (suffixed with ".tmp") generated during the compilation of JAVA source files, the depfile dependency header files (suffixed with ".d") generated during the compilation of C / C++ source files, and the description files (suffixed with ".txt") generated by commands such as echo, etc. 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 alone, but can only be compiled together with the corresponding main product when the main product is compiled, and 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 B.o and the by-product C.d. Deleting the by-product C.d will not affect the main product B.o, and modifying the source file A.cpp will cause the main product B.o to be recompiled in the compilation and verification process, and the by-product C.d will also be recompiled.
[0132] The actual compilation product includes the main product and the by-product actually built in the compilation process, and can be stored in the preset compilation product directory. In this way, the server 120 can query the actual compilation product under the compilation product directory. It should be noted that the actual compilation product does not include the cache product temporarily generated in the compilation process.
[0133] For example, under 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 the actual compilation product under out / target and out / host.
[0134] It should be noted that not all main products are stored in the compilation product directory, and some main products can also be stored in other directories (e.g. out / soong), which are not related to the source code and will not affect the version build.
[0135] The effective compilation target includes the main product actually built in the compilation process. In other words, the effective compilation target is the compilation target built in the actual compilation process.
[0136] Understandably, since compiling all valid compilation targets will also compile all byproducts, the compilation result obtained by compiling all valid compilation targets is the same as the compilation result obtained by compiling the source file in its entirety, which is all valid compilation targets plus all byproducts.
[0137] When determining the aforementioned valid compilation targets, server 120 can first determine the expected compilation artifacts based on the dependency file. The expected compilation artifacts include all compilation targets involved in the dependency file, i.e., all the main artifacts that should theoretically be generated. Since some main artifacts may not be built during the compilation process, the expected compilation artifacts include both the main artifacts actually built during compilation and the main artifacts that were not built. Then, server 120 takes the intersection of the expected compilation artifacts and the actual compilation artifacts as the main artifacts actually built during compilation, i.e., the valid compilation targets.
[0138] S303, determine the first type of target from the valid compilation targets based on the dependency file. The first type of target is the compilation target that is not depended on by other compilation targets.
[0139] In one possible design, when determining the first type of target, server 120 can first construct a dependency graph based on the dependency file. Specifically, server 120 uses compilation targets as nodes and constructs edges connecting corresponding nodes based on the dependencies between two compilation targets, thus obtaining the dependency graph. The dependency graph includes leaf nodes, where the compilation target corresponding to a leaf node is not depended upon by any other compilation target. Then, server 120 can determine the intersection of the compilation targets corresponding to the leaf nodes in the dependency graph and the valid compilation targets as the first type of target.
[0140] For example, using a 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, server 120 can construct the following based on the above dependency file: Figure 5 The dependency graph shown is as follows. Figure 5 As shown, the dependency graph includes 8 nodes: nodes 1-3 and nodes A-E. Node 1 corresponds to a.cpp, node 2 to b.cpp, and node 3 to c.cpp. Nodes A-E correspond to targets A-E respectively. Node 1 is connected to node A, node A to node D, node 2 to node E, node E to node B, node B to node D, and node 3 to node C. It can be seen that nodes C and D are leaf nodes. Taking the example that targets A-E are all valid compilation targets, server 120 can determine that targets C and D are first-class targets.
[0141] In another possible design, the server 120 can also determine the first type of target according to the flow shown in FIG. 3. Figure 6 Referring to FIG. 3, a flow of a compiling method provided by an embodiment of the present application is shown, which specifically shows a process of determining the first type of target from the valid compiling targets according to the dependency file. As shown in FIG. 3, the compiling method includes S3011-S3014. Figure 6 Referring to FIG. 3, a flow of a compiling method provided by an embodiment of the present application is shown, which specifically shows a process of determining the first type of target from the valid compiling targets according to the dependency file. As shown in FIG. 3, the compiling method includes S3011-S3014. Figure 6 Referring to FIG. 3, a flow of a compiling method provided by an embodiment of the present application is shown, which specifically shows a process of determining the first type of target from the valid compiling targets according to the dependency file. As shown in FIG. 3, the compiling method includes S3011-S3014.
[0142] S3031, a dependency relationship correspondence table is established according to the dependency file, and the dependency relationship correspondence table includes multiple groups of key-value pairs, each group of key-value pairs taking one compiling target as a key and taking one compiling target that depends on the compiling target as a value.
[0143] When one compiling target is simultaneously depended on by multiple compiling targets, key-value pairs corresponding to the multiple compiling targets respectively can be established. For example, compiling target A and compiling target B both depend on compiling target C, and the server 120 can establish a key-value pair taking compiling target C as the key and taking compiling target A as the value, and a key-value pair taking compiling target C as the key and taking compiling target B as the value.
[0144] When one compiling target is not depended on by any target, the server 120 can also establish a key-value pair taking the compiling target as the key, but the value in the key-value pair is empty.
[0145] For example, referring to the dependency relationship diagram shown in FIG. 2, the server 120 can establish the dependency relationship correspondence table shown in Table 3. Figure 5
[0146] Table 3
[0147]
[0148] According to Table 3, it can be known that the value corresponding to target A is target D, and the values corresponding to target C and target D are empty.
[0149] In a possible design, the server 120 can perform hash processing on the keys and values in the dependency relationship correspondence table to obtain a hash table, so as to improve the efficiency of querying data in the dependency relationship correspondence table.
[0150] S3032, whether there is a value corresponding to each valid compiling target in the dependency relationship correspondence table is queried.
[0151] If there is no value corresponding to the valid compiling target in the dependency relationship correspondence table, S3033 is performed; if there is a value corresponding to the valid compiling target in the dependency relationship correspondence table, S3034 is performed.
[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 type target.
[0154] It can be understood that if the value corresponding to the valid compilation target does not exist in the dependency correspondence table, it means that the valid compilation target is not dependent on other compilation targets, and therefore it is determined to be a first type target.
[0155] S3044, determining that the valid compilation target is a second type target.
[0156] It can be understood that if the value corresponding to the valid compilation target exists in the dependency correspondence table, it means that the valid compilation target is dependent on other compilation targets, and therefore it is determined to be a second type target.
[0157] It can be understood that in the case of a hash table as the dependency correspondence table, the server 120 can query whether there is a value corresponding to the hash value of the valid compilation target in the dependency correspondence table, and obtain the corresponding judgment according to the query result. The judgment process is similar to the process shown in Figure 6 , and will not be repeated here.
[0158] Next, taking the dependency relationship diagram shown in Figure 5 as an example, the process of the server 120 determining the first type target according to the process shown in Figure 6 will be described. First, the server 120 can determine that the actual compilation products include targets A-E, and determine that the expected compilation products include targets A-E according to the dependency relationship file, so as to determine that the valid compilation targets include targets A-E. Then, the server 120 establishes the dependency correspondence table as shown in Table 3 according to the dependency relationship file, and queries the values of targets A-E in the dependency correspondence table, respectively. Since it is found that the values corresponding to targets C and D are empty, it is determined that targets C and D are first type targets in the valid compilation targets.
[0159] It can be understood that in the process of compiling the first type target, all compilation targets dependent on the first type target will be compiled. Therefore, the compilation result obtained by compiling all first type 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 full compilation of the code file, which is all valid compilation targets plus all byproducts.
[0160] For example, in the process of compiling Figure 5The target D shown depends on the target A, the target B and the target E, and all the by-products related thereto, i.e., compiling the target D can achieve the same compiling result as compiling the source file a.cpp and the source file b.cpp.
[0161] In S304, the server 120 determines the dependency file of each first-type target according to the dependency relationship file.
[0162] The dependency file of a compiling target includes the source file on which the compiling target depends. It should be noted that the dependency file of a compiling target can be one or more. For example, Figure 5 The target D shown depends on the source file a.cpp and the source file b.cpp, and thus the dependency file of the target D includes the source file a.cpp and the source file b.cpp. For another example, Figure 5 The target C shown depends on the source file c.cpp, and thus the dependency file of the target C includes the source file c.cpp.
[0163] In S305, the server 120 generates dependency information by taking each dependency file as a key and taking the first-type target corresponding to the dependency file as a value.
[0164] For example, the server 120 determines in S304 that the dependency file of the compiling target 1 includes the source file 1, and the dependency file of the compiling target 2 includes the source file 1 and the source file 2, and then the server 120 can generate the dependency information indicating that the value corresponding to the source file 1 includes the compiling target 1 and the compiling target 2, and the value corresponding to the source file 2 includes the compiling target 1. In other words, modifying the source file 1 can cause the compiling target 1 and the compiling target 2 to be recompiled, and modifying the source file 2 can cause the compiling target 2 to be recompiled.
[0165] For another example, the dependency information generated by the server 120 can be as shown in Table 2.
[0166] It can be understood that the dependency information can be used to quickly query the compiling target affected by each dependency file. In addition, the dependency information generated in the above manner can reduce the compiling target corresponding to each dependency file, so that the server 120 compiles a smaller number of compiling targets in the compiling verification process, and reduces the consumption of compiling resources.
[0167] In a possible design, the server 120 can also not perform S303, but directly determine the dependency file of each valid compiling target according to the dependency relationship file, and then generate dependency information by taking each dependency file as a key and taking the valid compiling target corresponding to the dependency file as a value. The dependency information can be as shown in Table 1. Although this manner can increase the compiling target corresponding to each dependency file, it can simplify the process of generating the dependency information by the server 120, and improve the efficiency of generating the dependency information by the server 120.
[0168] In the embodiments of the present application, the dependency information can be updated. For example, the server 120 can re-generate the dependency information when detecting that the build rule file is updated.
[0169] In summary, the compiling method provided by the embodiments of the present application can reduce the targets to be compiled in the compiling and verifying process, save compiling resources, and shorten the compiling time.
[0170] The embodiments of the present application also provide a chip system. As shown in Figure 7 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 a line. For example, the interface circuit 702 can be used to receive signals from other devices (for example, a memory of an electronic device). For another example, the interface circuit 702 can be used to send signals to other devices (for example, the processor 701). For example, the interface circuit 702 can read 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 the server can perform the steps in the above embodiments. Of course, the chip system can also include other discrete devices, which are not limited in the embodiments of the present application.
[0171] The embodiments of the present application also provide an electronic device. Please refer to Figure 8 , which is a schematic diagram of the hardware structure of the electronic device provided by the embodiments of the present application. As shown in Figure 8 , the electronic device 800 can include a processor 810 and a memory 820.
[0172] The processor 810 can be used to read and execute computer readable instructions. In a specific implementation, the processor 810 can mainly include a controller, an arithmetic unit and a register. The controller is mainly responsible for instruction decoding and sending control data for the operation corresponding to the instruction. The arithmetic unit is mainly responsible for saving the register operands and intermediate operation results temporarily stored in the instruction execution process. 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 RISC machine (ARM) architecture or a network processor (NP) architecture, etc., which is not limited here.
[0173] The memory 820 is coupled to the processor 810 for storing various software programs (e.g., the compiler described above) and / or sets of instructions. In particular implementations, the memory 820 can include a high-speed random access memory and can also include a nonvolatile memory, such as one or more magnetic disk storage devices, flash memory devices, or other non-volatile solid-state storage devices. The memory 820 can store an operating system, such as an embedded operating system, e.g., uCOS, VxWorks, RTLinux, etc.
[0174] It can be understood that the structure of the embodiments of the present application does not constitute a specific limitation on the electronic device 800. In other embodiments, the electronic device 800 can include more or fewer components than those shown, or combine certain components, or split certain components, or arrange different components. The illustrated components can be implemented in hardware, software, or a combination of software and hardware. Figure 8 It can be understood that the structure of the embodiments of the present application does not constitute a specific limitation on the electronic device 800. In other embodiments, the electronic device 800 can include more or fewer components than those shown, or combine certain components, or split certain components, or arrange different components. The illustrated components can be implemented in hardware, software, or a combination of software and hardware.
[0175] The embodiments also provide a computer readable storage medium, which stores computer instructions, when the computer instructions run on an electronic device, the electronic device executes the functions or steps of the above method embodiments.
[0176] The embodiments also provide a computer program product, when the computer program product runs on a computer, the computer executes the functions or steps of the above method embodiments.
[0177] In addition, the embodiments of the present application also provide an apparatus, which can be a chip, a component or a module, and the apparatus can include a processor and a memory connected to each other. The memory is used to store computer execution instructions, and when the apparatus runs, the processor can execute the computer execution instructions stored in the memory to make the chip execute the functions or steps of the above method embodiments.
[0178] The electronic device, the computer readable storage medium, the computer program product or the chip provided by the embodiments can achieve the beneficial effects of the corresponding methods provided above, and the beneficial effects are not repeated here.
[0179] Through the description of the above embodiments, those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above functional modules is taken as an example for illustration, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the apparatus is divided into different functional modules to complete all or part of the functions described above.
[0180] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented by other manners. For example, the apparatus embodiments described above are merely illustrative, for example, the division of the modules or units is merely a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another apparatus, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units or components shown or discussed can be indirect coupling or communication connection through some interfaces, apparatuses or units, and can be electrical, mechanical or other forms.
[0181] The units described as separate components can or can not be physically separate, and the components shown as units can be one physical unit or a plurality of physical units, that is, can be located in one place or can be distributed to a plurality of different places. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0182] In addition, the functional units in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0183] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application essentially or the part of the prior art that makes a contribution or the whole or part of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium and includes a plurality of instructions for causing an apparatus (which can be a single-chip microcomputer, a chip, etc.) or a processor to execute all or part of the steps of the method of the embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various storage medium that can store program codes.
[0184] Finally, it should be noted that the above embodiments are merely used to illustrate the technical solutions of the present application and not to limit the present application. Although the present application has been described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that the technical solutions of the present application can be modified or replaced equivalently without departing from the spirit and scope of the technical solutions of the present application.
Claims
1. A method of compiling, characterized by, The method comprises: acquiring a dependency file, the dependency file being used to indicate a dependency between compilation targets; determining valid compilation targets from actual compilation products according to the dependency file; wherein the actual compilation products comprise main products and by-products obtained by actual compilation, the valid compilation targets comprise main products obtained by actual compilation, the main products comprise compilation results defined by the dependency, and the by-products are compilation results not defined by the dependency; determining first-class targets from the valid compilation targets according to the dependency file, the first-class targets being compilation targets not dependent on other compilation targets; determining dependency files of each of the first-class targets according to the dependency file; establishing a mapping relationship between each of the dependency files and the first-class targets dependent on the dependency files, to obtain dependency information; when detecting that a source file not affecting a compilation step is updated, acquiring modification information; wherein the modification information comprises a modification file, and the modification file is the updated source file; querying a compilation target corresponding to each of the modification files from the dependency information, to obtain first targets; wherein the dependency information comprises dependency files and compilation targets corresponding to the dependency files, the dependency files are source files dependent on at least one compilation target, the compilation targets corresponding to the dependency files comprise first-class targets in all compilation targets dependent on the dependency files, and the compilation targets comprise at least one of an executable file, a library file and an intermediate representation generated according to source code; compiling source files dependent on the first targets in sequence, the source files dependent on the first targets comprising all source files dependent on the first targets in a process of building the first targets.
2. The method of claim 1, wherein, The determining of the first-class targets from the valid compilation targets according to the dependency file comprises: establishing a dependency relationship correspondence table according to the dependency file, the dependency relationship correspondence table comprising a plurality of groups of key-value pairs, each group of key-value pairs taking a compilation target as a key and taking a compilation target dependent on the compilation target as a value; taking each of the valid compilation targets as a key, querying whether a value corresponding to the valid compilation target exists in the dependency relationship correspondence table; if the value corresponding to the valid compilation target does not exist in the dependency relationship correspondence table, determining that the valid compilation target is the first-class target.
3. The method of claim 1, wherein, The determining of the first-class targets from the valid compilation targets according to the dependency file comprises: taking compilation targets involved in the dependency file as nodes, establishing an edge connecting two nodes corresponding to two compilation targets according to a dependency relationship between the two compilation targets, to obtain a dependency relationship graph; wherein the dependency relationship graph comprises leaf nodes, and the leaf nodes correspond to compilation targets not dependent on other compilation targets; determining an intersection of the compilation targets corresponding to the leaf nodes and the valid compilation targets as the first-class targets.
4. The method according to claim 2 or 3, characterized in that, The determining of the valid compilation targets from the actual compilation products according to the dependency file comprises: determining expected compilation products according to the dependency file, the expected compilation products comprising all compilation targets involved in the dependency file; querying the actual compilation product from a preset compilation product path; determining an intersection of the expected compilation product and the actual compilation product as the effective compilation target.
5. The method of claim 1, wherein, Before the obtaining the modification information, the method further comprises: when detecting that the source file is updated, judging whether the build rule file is updated; if the build rule file is not updated, determining that the source file which does not affect the compiling step is updated.
6. An electronic device, comprising: The electronic device comprises a memory and a processor; the processor is coupled with the memory; wherein the memory is configured 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 claimed in any one of claims 1-5.
7. A computer readable storage medium characterized by comprise computer instructions; when the computer instructions run on an electronic device, the electronic device executes the method as claimed in any one of claims 1-5.
Citation Information
Patent Citations
Compiling method and device
CN108304184A
PLC software incremental compiling method and device
CN117806651A