Code compilation method, device, electronic device and storage medium

By building a virtual POM dependency diagram and correcting it, the compilation error problem caused by the Maven server-associated dependency module is solved, and the accuracy and efficiency of code compilation are improved.

CN114461217BActive Publication Date: 2024-12-31BEIJING DAJIA INTERNET INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202111590796.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-23
Publication Date
2024-12-31
Estimated Expiration
2041-12-23

AI Technical Summary

Technical Problem

In the prior art, when compiling code by the Maven server associated with dependency modules, it is easy to cause dependency errors, resulting in compilation errors, and affecting compilation efficiency and accuracy.

Method used

By obtaining the source code dependency diagram of the current project code, replacing the target compilation file, building a virtual POM dependency diagram, and correcting it, generating an accurate target dependency diagram for compilation.

Benefits of technology

Real-time accuracy and lossless single-point replacement of source code module dependencies are realized, which improves the accuracy and efficiency of code compilation, avoids dependency errors, and adapts to different application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114461217B_ABST
    Figure CN114461217B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a code compilation method, device, electronic device and storage medium. The method includes: obtaining the current source code dependency graph of multiple source code modules in the current project code and the first source code module; replacing the first source code module in the current source code dependency graph with the target compilation file to obtain the first intermediate dependency graph; based on the current source code dependency graph, constructing a virtual POM dependency graph for the target compilation file in the first intermediate dependency graph to obtain the second intermediate dependency graph; based on the dependency compilation file, correcting the dependency in the second intermediate dependency graph to obtain the target dependency graph; compiling multiple source code modules based on the target dependency graph to obtain a code compilation file. According to the technical solution provided by the present disclosure, the accuracy of code compilation can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of data processing technology, and in particular to a code compilation method, device, electronic device and storage medium. Background Art

[0002] The code will go through a compilation process when it is used. However, as the amount of code increases, the compilation time becomes longer and longer. In order to speed up the compilation, in the related technology, when publishing the compiled file AAR (Android Archive, a binary archive file of the Android library project) of the source code module, the dependencies will be translated into the POM (project object model) file and uploaded to the Maven server, and the dependent modules will be associated through the Maven Url. In the subsequent compilation process triggered by the modification of the source code module, the unmodified source code module can be directly replaced with the corresponding AAR in Maven to speed up the compilation. This way of using dependencies in the Maven server is prone to dependency errors, which in turn lead to compilation errors. Summary of the invention

[0003] The present disclosure provides a code compilation method, device, electronic device and storage medium to at least solve the problem of how to improve the efficiency and accuracy of code compilation in the related art. The technical solution of the present disclosure is as follows:

[0004] According to a first aspect of an embodiment of the present disclosure, a code compiling method is provided, comprising:

[0005] Obtaining a current source code dependency graph of multiple source code modules in the current project code and a first source code module, where the first source code module is any source code module having a corresponding target compiled file among the multiple source code modules;

[0006] Replacing the first source code module in the current source code dependency graph with the target compiled file to obtain a first intermediate dependency graph;

[0007] Based on the current source code dependency graph, constructing a virtual project object model (POM) dependency graph for the target compiled file in the first intermediate dependency graph to obtain a second intermediate dependency graph; the virtual POM dependency graph represents the dependency relationship between the target compiled file and the dependent compiled file having a dependency relationship with the target compiled file;

[0008] Based on the dependency compilation file, modify the dependency relationship in the second intermediate dependency relationship graph to obtain a target dependency relationship graph;

[0009] The multiple source code modules are compiled based on the target dependency graph to obtain a code compilation file.

[0010] In a possible implementation, the modifying the dependency relationship in the second intermediate dependency relationship graph based on the dependency compilation file to obtain the target dependency relationship graph includes:

[0011] Determine a second source code module corresponding to the dependent compiled file;

[0012] Based on the second source code module, the dependency relationship in the virtual POM dependency relationship graph is modified to obtain the target dependency relationship graph.

[0013] In a possible implementation, the modifying the dependency relationship in the virtual POM dependency relationship graph based on the second source code module to obtain the target dependency relationship graph includes:

[0014] The dependent compiled file in the virtual POM dependency graph is replaced with the second source code module to obtain the target dependency graph.

[0015] In a possible implementation, the modifying the dependency relationship in the second intermediate dependency relationship graph based on the dependency compilation file to obtain the target dependency relationship graph includes:

[0016] Determine a second source code module corresponding to the dependent compiled file;

[0017] If there is no compiled file matching the second source code module in the project code management system, replacing the dependent compiled file in the second intermediate dependency graph with the second source code module to obtain the target dependency graph;

[0018] If there is a compiled file matching the second source code module in the project code management system, the second source code module in the second intermediate dependency graph is replaced with the dependent compiled file to obtain the target dependency graph.

[0019] In a possible implementation, obtaining the first source code module includes:

[0020] Based on the current source code dependency graph, obtaining a dependent source code module of each source code module; the dependent source code module is at least one of the multiple source code modules;

[0021] Determine module identification information of each source code module based on each source code module and its dependent source code modules;

[0022] Determine a target compiled file in a project code management system that matches the module identification information;

[0023] The first source code module corresponding to the target compiled file is determined from the multiple source code modules.

[0024] In a possible implementation, determining the module identification information of each source code module based on each source code module and the dependent source code modules of each source code module includes:

[0025] Obtain summary information of each source code module and summary information of the dependent source code modules;

[0026] The module identification information of each source code module is determined according to the summary information of each source code module and the summary information of the dependent source code modules having a dependency relationship with each source code module.

[0027] In a possible implementation, the method further includes:

[0028] A code update event is detected, and a compiled file of a source code module to be released and a project object model POM file to be released are generated, wherein the source code module to be released is a source code module whose module identification information does not match the compiled file identification information among the multiple source code modules, and the compiled file identification information is the identification information of the compiled file in the project code management system; and the dependency relationship in the POM file to be released is an empty dependency relationship;

[0029] The compiled file of the source code module to be released and the POM file to be released are released to the project code management system.

[0030] According to a second aspect of an embodiment of the present disclosure, a code compiling device is provided, including:

[0031] An acquisition module is configured to execute acquisition of a current source code dependency graph of multiple source code modules in a current project code and a first source code module, wherein the first source code module is any source code module having a corresponding target compiled file among the multiple source code modules;

[0032] A replacement module is configured to replace the first source code module in the current source code dependency graph with the target compiled file to obtain a first intermediate dependency graph;

[0033] A virtual POM construction module is configured to execute, based on the current source code dependency graph, construct a virtual project object model POM dependency graph for the target compiled file in the first intermediate dependency graph to obtain a second intermediate dependency graph; the virtual POM dependency graph represents a dependency relationship between the target compiled file and a dependent compiled file having a dependency relationship with the target compiled file;

[0034] A correction module is configured to perform correction processing on the dependency relationship in the second intermediate dependency relationship graph based on the dependency compilation file to obtain a target dependency relationship graph;

[0035] The compiling module is configured to compile the plurality of source code modules based on the target dependency graph to obtain a code compilation file.

[0036] In a possible implementation, the correction module includes:

[0037] A first determining unit is configured to determine a second source code module corresponding to the dependent compiled file;

[0038] The first correction unit is configured to perform correction processing on the dependency relationship in the virtual POM dependency relationship graph based on the second source code module to obtain the target dependency relationship graph.

[0039] In a possible implementation manner, the first correction unit includes:

[0040] The correction subunit is configured to replace the dependent compiled file in the virtual POM dependency graph with the second source code module to obtain the target dependency graph.

[0041] In a possible implementation, the correction module includes:

[0042] A second determining unit is configured to determine a second source code module corresponding to the dependent compiled file;

[0043] A second correction unit is configured to replace the dependent compiled file in the second intermediate dependency graph with the second source code module if there is no compiled file matching the second source code module in the project code management system, so as to obtain the target dependency graph;

[0044] The third correction unit is configured to execute, if there is a compilation file matching the second source code module in the project code management system, replacing the second source code module in the second intermediate dependency graph with the dependent compilation file to obtain the target dependency graph.

[0045] In a possible implementation, the acquisition module includes:

[0046] A dependent source code module acquisition unit, based on the current source code dependency graph, acquires a dependent source code module of each source code module; the dependent source code module is at least one of the multiple source code modules;

[0047] A module identification determination unit is configured to determine module identification information of each source code module based on each source code module and its dependent source code modules;

[0048] A matching processing unit, configured to determine a target compiled file matching the module identification information in a project code management system;

[0049] The first source code module obtaining unit is configured to determine the first source code module corresponding to the target compiled file from the multiple source code modules.

[0050] In a possible implementation manner, the module identification determination unit includes:

[0051] A summary acquisition subunit is configured to execute acquisition of summary information of each source code module and summary information of the dependent source code module;

[0052] The identification information determining subunit is configured to determine the module identification information of each source code module according to the summary information of each source code module and the summary information of the dependent source code module having a dependency relationship with each source code module.

[0053] In a possible implementation, the method further includes:

[0054] A source code publishing module is configured to execute a code update event and generate a compiled file of a source code module to be published and a project object model POM file to be published, wherein the source code module to be published is a source code module whose module identification information does not match the compiled file identification information among the multiple source code modules, and the compiled file identification information is the identification information of the compiled file in the project code management system; and the dependency relationship in the POM file to be published is an empty dependency relationship;

[0055] The upload module is configured to execute publishing of the compiled file of the source code module to be published and the POM file to be published to the project code management system.

[0056] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement a method as described in any one of the above-mentioned first aspects.

[0057] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute any method described in the first aspect of the embodiment of the present disclosure.

[0058] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, comprising computer instructions, which, when executed by a processor, enable a computer to execute any one of the methods described in the first aspect of an embodiment of the present disclosure.

[0059] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:

[0060] By dynamically constructing a virtual POM dependency graph based on the accurate current source code dependency graph at compile time, and determining the target dependency graph for compilation based on the virtual POM dependency graph, the real-time accuracy of source code module dependencies can be guaranteed, lossless single-point replacement of the dependency graph can be achieved, and the accuracy of the target dependency graph can be improved; and this method of dynamically constructing a virtual POM dependency graph at compile time can adapt to various application scenarios in real time, avoid dependency errors in different application scenarios, and further improve the accuracy of code compilation.

[0061] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.

[0063] Figure 1 It is a schematic diagram of an application environment according to an exemplary embodiment.

[0064] Figure 2 The figure is a flowchart of a code compiling method according to an exemplary embodiment.

[0065] Figure 3 The present invention is a flow chart of a method for obtaining a first source code module according to an exemplary embodiment.

[0066] Figure 4 The diagram is a schematic diagram of a source code dependency graph according to an exemplary embodiment.

[0067] Figure 5 The present invention is a flow chart showing a method for determining module identification information of each source code module based on each source code module and its dependent source code modules according to an exemplary embodiment.

[0068] Figure 6 The figure is a schematic diagram of a process of determining module identification information according to an exemplary embodiment.

[0069] Figure 7a to Figure 7gThe present invention is a schematic diagram of a construction process of a virtual POM dependency graph according to an exemplary embodiment.

[0070] Figure 8 The figure is a block diagram of a code compiling device according to an exemplary embodiment.

[0071] Fig. 9 The invention is a block diagram of an electronic device for code compilation according to an exemplary embodiment.

[0072] Fig.10 is a block diagram of another electronic device for code compilation according to an exemplary embodiment. DETAILED DESCRIPTION

[0073] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.

[0074] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0075] See also Figure 1 , Figure 1 is a schematic diagram of an application environment according to an exemplary embodiment. Figure 1 As shown, the application environment may include a project code management system 01 and a terminal 02 .

[0076] In an optional embodiment, the project code management system 01 can be used to manage compiled code. For example, when the project code management system 01 is a Maven system, it can be used to manage the compiled file AAR (or called aar) after the code is compiled. The project code management system 01 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0077] In an optional embodiment, the terminal 02 can be used for code compilation processing. Specifically, the terminal 02 can include but is not limited to smart phones, desktop computers, tablet computers, laptops, smart speakers, digital assistants, augmented reality (AR) / virtual reality (VR) devices, smart wearable devices and other types of electronic devices. Optionally, the operating system running on the electronic device can include but is not limited to Android system, IOS system, Linux, Windows, etc.

[0078] In addition, it should be noted that Figure 1 What is shown is only one application environment of the code compilation method provided by the present disclosure.

[0079] In the embodiments of this specification, the server 01 and the terminal 02 may be directly or indirectly connected via wired or wireless communication, and this application does not impose any limitation thereto.

[0080] It should be noted that the following figure shows a possible sequence of steps, which is not actually limited to this sequence. Some steps can be executed in parallel without relying on each other. The user information (including but not limited to user device information, user personal information, user behavior information, etc.) and data (including but not limited to data for display, compiled data, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.

[0081] Figure 2 FIG. 1 is a flowchart of a code compiling method according to an exemplary embodiment. Figure 2 As shown, the following steps may be included:

[0082] In step S201, a current source code dependency graph of multiple source code modules in the current project code and a first source code module are obtained. The first source code module is any source code module having a corresponding target compiled file among the multiple source code modules.

[0083] In the embodiment of this specification, the current project code may refer to the code stored in a code repository (such as a git repository); the multiple source code modules may refer to all the source code modules included in the current project code, that is, all the source code modules in a git repository. Among them, a source code module may correspond to a business function, and the present disclosure does not limit the division method of the source code module. Optionally, the step S201 can be triggered when a compilation event is detected, and the present disclosure does not limit this. It should be noted that the multiple source code modules in the current project code can all be updated, for example, a certain source code module can be modified by the code writer based on business needs, or at least one source code module in the multiple source code modules is a newly added source code module. In practical applications, the current source code dependency graph of multiple source code modules can be determined based on the reference relationship between multiple source code modules, so as to obtain the current source code dependency graph of multiple source code modules in the current project code. The current source code dependency graph can be a directed acyclic graph, and the current source code dependency graph can include multiple nodes and dependencies between nodes, and the multiple nodes can be represented by the module identification information of multiple source code modules. As an example, the source code dependency graph can be as follows Figure 7a As shown, A, B, C and D can be module identification information of each of multiple source code modules in the current project code.

[0084] In actual applications, the compiled file AAR after the source code module is compiled can be uploaded to the Maven system. Based on this, multiple compiled files of the current project code can be obtained from the Maven system, so that the target compiled files that match the current multiple source code modules can be screened out from the multiple compiled files. For example, the source code identification information of a source code module and the file identification information of the compiled file of the source code module have a corresponding relationship, or the source code identification information of a source code module and the file identification information of the compiled file of the source code module are the same. Based on this, the source code identification information can be used to match the file identification information, and the compiled files corresponding to the file identification information that is the same as the module identification information of each source code module or has a corresponding relationship are used as the target compiled files that match each source code module. Accordingly, these source code modules with matching target compiled files can be used as the first source code modules.

[0085] In a possible implementation, in order to improve the accuracy of linkage update, such as Figure 3 As shown, the first source code module can be obtained by following the steps below:

[0086] In step S301, based on the current source code dependency graph, a dependent source code module of each source code module is obtained; the dependent source code module is at least one of the multiple source code modules.

[0087] In practical applications, the dependent source code module of a source code module may refer to the source code module that is visible to the source code module in the dependency graph of the source code module (i.e., the visible dependent source code module). As an example, the source code dependency graph of each source code module can be extracted from the current source code dependency graph, such as Figure 4 The source code dependency diagram of source code module A is shown, where the dotted line represents a non-transitive dependency (implementation) and the solid line represents a transitive dependency (such as an API). For example, visible in the source code module dependency means that the number of transitive dependencies or non-transitive dependencies between the source code module and the visible dependent source code module is less than 2. Figure 4 The source code modules visible to source code module A may be source code module B, source code module C, and source code module D.

[0088] Optionally, based on the reference relationship between multiple source code modules, dependent source code modules with which each source code module has a dependency relationship can be obtained. That is, based on the reference relationship between each source code module in the current source code dependency graph, the dependent source code modules of each source code module can be obtained. As an example, a source code module referenced by a source code module and located in a preset level can be used as a dependent source code module of the source code module, wherein the preset level can be the first level or the second level, and the present disclosure does not limit this. For example, if source code module A references source code module B, then source code module B is considered to be at the first level of source code module A; if source code module B references source code module C, then source code module C is considered to be at the second level of source code module A.

[0089] In step S303, module identification information of each source code module is determined based on each source code module and its dependent source code modules.

[0090] In the embodiment of this specification, in order to realize that a source code module and a source code module that depends on the source code module can be updated and compiled in a linked manner and updated and released in a linked manner, the module identification information of each source code module is determined based on each source code module and the source code module that depends on the source code module. Among them, the source code module that depends on the source code module can refer to the source code module that is a visible dependent source code module of the source code module. For example Figure 4 As shown, dependence Figure 4 The source code modules of source code module D are source code module B and source code module A. If source code module D is changed, even if source code module A and source code module B are not changed, the module identification information of source code module A and source code module B will be changed due to the change of source code module D, so that the linked update compilation and linked update release between source code modules with dependency relationships can be realized through the code compilation method of the embodiment of this specification.

[0091] In one example, the code contents of each source code module and the dependent source code module can be extracted respectively, and then the code contents are processed by a preset function to obtain module identification information. The preset function here can be a hash function or other function that can realize the mapping function, which is not limited in the present disclosure.

[0092] In one possible implementation, Figure 5 As shown, step S303 may include:

[0093] In step S501, the summary information of each source code module and the summary information of the dependent source code modules are obtained;

[0094] In step S503, module identification information of each source code module is determined according to the summary information of each source code module and the summary information of the dependent source code modules of each source code module.

[0095] In practical applications, the above summary information can be obtained based on a preset summary algorithm. The preset summary algorithm may include MD5 (Message-Digest Algorithm), SHA1 (Secure Hash Algorithm 1), SHA512 (Secure Hash Algorithm512), signature algorithm, etc., which is not limited in the present disclosure.

[0096] As an example, Figure 6 As shown, MD5 can be used to extract a summary of the content of source code module A itself to obtain summary information A of source code module A; and MD5 can be used to extract a summary of the content of visible dependent modules B, C and D of source code module A respectively, so as to obtain summary information B of source code module B, summary information C of source code module C, and summary information D of source code module D. Further, summary information B, summary information C and summary information D can be sorted to obtain sorted summary information. Thus, the content of the sorted summary information can be extracted to obtain module identification information of source code module A. Based on the same method, module identification information of each source code module can be obtained. Among them, the sorting of each source code module can be preset. By determining the module identification information of each source code module through the summary information of each source code module and the summary information of the dependent source code modules of each source code module, the security and accuracy of the module identification information can be improved.

[0097] In step S305, a target compilation file matching the module identification information is determined in the project code management system.

[0098] In the embodiments of this specification, in order to improve the coding efficiency, the compiled source code module can be obtained, for example, all the compiled files associated with the current project code, such as all AAR files, can be downloaded from the project code management system; wherein, in the project code management system, all the compiled files associated with the current project code each have corresponding file identification information, and the file identification information of each compiled file is determined based on the source code module corresponding to each compiled file and the dependent source code module of the corresponding source code module, which can be specifically determined based on the implementation method of the above-mentioned step S303, and will not be repeated here. In other words, the module identification information of the source code module A is the same as the file identification information of the compiled file A corresponding to the source code module A, the module identification information is used to uniquely identify the source code module in the git repository, and the file identification information is used to uniquely identify the compiled file in maven.

[0099] Furthermore, the module identification information can be used to match the file identification information in Maven to determine the target file identification information that is the same as the module identification information; thereby, the target compiled file corresponding to the target file identification information can be obtained. That is, the target compiled file that matches the module identification information can refer to the target file identification information of the target compiled file matching the module identification information. Among them, the module identification information that can hit the target compiled file in Maven can be explained from the above method of determining the module identification information: the first source code module corresponding to the module identification information that hits the target compiled file has no code update, and the corresponding dependent source code module has no code update; these first source code modules that have not been updated can be skipped directly without compilation during this compilation process to improve compilation efficiency. Moreover, based on this matching method of module identification information, the first source code module can be found automatically and accurately, which can improve the accuracy of compilation.

[0100] In step S307, a first source code module corresponding to the target compiled file is determined from the multiple source code modules.

[0101] In the embodiment of the present specification, a first source code module corresponding to the target compiled file, i.e., a source code module that has not changed, can be determined from multiple source code modules. For example, a source code module corresponding to the module identification information that is the same as the file identification information of the target compiled file can be determined from multiple source code modules as the first source code module.

[0102] By using the current source code dependency graph to obtain dependent source code modules, the real-time accuracy of dependent source code modules can be guaranteed; and by determining the module identification information of each source code module and the dependent source code modules of each source code module, and determining the target compilation file based on the module identification information, the source code modules that need to be compiled in conjunction later can be automatically, efficiently and accurately determined, thereby improving the accuracy of the first source code module and providing a guarantee for subsequent precise compilation.

[0103] In step S203, the first source code module in the current source code dependency graph is replaced with the target compiled file to obtain a first intermediate dependency graph;

[0104] In step S205, based on the current source code dependency graph, a virtual POM dependency graph is constructed for the target compiled file in the first intermediate dependency graph to obtain a second intermediate dependency graph; the virtual POM dependency graph represents the dependency relationship between the target compiled file and the dependent compiled file having a dependency relationship with the target compiled file;

[0105] In step S207, based on the dependency compilation file, the dependency relationship in the second intermediate dependency relationship graph is modified to obtain a target dependency relationship graph.

[0106] See also Figure 7a to Figure 7d , introduces the process of building a virtual POM dependency graph and determining the source code modules to be compiled. For example, the dependency relationship of four source code modules (source code modules A to D) can be as follows Figure 7a The directed acyclic graph shown in Figure 1. In order to ensure the losslessness of the dependency, the target dependency graph can be obtained by building a virtual POM dependency graph. Assuming that the target compilation file is C.aar, the following takes C.aar as an example for introduction.

[0107] Specifically, Figure 7a Replace C in the current source code dependency graph with C.aar (target compilation file), and you get Figure 7b The first intermediate dependency diagram shown in Figure 1. Since C.aar can only point to AAR in Maven, Figure 7b The dependency of C.aar in the file is lost. However, in order to avoid the problem that the dependencies in the POM uploaded when AAR is released are fixed, which leads to the problem that it cannot adapt to various application scenarios and causes dependency errors, the present invention selects the POM file uploaded when releasing to not include dependencies. Based on this, it is necessary to build the dependency of C.aar here. For example, based on the current source code dependency graph, a virtual POM dependency graph can be built for C.aar in the first intermediate dependency graph to obtain a second intermediate dependency graph, such as Figure 7cAs shown, the virtual POM dependency graph may include C.aar, D.aar, and a directed edge from C.aar to D.aar, and D.aar may be regarded as a dependent compiled file of C.aar.

[0108] Furthermore, due to Figure 7c There are D and D.aar in it, which needs to be corrected, that is, it is necessary to determine whether a node in the graph is a source code module or a compiled file, so that it can be clear whether compilation is required. In one possible implementation, the second source code module corresponding to the dependent compiled file can be determined, such as D corresponding to D.aar. And based on the second source code module, the dependency relationship in the virtual POM dependency graph can be corrected to obtain the target dependency graph. For example, the dependent compiled file in the virtual POM dependency graph is replaced with the second source code module to obtain the target dependency graph. For example, the gradle tool can be used to replace the dependent compiled file with the second source code module, and the present disclosure is not limited to this, so as to obtain the target dependency graph, such as Figure 7d By directly replacing the dependent compiled files with the corresponding source code modules, the correction operation is relatively simple and the accurate execution of the correction is guaranteed.

[0109] In another possible implementation, based on this, the second source code module corresponding to the dependent compiled file can be determined, for example, D corresponding to D.aar. And the second source code module and the dependent compiled file in the second intermediate dependency graph can be corrected to obtain the target dependency graph. The specific correction process may include:

[0110] If there is no compiled file matching the second source code module in the project code management system, replace the second source code module and the dependent compiled files in the second intermediate dependency graph with the second source code module;

[0111] If there is a compiled file matching the second source code module in the project code management system, the second source code module and the dependent compiled file in the second intermediate dependency graph are replaced with the dependent compiled file.

[0112] like Figure 7c For example, if D.aar does not exist in Maven, you can merge D.aar and D into D, such as Figure 7d The target dependency graph obtained in this way can represent both the source code modules that need to be compiled and the source code modules that can be skipped for compilation, making the determination of the source code modules to be compiled more accurate and improving the correction efficiency.

[0113] It should be noted that when there are multiple target compilation files, for example, the hit target compilation files include C.aar and B.aar, the above S203 to S207 can be executed on C.aar and B.aar in sequence to obtain the target dependency graph; or S203 to S207 can be executed on C.aar and B.aar in parallel. Among them, when executing in series, the currently executed target compilation file can be executed based on the dependency graph obtained after the previous target compilation file is executed. For example Figure 7d This is the dependency graph after C.aar executes S203 to S207. Based on this, we can execute the above S203 to S207 on B.aar to obtain the target dependency graph as shown in Figure 7e Or you can execute them separately to get the dependency graph of B.aar, as shown Figure 7f As shown. Figure 7d and Figure 7e For example, the same source code modules are merged into one source code module, and the matching source code modules and compiled files are merged into a compiled file to obtain the target dependency graph, such as Figure 7e shown.

[0114] In parallel execution, the second intermediate dependency graph can be as follows Figure 7g As shown, the dependent compiled file D.aar of B.aar and the dependent compiled file D.aar of C.aar can be corrected to obtain the target dependency graph, as shown in Figure 7e shown.

[0115] In step S209, multiple source code modules are compiled based on the target dependency graph to obtain a code compilation file.

[0116] In the embodiments of this specification, in order to improve compilation efficiency, the compilation of source code modules with corresponding AARs can be skipped. Based on this, multiple source code modules can be compiled based on the target dependency graph to obtain code compilation files, so that the target compilation files can be skipped. The specific compilation process can be performed using the gradle tool, which is not limited in this disclosure. As an example, the compilation process may not translate dependencies, that is, the dependencies in the POM file may be empty.

[0117] By dynamically constructing a virtual POM dependency graph based on the accurate current source code dependency graph at compile time, and determining the target dependency graph for compilation based on the virtual POM dependency graph, the real-time accuracy of source code module dependencies can be guaranteed, lossless single-point replacement of the dependency graph can be achieved, and the accuracy of the target dependency graph can be improved; and this method of dynamically constructing a virtual POM dependency graph at compile time can adapt to various application scenarios in real time, avoid dependency errors in different application scenarios, and further improve the accuracy of code compilation.

[0118] The above-mentioned compiled file can be a source code module published to Maven. In order to provide the above-mentioned code compilation with a compiled file that can be matched to accelerate the compilation, a production process can be maintained. The production process can be user-insensitive and triggered by a code update event. Specifically, the production process can include the following steps:

[0119] A code update event is detected, and a compiled file of a source code module to be released and a POM file to be released are generated. The source code module to be released is a source code module whose module identification information does not match the compiled file identification information among multiple source code modules. The compiled file identification information is the identification information of the compiled file in the project code management system. The dependency relationship in the POM file to be released in the project code management system is an empty dependency relationship.

[0120] Publish the compiled files of the source code modules to be released and the POM files to be released to the project code management system.

[0121] In the embodiments of this specification, the source code module to be released may refer to a source code module whose code has changed, that is, a source code module that does not have a matching compiled file in Maven. When a code update event is detected, the above steps S201 to S209 may be executed to obtain the compiled file at the time of the code update event, so that the compiled file of the source code module to be released may be determined from the compiled file at the time of the code update event. And the POM file to be released may be generated based on the current source code dependency graph, and the dependency in the POM file to be released is empty, for example, <dependencis>It can be empty. Furthermore, the compiled files of the source code modules to be released and the POM files to be released can be published to the project code management system. This ensures that the project code management system has a relatively complete compiled file at the current moment, providing real-time and effective services for user code compilation, thereby improving the efficiency of user-side code compilation.

[0122] Figure 8 is a block diagram of a code compiling device according to an exemplary embodiment. Figure 8 , the device may include:

[0123] The acquisition module 801 is configured to execute acquisition of a current source code dependency graph of multiple source code modules in the current project code and a first source code module, where the first source code module is any source code module having a corresponding target compiled file among the multiple source code modules;

[0124] A replacement module 803 is configured to replace the first source code module in the current source code dependency graph with the target compiled file to obtain a first intermediate dependency graph;

[0125] A virtual POM construction module 805 is configured to execute, based on the current source code dependency graph, construct a virtual project object model POM dependency graph for the target compiled file in the first intermediate dependency graph to obtain a second intermediate dependency graph; the virtual POM dependency graph represents the dependency relationship between the target compiled file and the dependent compiled file having a dependency relationship with the target compiled file;

[0126] A correction module 807 is configured to perform correction processing on the dependency relationship in the second intermediate dependency relationship graph based on the dependency compilation file to obtain a target dependency relationship graph;

[0127] The compiling module 809 is configured to compile the multiple source code modules based on the target dependency graph to obtain a code compilation file.

[0128] In a possible implementation, the correction module 807 may include:

[0129] A first determining unit is configured to determine a second source code module corresponding to the dependent compiled file;

[0130] The first correction unit is configured to perform correction processing on the dependency relationship in the virtual POM dependency relationship graph based on the second source code module to obtain the target dependency relationship graph.

[0131] In a possible implementation manner, the first correction unit includes:

[0132] The correction subunit is configured to replace the dependent compiled file in the virtual POM dependency graph with the second source code module to obtain the target dependency graph.

[0133] In a possible implementation, the correction module 807 may include:

[0134] A second determining unit is configured to determine a second source code module corresponding to the dependent compiled file;

[0135] A second correction unit is configured to replace the dependent compiled file in the second intermediate dependency graph with the second source code module if there is no compiled file matching the second source code module in the project code management system, so as to obtain the target dependency graph;

[0136] The third correction unit is configured to execute, if there is a compilation file matching the second source code module in the project code management system, replacing the second source code module in the second intermediate dependency graph with the dependent compilation file to obtain the target dependency graph.

[0137] In a possible implementation, the acquisition module 801 may include:

[0138] A dependent source code module acquisition unit, based on the current source code dependency graph, acquires a dependent source code module of each source code module; the dependent source code module is at least one of the multiple source code modules;

[0139] A module identification determination unit is configured to determine module identification information of each source code module based on each source code module and its dependent source code modules;

[0140] A matching processing unit, configured to determine a target compiled file matching the module identification information in a project code management system;

[0141] The first source code module obtaining unit is configured to determine the first source code module corresponding to the target compiled file from the multiple source code modules.

[0142] In a possible implementation manner, the module identification determination unit includes:

[0143] A summary acquisition subunit is configured to execute acquisition of summary information of each source code module and summary information of the dependent source code module;

[0144] The identification information determining subunit is configured to determine the module identification information of each source code module according to the summary information of each source code module and the summary information of the dependent source code module having a dependency relationship with each source code module.

[0145] In a possible implementation, the device may further include:

[0146] A source code publishing module is configured to execute a code update event and generate a compiled file of a source code module to be published and a project object model POM file to be published, wherein the source code module to be published is a source code module whose module identification information does not match the compiled file identification information among the multiple source code modules, and the compiled file identification information is the identification information of the compiled file in the project code management system; and the dependency relationship in the POM file to be published is an empty dependency relationship;

[0147] The upload module is configured to execute publishing of the compiled file of the source code module to be published and the POM file to be published to the project code management system.

[0148] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0149] Fig. 9 is a block diagram of an electronic device for code compilation according to an exemplary embodiment. The electronic device may be a terminal, and its internal structure diagram may be as shown in FIG. Fig. 9 As shown. The electronic device includes a processor, a memory, a network interface, a display screen and an input device connected via a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a method of code compilation is implemented. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the housing of the electronic device, or an external keyboard, touchpad or mouse, etc.

[0150] Those skilled in the art will understand that Fig. 9 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present disclosure, and does not constitute a limitation on the electronic device to which the scheme of the present disclosure is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0151] Fig.10 is a block diagram of another electronic device for code compilation according to an exemplary embodiment. The electronic device may be a server, and its internal structure diagram may be as shown in FIG. Fig.10 As shown. The electronic device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method of code compilation is implemented.

[0152] Those skilled in the art will understand that Fig.10 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present disclosure, and does not constitute a limitation on the electronic device to which the scheme of the present disclosure is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0153] In an exemplary embodiment, an electronic device is also provided, including: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the code compiling method in the embodiment of the present disclosure.

[0154] In an exemplary embodiment, a computer-readable storage medium is also provided, and when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the code compilation method in the embodiment of the present disclosure. The computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0155] In an exemplary embodiment, a computer program product including instructions is also provided. When the computer program product is run on a computer, the computer is enabled to execute the code compiling method in the embodiment of the present disclosure.

[0156] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0157] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0158] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.< / dependencis>

Claims

1. A code compilation method, characterized in that: include: Obtaining a current source code dependency graph of multiple source code modules in the current project code and a first source code module, where the first source code module is any source code module having a corresponding target compiled file among the multiple source code modules; Replacing the first source code module in the current source code dependency graph with the target compiled file to obtain a first intermediate dependency graph; Based on the current source code dependency graph, constructing a virtual project object model (POM) dependency graph for the target compiled file in the first intermediate dependency graph to obtain a second intermediate dependency graph; the virtual POM dependency graph represents the dependency relationship between the target compiled file and the dependent compiled file having a dependency relationship with the target compiled file; Based on the dependency compilation file, modify the dependency relationship in the second intermediate dependency relationship graph to obtain a target dependency relationship graph; Compile the multiple source code modules based on the target dependency graph to obtain a code compilation file; The step of modifying the dependency relationship in the second intermediate dependency relationship graph based on the dependency compilation file to obtain the target dependency relationship graph includes: Determine a second source code module corresponding to the dependent compiled file; The dependent compiled file in the second intermediate dependency graph is replaced with the second source code module to obtain the target dependency graph.

2. The method according to claim 1, characterized in that: The step of modifying the dependency relationship in the second intermediate dependency relationship graph based on the dependency compilation file to obtain the target dependency relationship graph includes: Determine a second source code module corresponding to the dependent compiled file; If there is no compiled file matching the second source code module in the project code management system, replacing the dependent compiled file in the second intermediate dependency graph with the second source code module to obtain the target dependency graph; If there is a compiled file matching the second source code module in the project code management system, the second source code module in the second intermediate dependency graph is replaced with the dependent compiled file to obtain the target dependency graph.

3. The method according to claim 1, characterized in that The first source code module is obtained by the following steps, including: Based on the current source code dependency graph, obtaining a dependent source code module of each source code module; the dependent source code module is at least one of the multiple source code modules; Determine module identification information of each source code module based on each source code module and its dependent source code modules; Determine a target compiled file in a project code management system that matches the module identification information; The first source code module corresponding to the target compiled file is determined from the multiple source code modules.

4. The method according to claim 3, characterized in that: The step of determining module identification information of each source code module based on each source code module and the dependent source code modules of each source code module includes: Obtain summary information of each source code module and summary information of the dependent source code modules; The module identification information of each source code module is determined according to the summary information of each source code module and the summary information of the dependent source code modules having a dependency relationship with each source code module.

5. The method according to claim 3, characterized in that: Also includes: A code update event is detected, and a compiled file of a source code module to be released and a project object model POM file to be released are generated, wherein the source code module to be released is a source code module whose module identification information does not match the compiled file identification information among the multiple source code modules, and the compiled file identification information is the identification information of the compiled file in the project code management system; and the dependency relationship in the POM file to be released is an empty dependency relationship; The compiled file of the source code module to be released and the POM file to be released are released to the project code management system.

6. A code compiling device, characterized in that: include: An acquisition module is configured to execute acquisition of a current source code dependency graph of multiple source code modules in a current project code and a first source code module, wherein the first source code module is any source code module having a corresponding target compiled file among the multiple source code modules; A replacement module is configured to replace the first source code module in the current source code dependency graph with the target compiled file to obtain a first intermediate dependency graph; A virtual POM construction module is configured to execute, based on the current source code dependency graph, construct a virtual project object model POM dependency graph for the target compiled file in the first intermediate dependency graph to obtain a second intermediate dependency graph; the virtual POM dependency graph represents a dependency relationship between the target compiled file and a dependent compiled file having a dependency relationship with the target compiled file; A correction module is configured to perform correction processing on the dependency relationship in the second intermediate dependency relationship graph based on the dependency compilation file to obtain a target dependency relationship graph; A compiling module is configured to compile the plurality of source code modules based on the target dependency graph to obtain a code compilation file; Wherein, the correction module comprises: A first determining unit is configured to determine a second source code module corresponding to the dependent compiled file; A first correction unit is configured to perform correction processing on the dependency relationship in the second intermediate dependency relationship graph based on the second source code module to obtain the target dependency relationship graph; The first correction unit includes: a correction sub-unit configured to replace the dependent compiled file in the second intermediate dependency graph with the second source code module to obtain the target dependency graph.

7. The device according to claim 6, characterized in that The correction module comprises: A second determining unit is configured to determine a second source code module corresponding to the dependent compiled file; A second correction unit is configured to replace the dependent compiled file in the second intermediate dependency graph with the second source code module if there is no compiled file matching the second source code module in the project code management system, so as to obtain the target dependency graph; The third correction unit is configured to execute, if there is a compilation file matching the second source code module in the project code management system, replacing the second source code module in the second intermediate dependency graph with the dependent compilation file to obtain the target dependency graph.

8. The device according to claim 6, characterized in that The acquisition module comprises: A dependent source code module acquisition unit, based on the current source code dependency graph, acquires a dependent source code module of each source code module; the dependent source code module is at least one of the multiple source code modules; A module identification determination unit is configured to determine module identification information of each source code module based on each source code module and its dependent source code modules; A matching processing unit, configured to determine a target compiled file matching the module identification information in a project code management system; The first source code module obtaining unit is configured to determine the first source code module corresponding to the target compiled file from the multiple source code modules.

9. The device according to claim 8, characterized in that The module identification determination unit comprises: A summary acquisition subunit is configured to execute acquisition of summary information of each source code module and summary information of the dependent source code module; The identification information determining subunit is configured to determine the module identification information of each source code module according to the summary information of each source code module and the summary information of the dependent source code module having a dependency relationship with each source code module.

10. The device according to claim 8, characterized in that Also includes: A source code publishing module is configured to execute a code update event and generate a compiled file of a source code module to be published and a project object model POM file to be published, wherein the source code module to be published is a source code module whose module identification information does not match the compiled file identification information among the multiple source code modules, and the compiled file identification information is the identification information of the compiled file in the project code management system; and the dependency relationship in the POM file to be published is an empty dependency relationship; The upload module is configured to execute publishing of the compiled file of the source code module to be published and the POM file to be published to the project code management system.

11. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the code compiling method according to any one of claims 1 to 5.

12. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the code compiling method according to any one of claims 1 to 5.

13. A computer program product comprising computer instructions, characterized in that: When the computer instructions are executed by a processor, the code compiling method according to any one of claims 1 to 5 is implemented.

Citation Information

Cited By

  • Virtual assistant with conversion and analysis capabilities

    US12705036B2