Code compiling method and device, storage medium and electronic device
By generating target configuration files and modifying preset compilation templates, the problem of synchronizing code in different compilation environments when local code changes is solved, the separation of code and compilation software is achieved, and the compilation efficiency and accuracy are improved.
Patent Information
- Application Number
- CN202510161362.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-13
- Publication Date
- 2025-06-10
AI Technical Summary
When local code changes, it is necessary to synchronize the code in different compilation environments, and the existing technology has not yet proposed an effective solution.
By generating the target configuration file based on the path dependency information and the module name of the target code module, calling an automated script to modify the preset compilation template, and compiling it using the modified template in the compilation environment to generate the target link library.
It realizes the separation of code and compilation software, avoids the problem of synchronizing code in different compilation environments when code changes, and improves the compilation efficiency and accuracy of cross-platform code.
Smart Images

Figure CN120122952A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of smart home. Specifically, it relates to a method and device for compiling code, a storage medium, and an electronic device. Background Art
[0002] Generally, when compiling native code such as C language code on Android, the Android Studio tool (software for developing and debugging Android applications) is used, in cooperation with the compilation toolchain of the Native Development Kit (abbreviated as NDK), for compilation. The code must be imported into the Android Studio tool, and the tool generates relevant compilation configuration files for compilation.
[0003] That is to say, when cross-platform native code is compiled on Android using NDK, it needs to be imported into the Android Studio tool. When the code changes, the code needs to be synchronized between different compilation environments.
[0004] In view of the problem in the related art that code needs to be synchronized between different compilation environments when native code changes, no effective solution has been proposed yet. Summary of the Invention
[0005] Embodiments of the present application provide a method and device for compiling code, a storage medium, and an electronic device, so as to at least solve the problem in the related art that code needs to be synchronized between different compilation environments when native code changes.
[0006] According to an embodiment of the embodiments of the present application, a method for compiling code is provided, including: generating a target configuration file corresponding to a target code module according to path dependency information and the module name of the target code module, where the path dependency information includes: path dependency information corresponding to the target code module and path dependency information of a compilation environment; calling an automated script to enable the automated script to modify a preset compilation template according to the target configuration file; and compiling the target code module in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module.
[0007] In an exemplary embodiment, generating a target configuration file corresponding to the target code module according to path dependency information and the module name of the target code module includes: obtaining a compilation environment identifier in a preset configuration file, where the compilation environment identifier carries dynamic configuration information of a compilation output directory; updating a target path corresponding to the compilation output directory according to the path dependency information; and when it is determined through a first script that the updated target path matches the path dependency information successfully, writing the path dependency information and the module name into the preset configuration file to generate the target configuration file.
[0008] In an exemplary embodiment, after calling the automation script, the method further includes: determining, through the automation script, version information corresponding to the compilation environment, where the version information includes: a compiler corresponding to the target code module in the compilation environment, a linker, and a version number corresponding to the compilation environment; and determining a preset compilation template matching the version information in a preset compilation template library.
[0009] In an exemplary embodiment, calling an automation script to enable the automation script to modify a preset compilation template according to the target configuration file includes: determining environment variables in the preset compilation template based on the automation script; updating the environment variables according to path dependency information in the target configuration file, and writing the module name in the target configuration file into the preset compilation template to generate the modified preset compilation template.
[0010] In an exemplary embodiment, compiling the target code module in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module includes: when it is determined that the target code module includes a first code module, compiling the first code module in the compilation environment according to the preset compilation template to generate a first static link library corresponding to the target code module, and determining the first static link library as the target link library; when it is determined that the target code module includes a plurality of second code modules, compiling in a compilation environment corresponding to each second code module according to each modified preset compilation template corresponding to each second code module to generate each second static link library corresponding to each second code module; generating a dynamic link library according to the plurality of second static link libraries, and determining the dynamic link library as the target link library.
[0011] In an exemplary embodiment, generating a dynamic link library according to a plurality of second static link libraries includes: reading compilation information in each of the second static link libraries, where the compilation information includes: interface information corresponding to each of the second static link libraries; determining each interface corresponding to each of the second static link libraries according to the compilation information; invoking a second script and determining an association relationship between the plurality of second static link libraries according to the second script; and linking the plurality of second static link libraries into the dynamic link library according to each interface and the association relationship.
[0012] According to another embodiment of the embodiments of the present application, there is also provided a code compilation apparatus, including: a generation module, configured to generate a target configuration file corresponding to the target code module according to path dependency information and the module name of the target code module, where the path dependency information includes: path dependency information corresponding to the target code module and path dependency information of the compilation environment; a call module, configured to call an automation script to enable the automation script to modify a preset compilation template according to the target configuration file; and a compilation module, configured to compile the target code module in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module.
[0013] According to yet another aspect of the embodiments of the present application, there is also provided a computer-readable storage medium storing a computer program, where the computer program is configured to execute the above-mentioned code compilation method when running.
[0014] According to yet another aspect of the embodiments of the present application, there is also provided an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where the above-mentioned processor executes the above-mentioned code compilation method through the computer program.
[0015] According to yet another aspect of the embodiments of the present application, there is also provided a computer program product, including a computer program, where the above-mentioned computer program is executed by a processor to execute the above-mentioned method.
[0016] In the embodiments of the present application, a target configuration file corresponding to a target code module is generated according to the path dependency information corresponding to the target code module, the path dependency information of the compilation environment, and the module name of the target code module; an automation script is called to enable the automation script to modify a preset compilation template according to the automatic configuration file; the target code module is compiled in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module. That is to say, in the embodiments of the present application, a target configuration file is generated according to the path dependency information and the module name, and then the preset compilation template is modified according to the target configuration file to achieve the separation of the code and the compilation software. Furthermore, it is not necessary to configure the target code module through the compilation software, and the target code module can be compiled in the compilation environment. Through the embodiments of the present application, the problem of synchronizing code in different compilation environments when local code changes in the related art can be solved. Furthermore, when the code changes, it is not necessary to synchronize the code in different compilation environments. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present application and used together with the specification to explain the principles of the present application.
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0019] Figure 1 It is a schematic diagram of the hardware environment of a code compilation method according to an embodiment of the present application;
[0020] Figure 2 It is a flowchart of a code compilation method according to an embodiment of the present application;
[0021] Figure 3 It is a structural block diagram of a code compilation device according to an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0022] In order to enable those skilled in the art to better understand the solutions of the present application, the following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0023] It should be noted that the terms "first", "second", etc. in the description, claims and above-mentioned drawings of this application are used to distinguish similar objects, and do not necessarily describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of this application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units does not necessarily limit to those clearly listed steps or units, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0024] According to one aspect of the embodiments of the present application, a method for compiling code is provided. The method for compiling code is widely applied to whole-house intelligent digital control application scenarios such as Smart Home, smart home, intelligent home appliance ecosystem, Intelligence House ecosystem, etc. Optionally, Figure 1 is a schematic diagram of the hardware environment of a method for compiling code according to an embodiment of the present application. In this embodiment, the above method for compiling code can be applied to, for example, Figure 1 the hardware environment composed of a central control device 102 and a server 104 as shown. As Figure 1 shown, the server 104 is connected to the central control device 102 through a network, and can be used to provide services (such as application services, etc.) for the terminal or the client installed on the terminal. A database can be set on the server or independently of the server, which is used to provide data storage services for the server 104. Cloud computing and / or edge computing services can be configured on the server or independently of the server, which is used to provide data operation services for the server 104.
[0025] The above network may include, but is not limited to, at least one of the following: wired network, wireless network. The above wired network may include, but is not limited to, at least one of the following: wide area network, metropolitan area network, local area network. The above wireless network may include, but is not limited to, at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The central control device 102 is not limited to being a PC, mobile phone, tablet computer, smart air conditioner, smart range hood, smart refrigerator, smart oven, smart stove, smart washing machine, smart water heater, smart washing equipment, smart dishwasher, smart projection device, smart TV, smart drying rack, smart curtain, smart audio and video, smart socket, smart speaker, smart sound box, smart fresh air device, smart kitchen and bathroom equipment, smart bathroom equipment, smart floor sweeping robot, smart window cleaning robot, smart mopping robot, smart air purification device, smart steam box, smart microwave oven, smart kitchen water heater, smart purifier, smart water dispenser, smart door lock, etc.
[0026] In this embodiment, a method for compiling code is provided, which is applied to the above-mentioned central control device. Figure 2 It is a flowchart of the method for compiling code according to an embodiment of the present application. The process includes the following steps:
[0027] Step S202, generate a target configuration file corresponding to the target code module according to the path dependency information and the module name of the target code module, where the path dependency information includes: the path dependency information corresponding to the target code module and the path dependency information of the compilation environment;
[0028] Step S204, call an automated script to enable the automated script to modify a preset compilation template according to the target configuration file;
[0029] Step S206, compile the target code module in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module.
[0030] Through the above steps, generate a target configuration file corresponding to the target code module according to the path dependency information including the path dependency information corresponding to the target code module, the path dependency information of the compilation environment, and the module name of the target code module; call an automated script to enable the automated script to modify a preset compilation template according to the automatic configuration file; compile the target code module in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module. That is to say, the embodiment of the present application generates a target configuration file according to the path dependency information and the module name, and then modifies the preset compilation template according to the target configuration file to realize the separation of the code and the compilation software. Furthermore, it is not necessary to configure the target code module through the compilation software, and the target code module can be compiled in the compilation environment. Through the embodiment of the present application, the problem of synchronizing code in different compilation environments when local code changes in the related art can be solved. Furthermore, when the code changes, it is not necessary to synchronize the code in different compilation environments.
[0031] Optionally, the step S202 of generating a target configuration file corresponding to the target code module according to the path dependency information and the module name of the target code module includes: obtaining a compilation environment identifier in a preset configuration file, where the compilation environment identifier carries dynamic configuration information of a compilation output directory; updating a target path corresponding to the compilation output directory according to the path dependency information; when it is determined through a first script that the updated target path matches the path dependency information successfully, write the path dependency information and the module name into the preset configuration file to generate the target configuration file.
[0032] It can be understood that the target configuration file can be generated based on the path dependency information and the module name of the target code module. Specifically:
[0033] Obtain the compilation environment identifier in the preset configuration file: Use the YAML configuration file as the preset configuration file. Assume that the identifiers for different compilation environments are defined in it, such as: android, ios, windows, etc. Each identifier is associated with a specific compilation output directory.
[0034] Update the target path corresponding to the compilation output directory according to the path dependency information: When the automation script runs, the automation script will read the android compilation environment identifier in the YAML configuration file, as well as the path dependency information in the project, including the source code path, library path, toolchain path, etc.
[0035] Assume that the project structure or compilation requirements change. The automation script will adjust these output paths accordingly to ensure consistency with the current path dependency information.
[0036] Verify the matching of the updated target path and the path dependency information through the first script: The automation script (such as tools.py) will perform a series of checks to verify whether the updated target path exactly matches the path dependency information. This includes checking whether the paths of the source code directory, libraries, and resource files are correct, and confirming that there are no conflicts or errors in the updated output directory. Only after successful verification will the script continue to execute the next step.
[0037] Write the path dependency information and the module name into the preset configuration file: Once the verification is successful, the script will write the updated path dependency information and the target module name into the YAML configuration file. The YAML configuration file after writing the path dependency information and the target module name is the target configuration file. In this way, the YAML configuration file can dynamically record and update the compilation environment information to adapt to different compilation requirements.
[0038] Optionally, after calling the automation script in step S204, the method further includes: determining the version information corresponding to the compilation environment through the automation script, where the version information includes: the compiler, linker corresponding to the target code module in the compilation environment, and the version number corresponding to the compilation environment; determining the preset compilation template that matches the version information in the preset compilation template library.
[0039] It can be understood that before modifying the preset compilation template, it is also necessary to select the preset compilation template. Specifically:
[0040] Determine the version information corresponding to the compilation environment through an automated script: In the YAML configuration file, not only the compilation environment identifier (such as android) is defined, but also the specific information of the specific version of the compilation environment may be included. For example, for the Android compilation environment, we may need to specify the NDK version used, and at the same time determine the specific versions of the compiler (such as GCC or Clang) and the linker. The automated script (such as tools.py) can obtain the following version information by reading the YAML configuration file:
[0041] Compiler version: For example, GCC 7.3.0 or Clang 9.0.1;
[0042] Linker version: This usually matches the compiler version. For example, the ld.gold version changes with GCC or Clang;
[0043] Compilation environment version number: Such as NDK r21e or Android SDK 29.
[0044] Determine the preset compilation template that matches the version information in the preset compilation template library: The automated script will search for and match the applicable compilation template in the preset compilation template library according to the obtained version information. The preset compilation template library contains compilation templates for different versions of the compilation environment, compiler, and linker. Each template contains the key configuration parameters and commands required for compilation under a specific version. The preset compilation template can be: the android.mk template.
[0045] Optionally, calling the automated script in step S204 to enable the automated script to modify the preset compilation template according to the target configuration file includes: determining the environment variables in the preset compilation template based on the automated script; updating the environment variables according to the path dependency information in the target configuration file, and writing the module name in the target configuration file into the preset compilation template to generate the modified preset compilation template.
[0046] It can be understood that after determining the preset compilation template, it is also necessary to modify the preset compilation template. Specifically: use the version information in the YAML configuration file, such as NDK r21e, GCC 7.3.0, etc., to select the correct preset compilation template. In the selected template, the script will update the configuration in the template according to the path dependency information in the YAML configuration file, such as the include directory and the libs directory, to ensure that the correct path information is included in the compilation configuration file. Finally, the script will generate an android.mk file that can effectively guide the compilation process of the target code module according to the version information and path dependency.
[0047] For example: Suppose you are using a YAML configuration file to prepare for the compilation of the module `moduledemo`, and the configuration file specifies the use of the NDK r21e version and the GCC 7.3.0 compiler for compilation. The automation script will read this information and search for the corresponding compilation template in the preset compilation template library for NDK r21e and GCC 7.3.0. After finding the matching template, the script will update the configuration parameters in the template according to the path dependency information of the `moduledemo` module (such as the `include` and `libs` directories). Finally, the script generates or updates an `android.mk` file (i.e., the preset compilation template) containing the correct version information and path configuration to guide the compilation process of the `moduledemo` module in the Android environment.
[0048] In this way, the automation script ensures that the compilation environment, compiler, and linker versions used each time are the most suitable for the current project requirements, and also ensures that the path information included in the compilation configuration file is up-to-date, thereby improving the compilation efficiency and accuracy of cross-platform code.
[0049] Optionally, the step S206 of compiling the target code module in the compilation environment according to the modified preset compilation template to generate the target link library corresponding to the target code module includes: when it is determined that the target code module includes a first code module, compiling the first code module in the compilation environment according to the preset compilation template to generate a first static link library corresponding to the target code module, and determining the first static link library as the target link library; when it is determined that the target code module includes multiple second code modules, compiling each second code module in the compilation environment corresponding to each second code module according to each modified preset compilation template corresponding to each second code module to generate each second static link library corresponding to each second code module; generating a dynamic link library based on the multiple second static link libraries, and determining the dynamic link library as the target link library.
[0050] That is to say, the result generated after compiling the code module may include a static link library, may include a dynamic link library, or may include both a static link library and a dynamic link library. Specifically:
[0051] When it is determined that the target code module includes multiple third code modules, compiling each third code module in the compilation environment corresponding to each third code module according to each modified preset compilation template corresponding to each third code module to generate each third static link library corresponding to each third code module;
[0052] Determine multiple fourth static link libraries from the multiple third static link libraries according to the association relationships between the multiple third static link libraries and a preset linking requirement, and generate a second dynamic link library from the multiple fourth static link libraries according to the association relationships, where the preset linking requirement is used to indicate the third static link libraries that are allowed to be linked as dynamic link libraries;
[0053] Determine the second dynamic link library and other static link libraries as the target link libraries, where the other static link libraries are used to indicate the other static link libraries in the multiple third static link libraries except the multiple fourth static link libraries.
[0054] Optionally, generating a dynamic link library from multiple second static link libraries includes: reading the compilation information in each of the second static link libraries, where the compilation information includes: the interface information corresponding to each of the second static link libraries; determining each interface corresponding to each of the second static link libraries according to the compilation information; calling a second script, and determining the association relationships between the multiple second static link libraries according to the second script; and linking the multiple second static link libraries into the dynamic link library according to each interface and the association relationships.
[0055] It can be understood that the steps of linking static link libraries into a dynamic link library can be:
[0056] Read the compilation information in each second static link library: The automation script reads the compilation information in each second static link library (such as a library file in the.a format) generated during the compilation process. This information is mainly obtained through the metadata of the library file or an additional description file, and includes the interface information supported or implemented by the library file.
[0057] Determine the interfaces corresponding to each second static link library according to the compilation information: After the script reads the compilation information of each static link library, it parses this information to determine the interfaces corresponding to each library file. This may involve parsing the symbol table of the library file to identify the functions and variables available for linking. For example, for libandroidenv.a, the script will identify interfaces such as the AndroidEnvInit, AndroidEnvCleanup, and AndroidEnvFunction functions.
[0058] Call the second script to determine the association relationship between multiple second static link libraries: The automation script will call another script (such as android_build_out.sh), which is responsible for analyzing the dependency relationships between these static link libraries and determining their association relationships. This may involve analyzing the references between library files to identify which libraries need to be linked before others during the linking process to ensure the correct reference and resolution of functions and data. For example, libandroidenv.a may depend on some functions in the libbase.a library.
[0059] Link multiple second static link libraries into a dynamic link library according to each interface and association relationship: The automation script will use a linker (such as LD) to link these libraries into a dynamic link library (such as a library file in.so format) according to the interface information of each static link library and the determined association relationship. The linking process will ensure that all necessary interfaces are correctly resolved and the dependency relationships between libraries are correctly handled. For example, libandroidenv.a, libbase.a, and other libraries will be linked into OSDK.so, and this dynamic library will contain the functions of all these libraries and can be dynamically loaded and used by Android applications at runtime.
[0060] For example: Suppose there are three static link libraries: libandroidenv.a, libbase.a, and libutils.a, where libandroidenv.a depends on functions in libbase.a, and libutils.a is independent of other libraries. The automation script reads the compilation information of each library, identifies their interfaces, and analyzes the association relationships between the libraries through the android_build_out.sh script. Based on this information, the script will link and generate the OSDK.so dynamic library, where libbase.a will be linked first to provide the functions required by libandroidenv.a. As an independent library, libutils.a will be linked into OSDK.so after all dependency relationships are processed. The finally generated dynamic library will contain the functions of all three static libraries and can be called by Android applications at runtime.
[0061] To better understand the process of the above code compilation method, the following further describes the implementation method flow of the above code compilation in combination with optional embodiments, but it is not used to limit the technical solutions of the embodiments of the present application.
[0062] An optional embodiment of the present application provides a method for compiling Android code through an automated script. Specifically: The optional embodiment of the present application is independent of the Android Studio tool and can compile code with an automated script, only requiring necessary configurations. The same set of configurations can also be reused for compiling other similar compilation toolchains, such as the GNU Compiler Collection (GCC for short), ARM (a compiler), etc.
[0063] Among them, the Android NDK is a toolset that can implement various parts of an application in native code using languages such as C and C++. For specific types of applications, this can reuse code libraries written in these languages.
[0064] YAML is a data serialization format mainly used for storing and exchanging data between different systems and programming languages. Similar to JSON and XML, the file extension is.yaml or.yml.
[0065] When cross-platform native code is compiled on Android using the NDK, it needs to be imported into the Android Studio tool. When the code changes, the code needs to be synchronized between different compilation environments.
[0066] The optional embodiment of the present application configures relevant compilation information through YAML, automatically generates a configuration file with an automated script, and the external compilation framework can perform compilation through the YAML configuration, avoiding the problem that a set of code must be compiled using different compilation tools on different platforms. Specifically:
[0067] Set relevant information in YAML (the file generated after setting the relevant information is the target configuration file). The compilation framework uses the YAML configuration for compilation.
[0068] The key information includes: printing the information of the start compilation module name; setting various path dependencies (i.e., path dependency information), including the paths of third-party libraries, compilation paths, project paths, solution paths, etc.
[0069] According to the settings such as the module name and path dependencies, use the tools.py script (i.e., the automated script) to modify the android.mk template (i.e., the preset compilation template).
[0070] Use android_build.sh (i.e., the second script) to compile a single module (i.e., the code module) to generate a static library (i.e., a static link library).
[0071] Use android_build_out.sh (i.e., the second script) to link the static libraries of each module to generate a dynamic library (i.e., a dynamic link library).
[0072] By using the YAML configuration file and automation scripts in the alternative embodiments of this application, the compilation process of cross-platform Native code (such as C language code) in the Android environment becomes more efficient and flexible. There is no need to manually import the code into Android Studio, which greatly reduces the complexity and time consumption of code synchronization and configuration maintenance. A set of automation scripts and configurations can be reused for multiple compilation toolchains, such as GCC, ARM, etc., enabling developers to quickly switch and adjust when facing different compilation requirements, and improving the generality and reusability of the compilation process. The tools.py script in the alternative embodiments of this application can dynamically modify the android.mk template according to the module name and path dependency information to ensure that the dependency relationships of each module in the compilation environment are accurately managed, avoiding compilation failures caused by configuration errors. The automation script can read version information, including the version numbers of the compiler, linker, and compilation environment, so as to select a compilation template that matches the version information in the preset compilation template library, ensuring the consistency and compatibility of the compilation process. The android_build.sh and android_build_out.sh scripts can determine the association relationships between each static library according to the compilation information of each static library, and then flexibly link multiple static libraries into a dynamic library, providing more advanced modular compilation and linking capabilities. The introduction of the automation script reduces the time for manual configuration and error troubleshooting, enabling developers to focus on code logic and function implementation rather than cumbersome compilation configuration details, thus improving the overall development efficiency and code quality. During the compilation configuration and link library generation process, the automation script executes a series of verification and inspection steps, which can effectively reduce compilation and runtime errors caused by human errors or configuration mismatches, improving the stability and reliability of the code.
[0073] In summary, the solution for compiling Android code through automation scripts not only simplifies the cross-platform compilation process, improves the compilation efficiency, but also enhances the flexibility and accuracy of the compilation process, providing more efficient and reliable tool support for the development and maintenance of Android applications.
[0074] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases, the former is a better implementation method. Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc), including several instructions for causing a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.
[0075] Figure 3 It is a structural block diagram of a code compilation device according to an embodiment of the present application; as Figure 3 shown, it includes:
[0076] A generation module 32, configured to generate a target configuration file corresponding to the target code module according to path dependency information and the module name of the target code module, wherein the path dependency information includes: path dependency information corresponding to the target code module and path dependency information of the compilation environment;
[0077] An invocation module 34, configured to invoke an automation script, so that the automation script modifies a preset compilation template according to the target configuration file;
[0078] A compilation module 36, configured to compile the target code module in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module.
[0079] Through the above device, a target configuration file corresponding to the target code module is generated according to path dependency information including path dependency information corresponding to the target code module, path dependency information of the compilation environment, and the module name of the target code module; an automation script is invoked so that the automation script modifies a preset compilation template according to the automatic configuration file; the target code module is compiled in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module. That is to say, the embodiment of the present application generates a target configuration file according to path dependency information and a module name, and then modifies a preset compilation template according to the target configuration file to realize the separation of code and compilation software, and further, without configuring the target code module through a compilation software, the target code module can be compiled in the compilation environment. Through the embodiment of the present application, the problem of synchronizing code in different compilation environments when local code changes in the related art can be solved. Further, when the code changes, there is no need to synchronize the code in different compilation environments.
[0080] In an exemplary embodiment, the generation module 32 is further configured to obtain a compilation environment identifier in a preset configuration file, wherein the compilation environment identifier carries dynamic configuration information of a compilation output directory; update a target path corresponding to the compilation output directory according to the path dependency information; and in the case that it is determined through a first script that the updated target path matches the path dependency information successfully, write the path dependency information and the module name into the preset configuration file to generate the target configuration file.
[0081] In an exemplary embodiment, the calling module 34 is further configured to determine, through the automation script, version information corresponding to the compilation environment, where the version information includes: a compiler corresponding to the target code module in the compilation environment, a linker, and a version number corresponding to the compilation environment; and determine, in a preset compilation template library, the preset compilation template that matches the version information.
[0082] In an exemplary embodiment, the calling module 34 is further configured to determine, based on the automation script, environment variables in the preset compilation template; update the environment variables according to path dependency information in the target configuration file, and write a module name in the target configuration file into the preset compilation template to generate the modified preset compilation template.
[0083] In an exemplary embodiment, when it is determined that the target code module includes a first code module, the compilation module 36 is further configured to compile the first code module in the compilation environment according to the preset compilation template to generate a first static link library corresponding to the target code module, and determine the first static link library as the target link library; when it is determined that the target code module includes multiple second code modules, compile each second code module in a compilation environment corresponding to each second code module according to each modified preset compilation template corresponding to each second code module to generate each second static link library corresponding to each second code module; generate a dynamic link library according to the multiple second static link libraries, and determine the dynamic link library as the target link library.
[0084] In an exemplary embodiment, the compilation module 36 is further configured to read compilation information in each second static link library, where the compilation information includes: interface information corresponding to each second static link library; determine each interface corresponding to each second static link library according to the compilation information; call a second script, and determine an association relationship between the multiple second static link libraries according to the second script; and link the multiple second static link libraries into the dynamic link library according to each interface and the association relationship.
[0085] An embodiment of the present application further provides a storage medium, which includes a stored program, where the above program, when running, executes the method in any one of the above.
[0086] Optionally, in this embodiment, the above storage medium may be set to store program code for executing the following steps:
[0087] S1. Generate a target configuration file corresponding to the target code module according to the path dependency information and the module name of the target code module, where the path dependency information includes: the path dependency information corresponding to the target code module and the path dependency information of the compilation environment;
[0088] S2. Invoke an automation script to enable the automation script to modify a preset compilation template according to the target configuration file;
[0089] S3. Compile the target code module in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module.
[0090] An embodiment of the present application further provides an electronic device, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0091] Optionally, the above electronic device may further include a transmission device and an input / output device, where the transmission device is connected to the above processor, and the input / output device is connected to the above processor.
[0092] Optionally, in this embodiment, the above processor may be configured to execute the following steps through a computer program:
[0093] S1. Generate a target configuration file corresponding to the target code module according to the path dependency information and the module name of the target code module, where the path dependency information includes: the path dependency information corresponding to the target code module and the path dependency information of the compilation environment;
[0094] S2. Invoke an automation script to enable the automation script to modify a preset compilation template according to the target configuration file;
[0095] S3. Compile the target code module in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module.
[0096] An embodiment of the present application further provides a computer program product, including a computer program, and the computer program is executed by a processor to perform the steps in any one of the above method embodiments.
[0097] Optionally, in this embodiment, the above computer program product may be executed by a processor to perform the following steps:
[0098] S1. Generate a target configuration file corresponding to the target code module according to the path dependency information and the module name of the target code module, where the path dependency information includes: the path dependency information corresponding to the target code module and the path dependency information of the compilation environment;
[0099] S2, call an automation script to enable the automation script to modify a preset compilation template according to the target configuration file;
[0100] S3, compile the target code module in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module.
[0101] Optionally, in this embodiment, the above storage medium may include, but is not limited to: various media such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disc that can store program codes.
[0102] Optionally, specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation manners, and details are not described herein again.
[0103] Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the present application can be implemented by a general-purpose computing device. They can be concentrated on a single computing device or distributed on a network composed of multiple computing devices. Optionally, they can be implemented by program codes executable by the computing device. Thus, they can be stored in a storage device and executed by the computing device. And in some cases, the steps shown or described can be executed in a different order from here, or they can be separately fabricated into individual integrated circuit modules, or multiple modules or steps among them can be fabricated into a single integrated circuit module to implement. In this way, the present application is not limited to any specific combination of hardware and software.
[0104] The above is only the preferred embodiment of the present application. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present application, several improvements and refinements can still be made, and these improvements and refinements should also be regarded as the protection scope of the present application.
Claims
1. A code compiling method, characterized in that: include: Generate a target configuration file corresponding to the target code module according to the path dependency information and the module name of the target code module, wherein the path dependency information includes: the path dependency information corresponding to the target code module and the path dependency information of the compilation environment; Calling an automation script so that the automation script modifies a preset compilation template according to the target configuration file; The target code module is compiled in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module.
2. The code compiling method according to claim 1, characterized in that: Generate a target configuration file corresponding to the target code module according to the path dependency information and the module name of the target code module, including: Obtaining a compilation environment identifier in a preset configuration file, wherein the compilation environment identifier carries dynamic configuration information of a compilation output directory; Update the target path corresponding to the compilation output directory according to the path dependency information; When it is determined through the first script that the updated target path successfully matches the path dependency information, the path dependency information and the module name are written into the preset configuration file to generate the target configuration file.
3. The code compiling method according to claim 1, characterized in that: After calling the automation script, the method further includes: Determine the version information corresponding to the compilation environment through the automated script, wherein the version information includes: the compiler and linker corresponding to the target code module in the compilation environment and the version number corresponding to the compilation environment; The preset compiling template matching the version information is determined in a preset compiling template library.
4. The code compiling method according to claim 1, characterized in that: Calling an automation script so that the automation script modifies a preset compilation template according to the target configuration file includes: Determine the environment variables in the preset compilation template based on the automation script; The environment variable is updated according to the path dependency information in the target configuration file, and the module name in the target configuration file is written into the preset compilation template to generate the modified preset compilation template.
5. The code compiling method according to claim 1, characterized in that: Compiling the target code module in the compilation environment according to the modified preset compilation template to generate a target link library corresponding to the target code module, including: In the case where it is determined that the target code module includes a first code module, the first code module is compiled in the compilation environment according to the preset compilation template to generate a first static link library corresponding to the target code module, and the first static link library is determined as the target link library; in the case where it is determined that the target code module includes a plurality of second code modules, each modified preset compilation template corresponding to each second code module is compiled in the compilation environment corresponding to each second code module to generate each second static link library corresponding to each second code module; A dynamic link library is generated according to the plurality of second static link libraries, and the dynamic link library is determined as the target link library.
6. The code compiling method according to claim 5, characterized in that: Generating a dynamic link library according to the plurality of second static link libraries comprises: Reading compilation information in each second static link library, wherein the compilation information includes: interface information corresponding to each second static link library; Determine each interface corresponding to each second static link library according to the compilation information; Calling a second script, and determining the association relationship between the plurality of second static link libraries according to the second script; The plurality of second static link libraries are linked into the dynamic link library according to each interface and the association relationship.
7. A code compiling device, characterized in that: include: A generation module, used to generate a target configuration file corresponding to the target code module according to the path dependency information and the module name of the target code module, wherein the path dependency information includes: the path dependency information corresponding to the target code module and the path dependency information of the compilation environment; A calling module, used for calling an automation script so that the automation script modifies a preset compilation template according to the target configuration file; The compiling module is used to compile the target code module in the compiling environment according to the modified preset compiling template to generate a target link library corresponding to the target code module.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 6 when executed.
9. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 6 through the computer program.
10. A computer program product, comprising a computer program, characterized in that The computer program is used by a processor to execute the steps of the method described in any one of claims 1 to 6.