Code compiling method and device, computer equipment, storage medium and program product
By obtaining the compilation configuration file and empty implementation switch information of the code project, obtaining the source code files and empty implementation code files, and compiling functions on demand, the problem of high consumption of operation and maintenance resources in the existing technology is solved, and functional independence is achieved. Management and flexibility.
Patent Information
- Application Number
- CN202411030492.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-09-27
AI Technical Summary
When the existing code compilation method implements conditional compilation through macro definition, it leads to a large consumption of operation and maintenance resources, because the macro definition is mixed with the function code in the source code file, making it difficult to independently manage and tailor it.
By obtaining the compilation configuration file of the code project, determine the empty implementation switch information of the function, obtain the corresponding source code file and empty implementation code file, compile it to generate the library file, realize on-demand compilation of functions, and reduce the compilation of unnecessary functions.
It realizes on-demand compilation of functions, reduces the consumption of operation and maintenance resources, avoids the impact of macro definitions in source code files, and improves the independence and flexibility of code logic.
Smart Images

Figure CN118708189A
Abstract
Description
Technical Field
[0001] The present application relates to the field of compilation technology, and in particular to a code compilation method, apparatus, computer equipment, storage medium and program product. Background Art
[0002] The code engineering of an application can store source code files that implement various functions in the application. After being compiled, the source code files can generate machine language code files that can be recognized by the computer, such as library files or executable files. With the update and iteration of the business, there is a need to develop new applications. If the new application needs to reuse some functions in the existing code engineering, it is necessary to extract the library files used to implement some functions from the existing code engineering. Since the code engineering does not support function tailoring, usually, conditional compilation is implemented through macro definitions in the source code files of the existing code engineering. That is, macro definitions are used to control the compilation of some source code files in the existing code engineering, and not to compile other source code files, so as to output the library files of some functions required by the new application.
[0003] However, the method of implementing conditional compilation through macro definition, because the macro definition processes the source code file, the code of the macro definition part and the code that implements the function in the source code file are mixed, resulting in the consumption of more operation and maintenance resources. Summary of the invention
[0004] Based on this, it is necessary to provide a code compilation method, device, computer equipment, storage medium and program product that can reduce the consumption of operation and maintenance resources in response to the above technical problems.
[0005] In a first aspect, the present application provides a code compilation method, comprising:
[0006] Obtaining a compilation configuration file of the code project, and determining, based on the compilation configuration file, respective empty implementation switch information of a plurality of functions that can be implemented by the code project;
[0007] Based on the empty implementation switch information, determining a first type of function that is closed by empty implementation and a second type of function that is opened by empty implementation among the multiple functions;
[0008] Obtain source code files of the first category of functions;
[0009] Obtaining an empty implementation code file of the second-category function, wherein the empty implementation code file includes a portion of code in the source code file of the second-category function, wherein the portion of code is code required for compiling without implementing the second-category function;
[0010] Compile based on the source code file of the first category of functions and the empty implementation code file of the second category of functions, and output a library file for loading into a program to implement the first category of functions.
[0011] In a second aspect, the present application also provides a code compilation device, including:
[0012] An acquisition module is used to acquire a compilation configuration file of a code project, and determine the empty implementation switch information of each of a plurality of functions that can be realized by the code project based on the compilation configuration file; determine, based on the empty implementation switch information, a first type of function whose empty implementation is turned off and a second type of function whose empty implementation is turned on among the plurality of functions; acquire a source code file of the first type of function; acquire an empty implementation code file of the second type of function, the empty implementation code file including part of the code in the source code file of the second type of function, the part of the code being the code required for compilation without realizing the second type of function;
[0013] A compiling module is used to compile based on the source code file of the first category of functions and the empty implementation code file of the second category of functions, and output a library file for loading into a program to implement the first category of functions.
[0014] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0015] Obtaining a compilation configuration file of the code project, and determining, based on the compilation configuration file, respective empty implementation switch information of a plurality of functions that can be implemented by the code project;
[0016] Based on the empty implementation switch information, determining a first type of function that is closed by empty implementation and a second type of function that is opened by empty implementation among the multiple functions;
[0017] Obtain source code files of the first category of functions;
[0018] Obtaining an empty implementation code file of the second-category function, wherein the empty implementation code file includes a portion of code in the source code file of the second-category function, wherein the portion of code is code required for compiling without implementing the second-category function;
[0019] Compile based on the source code file of the first category of functions and the empty implementation code file of the second category of functions, and output a library file for loading into a program to implement the first category of functions.
[0020] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0021] Obtaining a compilation configuration file of the code project, and determining, based on the compilation configuration file, respective empty implementation switch information of a plurality of functions that can be implemented by the code project;
[0022] Based on the empty implementation switch information, determining a first type of function that is closed by empty implementation and a second type of function that is opened by empty implementation among the multiple functions;
[0023] Obtain source code files of the first category of functions;
[0024] Obtaining an empty implementation code file of the second-category function, wherein the empty implementation code file includes a portion of code in the source code file of the second-category function, wherein the portion of code is code required for compiling without implementing the second-category function;
[0025] Compile based on the source code file of the first category of functions and the empty implementation code file of the second category of functions, and output a library file for loading into a program to implement the first category of functions.
[0026] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0027] Obtaining a compilation configuration file of the code project, and determining, based on the compilation configuration file, respective empty implementation switch information of a plurality of functions that can be implemented by the code project;
[0028] Based on the empty implementation switch information, determining a first type of function that is closed by empty implementation and a second type of function that is opened by empty implementation among the multiple functions;
[0029] Obtain source code files of the first category of functions;
[0030] Obtaining an empty implementation code file of the second-category function, wherein the empty implementation code file includes a portion of code in the source code file of the second-category function, wherein the portion of code is code required for compiling without implementing the second-category function;
[0031] Compile based on the source code file of the first category of functions and the empty implementation code file of the second category of functions, and output a library file for loading into a program to implement the first category of functions.
[0032] The above-mentioned code compilation method, device, computer equipment, storage medium and program product obtain the source code file of the first category of functions with empty implementation turned off, and obtain the empty implementation code file of the second category of functions with empty implementation turned on. Since the empty implementation code file is to compile the required code without realizing the second category of functions, the compilation is based on the source code file of the first category of functions and the empty implementation code file of the second category of functions, and the compilation can be passed, and the output library file can be loaded into the program to only realize the first category of functions, so as to achieve the purpose of realizing the required functions and not realizing the unnecessary functions; moreover, the empty implementation is turned on and the empty implementation is turned off based on the empty implementation switch information, and the empty implementation switch information is determined based on the compilation configuration file. The empty implementation switch information exists separately from the source code file in the code project. Compared with the traditional method of macro definition in the source code file in the code project, it does not affect the code logic of the source code file itself, and reduces the consumption of operation and maintenance resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0034] FIG1 is a schematic diagram of a flow chart of a code compiling method in one embodiment;
[0035] FIG2 is a schematic diagram of an on-demand compilation process in one embodiment;
[0036] FIG3 is a structural block diagram of a code compiling device in one embodiment;
[0037] FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0039] In one embodiment, as shown in FIG1 , a code compilation method is provided. This embodiment uses the method applied to a computer device as an example. It is understandable that the computer device can be a terminal or a server. The method can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. Among them, the terminal can be a personal computer, a laptop, a smart phone, or a tablet computer. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services. In this embodiment, the method includes the following steps:
[0040] Step 102 : obtaining a compilation configuration file of the code project, and determining, based on the compilation configuration file, the empty implementation switch information of each of a plurality of functions that can be implemented by the code project.
[0041] Among them, the code project is used to store various code files that implement the application. Various code files may include header files, source code files of multiple functions or other files. In some scenarios, the code project may also be called a code project. The source code file may be a code file written in a high-level programming language. The high-level programming language may be C language, C++ language, Java language or other. For example, the source code file may be written in C++ language, then the source code file may be a file with the suffix ".cpp", and the code project may be called a C++ project.
[0042] A code project may include multiple levels of file directories, for example, a source code file directory, which may include common support source code files that support multiple functions, and source code file subdirectories for multiple functions. In each source code file subdirectory, the source code file of the function may be stored, and the source code file of the function may include the class involved in the function and the class variables and functions. Classes are the basis for information encapsulation in object-oriented programming. Class variables may also be called member variables, and class functions may also be called member functions.
[0043] For example, a code project may be a code project of an image processing application (such as Meitu XiuXiu), which may include multiple functions such as eye beautification, skin beautification, lip beautification, and nose beautification. The name of the source code file directory may be src, and corresponding to the eye beautification, skin beautification, lip beautification, and nose beautification functions, the names of the source code file subdirectories included in the source code file directory may be "eye", "skin", "lip", and "nose", respectively; the class included in the source code file subdirectory eye may be BeautyEye, in which "int EyeCount; voiddoEyeBeauty(); void setEyeResPath()" may be defined, which respectively represent the member variable "EyeCount" of integer int, the untyped member function "doEyeBeauty" and the untyped member function "setEyeResPath"; the class included in the source code file subdirectory "skin" may be "BeautySkin", in which "bool isBlack; voiddoSkinWhite(); void setSkinResPath()", which respectively represent the Boolean member variable "isBlack", the untyped member function "doSkinWhite" and the untyped member function "setSkinResPath"; the class included in the source code file subdirectory "lip" may be "BeautyLip", in which "string lipColor; voidcolorLip(); void setLipResPath()" may be defined, which respectively represent the member variable of string type, the untyped member function "colorLip", and the untyped member function "setLipResPath"; the class included in the source code file subdirectory "nose" may be "BeautyNose", in which "float[] position; voidsetNoseResPath()" may be defined, which respectively represent the floating-point member variable "position" and the untyped member function "setNoseResPath".
[0044] A compilation configuration file is a configuration file that indicates how to compile. The compilation configuration file may be generated by a compilation tool, such as CMake (a cross-platform compilation tool), Xcode (an integrated development environment provided by Apple), or VS Code (Visual Studio Code, an open source code editor provided by Microsoft). The compilation configuration file may include empty implementation switch information for each of the multiple functions set according to the compilation target. The compilation target may be a function that needs to be implemented and a function that does not need to be implemented among the multiple functions. It can be understood that in the compilation configuration file, for the functions that need to be implemented, the empty implementation switch information may be set to indicate that the empty implementation is turned off, and for the functions that do not need to be implemented, the empty implementation switch information may be set to indicate that the empty implementation is turned on.
[0045] The empty implementation switch information of each of the multiple functions may be the switch value information set for the empty implementation variables corresponding to each of the multiple functions. The empty implementation variables are variables related to the empty implementation defined for the functions in the compilation configuration file. For example, the compilation configuration file may be generated by CMake, and the empty implementation variables corresponding to the eye beauty function, lip beauty function, nose beauty function, hair beauty function, and skin beauty function may be "Empty_Eye", "Empty_Lip", "Empty_Nose", "Empty_Hair", and "Empty_Skin", respectively. If the function to be implemented is the skin beautification function, and the functions that do not need to be implemented are the eye beautification function, lip beautification function, nose beautification function, and hair beautification function, then the empty implementation switch information of the skin beautification function can be "set(Empty_SkinOFF)", indicating that the empty implementation is turned off and the normal and complete skin beautification function is enabled. The empty implementation switch information of the eye beautification function, lip beautification function, nose beautification function, and hair beautification function can be "set(Empty_Eye ON)", "set(Empty_Lip ON)", "set(Empty_Nose ON)", and "set(Empty_Hair ON)", respectively, all indicating that the empty implementation is enabled. Among them, "set" is a command in CMake to set a variable to a given value, such as "ON" or "OFF".
[0046] In one embodiment, the computer device can obtain the compilation configuration file of the code project in response to the trigger event of compiling the code project, and parse the compilation configuration file to determine the empty implementation switch information of each of the multiple functions that can be implemented by the code project. The trigger event can be an automatic trigger event, such as a timed trigger when a timed compilation task is configured for the code project; the trigger event can also be a manual trigger operation, such as a trigger operation on the compilation trigger control displayed in the development tool of the code project.
[0047] In one embodiment, a computer device may determine the function identifier of each of the multiple functions, and based on the function identifier of each of the multiple functions, determine the empty implementation switch information of each of the multiple functions in the compiled configuration file. Among them, the function identifier may be a function number, a function name or other. The function identifier may specifically be the name of the source code file subdirectory corresponding to the function. The empty implementation switch information may include an empty implementation variable, and the function identifier may be matched with the name of the empty implementation variable to determine the empty implementation switch information of each of the multiple functions. For example, for the beautiful eye function, the function identifier is "eye", and the matching empty implementation variable name is "Empty_Eye", then the empty implementation switch information containing "Empty_Eye" is determined as the empty implementation switch information of the beautiful eye function.
[0048] Step 104 , based on the empty implementation switch information, determining the first type of functions that are closed by the empty implementation and the second type of functions that are opened by the empty implementation among the multiple functions.
[0049] Among them, empty implementation can mean that the implementation logic of the function is empty. The first type of function is a type of function whose empty implementation is turned off among multiple functions, that is, a normal complete function. The second type of function is a type of function whose empty implementation is turned on among multiple functions. It can be understood that the first type of function is a function that needs to be implemented, and the implementation logic of the first type of function needs to be compiled during compilation, that is, the implementation logic of the first type of function is not empty during compilation, and the empty implementation is turned off; the second type of function is a function that does not need to be implemented, and the implementation logic of this type of function does not need to be compiled during compilation, that is, the implementation logic of the second type of function is empty during compilation, and the empty implementation is turned on.
[0050] In one embodiment, the computer device may parse the empty implementation switch information of each of the multiple functions to obtain a switch identifier corresponding to the function; if the switch identifier is a first preset identifier, the function is determined to be a first type of function that is empty-implemented and turned off. The switch identifier is an identifier used to determine whether the empty implementation is turned off or turned on. The first preset identifier may be "OFF".
[0051] In one embodiment, if the switch identifier is a second preset identifier, the computer device may determine that the function is empty and implement the second type of function to be turned on. The second preset identifier is different from the first preset identifier, and the second preset identifier may be "ON".
[0052] Step 106, obtaining source code files of the first type of functions.
[0053] Among them, the source code file of the function is used to implement the function after compilation.
[0054] In one embodiment, the computer device may obtain a source code file path of the first category function, and obtain the source code file of the first category function from the source code file path.
[0055] In one embodiment, the computer device may assign a first path value representing a source code file directory to the path variable, and generate a source code file path for the first type of function based on the first path value and a relative path value preconfigured for the first type of function.
[0056] Among them, the path variable is a variable used to assign a value to specify the code file directory to generate the code file path. The code file directory under the code project can include a source code file directory, such as "src", and can also include an empty implementation code file directory, such as "emptySrc". The empty implementation code file directory can include an empty implementation code file subdirectory. For the same function, the source code file subdirectory and the empty implementation code file subdirectory can have the same name, so that the same relative path value can be formed.
[0057] The path variable can take the first path value representing the source code file directory, and the first path value can be "src". If the first type of function is subsequently configured as a second type of function, the path variable can also take the second path value representing the empty implementation code file directory, and the second path value can be "emptySrc". The relative path value is the directory one level below the code file directory. For example, for the beautiful eye function, the relative path value can be "eye / *.cpp", representing all code files under the file directory "eye". The first path value is spliced with the relative path value of the function to generate a source code file path. For example, the source code file path can be "src / eye / *.cpp", representing the source code file in the source code file subdirectory "eye" under the source code file directory "src". It can be understood that the second path value is spliced with the relative path value of the function to generate an empty implementation file code path. For example, the empty implementation code file path can be "emptySrc / eye / *.cpp", representing the empty implementation code file in the empty implementation code file subdirectory "eye" under the empty implementation code file directory "emptySrc".
[0058] Step 108, obtaining an empty implementation code file of the second type of function, wherein the empty implementation code file includes part of the code in the source code file of the second type of function, and the part of the code is the code required for compiling without implementing the second type of function.
[0059] Among them, the code required for compilation is the code required to compile. Each of the multiple functions may correspond to an empty implementation code file. The empty implementation code file of each function may specifically include an empty implementation function of the function called by other source code files, necessary header file identifiers, and the part required to be implemented by the grammatical rules of the programming language type corresponding to the code project. Other source code files are source code files other than the source code file of the function in the code project. An empty implementation function means that the implementation logic of the function is empty, and specifically, the function logic code in the function body is empty.
[0060] In one embodiment, the computer device may obtain an empty implementation code file path of the second type of function, and obtain an empty implementation code file of the second type of function from the empty implementation code file path.
[0061] In one embodiment, the computer device may assign a second path value representing a source code file directory to the path variable, and generate an empty implementation code file path for the second type of function based on the second path value and a relative path value preconfigured for the second type of function.
[0062] In one embodiment, the computer device can obtain the code file path corresponding to each of the multiple functions that can be implemented by the code engineering based on the pre-configured compilation control code for the function. It can be understood that each of the multiple functions that can be implemented by the code engineering can correspond to a source code file and an empty implementation code file; for each function, by configuring the empty implementation switch information, the targeted function can be determined as a first-class function or a second-class function in each compilation, and then combined with the compilation control code, it can be determined whether the code file to be compiled for the targeted function in this compilation is a source code file or an empty implementation code file. Taking the beautiful eyes function as an example, the compilation control code is shown in the following code example:
[0063] set(_path PATH_SRC) / / Assign the path variable "_path" to "PATH_SRC"
[0064] if(Empty_Eye) {
[0065] _path = PATH_EMPTY_SRC / / If the empty implementation is enabled (this function is the second type of function), assign the path variable "_path" to "PATH_EMPTY_SRC"
[0066] }
[0067] set(All_CPPs ${All_CPPs}
[0068] _path / eye / *.cpp / / Concatenate the assignment result of the path variable with the relative path value "eye / *.cpp"
[0069] }
[0070] Among them, "PATH_SRC" can represent the source code file directory "src", and "PATH_EMPTY_SRC" can represent the empty implementation code file directory "emptySrc"; in the above compilation control code, the path variable is assigned to "PATH_SRC" by default. If the empty implementation is turned off, that is, if the beautiful eye function is a first-class function, "PATH_SRC" can be concatenated with the relative path value "eye / *.cpp", and the resulting code file path is the source code file path of the beautiful eye function, thereby obtaining the source code file for compilation; if the empty implementation is turned on, that is, if the beautiful eye function is a second-class function, "PATH_EMPTY_SRC" can be concatenated with the relative path value "eye / *.cpp", and the resulting code file path is the empty implementation code file path of the beautiful eye function, thereby obtaining the empty implementation code file for compilation.
[0071] Step 110 , compile based on the source code file of the first type of function and the empty implementation code file of the second type of function, and output a library file for loading into the program to implement the first type of function.
[0072] Among them, the library file is a compiled binary code file. The library file is loaded into the program to implement only the first type of functions but not the second type of functions, which can achieve on-demand compilation. The library file can be a static library file, which can be linked to the executable file of the program before the program is executed so as to be loaded into the program. The library file can also be a dynamic library file, which can be dynamically loaded during the execution of the program.
[0073] In one embodiment, the computer device may compile the source code files of the first type of functions and the empty implementation code files of the second type of functions, and output a library file for loading into a program to implement the first type of functions.
[0074] In one embodiment, the code project includes a common support source code file shared by multiple functions. In this embodiment, the computer device can obtain the common support source code file, compile the common support source code file, the source code file of the first category of functions, and the empty implementation code file of the second category of functions, and output a library file for loading into the program to implement the first category of functions. Among them, the common support source code file is a file different from the source code files or empty implementation code files of the respective functions of the multiple functions, and is used as a common support file for multiple functions. The common support source code file is such as the project entry file "Start.cpp", which may include the initial startup class "Start".
[0075] In the above code compilation method, the source code file of the first type of function with the empty implementation turned off is obtained, and the empty implementation code file of the second type of function with the empty implementation turned on is obtained. Since the empty implementation code file compiles the required code without realizing the second type of function, the compilation is performed based on the source code file of the first type of function and the empty implementation code file of the second type of function, and the compilation can be passed, and the output library file can be loaded into the program to only realize the first type of function, so as to achieve the purpose of realizing the required functions and not realizing the unnecessary functions; moreover, the empty implementation is turned on and the empty implementation is turned off based on the empty implementation switch information, and the empty implementation switch information is determined based on the compilation configuration file. The empty implementation switch information exists separately from the source code file in the code project. Compared with the traditional method of macro definition in the source code file in the code project, it does not affect the code logic of the source code file itself, and reduces the consumption of operation and maintenance resources.
[0076] In one embodiment, before step 102, the above-mentioned code compilation method also includes the step of generating an empty implementation code file for a function among multiple functions, and the step includes: for a function among multiple functions, in the source code file of the function, determining a first function called by other source code files; eliminating the function logic code in the function body of the first function; determining an empty implementation function based on the remaining part of the first function after elimination; and generating an empty implementation code file of the function according to the empty implementation function.
[0077] Among them, for a function among multiple functions, it may refer to a function among multiple functions for which an empty implementation code file needs to be generated. The function for which an empty implementation code file needs to be generated may be each function among multiple functions, or may be one of some functions among multiple functions. This part of functions may be functions determined by developers according to business needs, for example, specifically the second type of functions.
[0078] If an empty implementation code file is generated for each function, and then the empty implementation switch information of the function is configured through the compilation configuration file, so as to determine the source code file of the compiled function or the empty implementation code file of the compiled function, this method can decouple the process of generating the empty implementation code file of the function from the process of configuring the empty implementation switch information, thereby improving the flexibility of operation and maintenance. If an empty implementation code file is generated only for the functions that are not currently required to be implemented among multiple functions, that is, only for the second type of functions, the workload of generating empty implementation code files can be reduced while achieving the goal of on-demand compilation, and the consumption of operation and maintenance resources can be reduced.
[0079] If an empty implementation code file is generated for each function, the other source code files are source code files other than the source code files of the functions targeted in the code project, and may specifically include public support source code files and source code files of other functions, and the other functions are functions other than the functions targeted in the multiple functions. If an empty implementation code file is generated only for the second type of functions, the other source code files may be necessary source code files in the code project, and the necessary source code files may specifically include source code files of the first type of functions, and may also include public support source code files.
[0080] The first function is a function in the source code file of the targeted function that is called by other source code files. That is to say, the first function is the coupling part of the source code file of the targeted function and other source code files. For example, in the common support source code file "Start.cpp", it is necessary to call the initialization function "initXXX()" of multiple functions, the resource configuration function "setXXXResPath()" of multiple functions and other functions, for example, the initialization function "initEye()" of the beauty eye function, and the resource configuration function "setEyeResPath()" of the beauty eye function. When generating an empty implementation code file of the beauty eye function, the first function called may include the initialization function "initEye()" of the beauty eye function and the resource configuration function "setEyeResPath()" of the beauty eye function. For functions that are not called in the source code file of the function, they may not participate in the generation of an empty implementation code file. For example, the "doEyeBeauty()" function of the beauty eye function is not called by other source code files, so when generating an empty implementation code file of the beauty eye function, the "doEyeBeauty()" function may be ignored.
[0081] The function body of the first function is a whole composed of all codes of the function function of the first function. The first function may also include a function header, which may include the function name of the first function, the return type of the first function, and the formal parameter list of the first function. The function body may be a code block after the function header, specifically, a code block from the function body start identifier to the function body end identifier after the function header. The function body start identifier may be the first "{" after the function header, and the function body end identifier may be the "}" corresponding to the function body start identifier.
[0082] Function logic code is logic code that implements the function function. The remaining part of the first function may include the function header of the first function and the remaining part of the function body of the first function after the function logic code is removed. The empty implementation function is a function composed of the required code compiled without implementing the function function of the first function. The remaining part of the first function after the removal can be determined as an empty implementation function, that is, the empty implementation function may include the function header of the first function and the remaining part of the function body of the first function after the function logic code is removed. If the return type of the first function is void, the function logic code may include the code between the function body start identifier and the function body end identifier, that is, the empty implementation function may include the function header, the function body start identifier and the function body end identifier of the first function.
[0083] The empty implementation code file may include an empty implementation function of the first function, and may also include other codes required to generate the code file. For example, the other codes may include header file identifiers, which may be part or all of the header file identifiers introduced in the source code file, and some header file identifiers may include header file identifiers required for compilation after removing the function logic code.
[0084] In the traditional method, in order to realize the on-demand compilation of partial functions to obtain a library file that only realizes partial functions, in addition to the method of conditional compilation through macro definition, the code project is also split into sub-projects corresponding to different functions, so that the different sub-projects can be compiled to obtain a library file that only realizes partial functions. However, splitting the code project into sub-projects corresponding to different functions has high requirements for the design and development of the code project, and the source code files of each function need to be specially designed to realize the decoupling between the source code files of each function, which consumes a lot of operation and maintenance resources. In this embodiment, the source code files of different functions can be coupled, and for the coupled functions, an empty implementation function corresponding to the function is generated, thereby generating an empty implementation code file, which can realize the decoupling between different functions without changing the source code files of the functions themselves, thereby reducing the consumption of operation and maintenance resources.
[0085] In this embodiment, the first function of the targeted function is a function called by other source code files, that is, the first function is the coupling part between the source code file of the targeted function and other source code files. For the coupling part, an empty implementation function is additionally generated, and an empty implementation code file of the function is generated based on the empty implementation function. When the function does not need to be implemented, the function does not need to be implemented. Therefore, without changing the implementation logic of the source code file itself, the functions that need to be implemented and the functions that do not need to be implemented can be decoupled, thereby reducing the consumption of operation and maintenance resources.
[0086] In one embodiment, the step of generating an empty implementation code file of a function based on an empty implementation function includes: determining multiple header file identifiers introduced in the source code file of the function; determining a target header file identifier that matches a preconfigured necessary header file type from the multiple header file identifiers; and generating an empty implementation code file of the function based on the target header file identifier and the empty implementation function.
[0087] Among them, header files are files in a code project that are different from source code files and are used to declare entities such as functions and variables. The extension of a header file can be ".h" or ".hpp". The header file identifier can be the name of the header file. In a source code file, a header file identifier can be introduced based on a header file command, so that when compiling a source code file, the header file corresponding to the introduced header file identifier is loaded for compilation. A header file command such as "#include< >" and a header file identifier such as "string.h" can be introduced in the source code file through the statement "#include< string.h>".
[0088] In the source code file of the function, various header file identifiers are introduced due to the large amount of code. However, in the empty implementation code file of the function, some functions do not need to exist, and the function logic code of the empty implementation function does not need to be implemented. Some header file identifiers in the source code file can be omitted. Only the header files required for the functions and variables in the empty implementation code file need to be introduced to allow the compilation to pass.
[0089] The necessary header file type is the type of header file required for the functions and variables present in the empty implementation code file. The necessary header file type may include function-related header file types and basic library header file types. Among them, the function-related header file type may be a type in which the header file name matches the file name of the source code file of the function. For example, for the beauty eye function, the file name of the source code file may be "BeautyEye.cpp". If the introduced header file includes "BeautyEye.h", it can be determined that "BeautyEye.h" belongs to the function-related header file type, and "BeautyEye.h" is determined as the target file identifier. The basic library header file type may be a basic library header file type of a programming language such as C language or C++ language. For example, the string type header file "string.h" may belong to the basic library header file.
[0090] The header file identifiers other than the target header file identifier among multiple header file identifiers may not participate in the generation of the empty implementation code file, such as the file operation flow "iostrem.h", "filesystem.h", etc. Since the empty implementation function does not include specific function logic code, the header file of the file operation flow may not be introduced.
[0091] In this embodiment, the target header file identifier is introduced into the empty implementation code file, that is, only the necessary header file identifiers are introduced, which can streamline the header file identifiers and reduce the amount of code in the empty implementation file. In addition, the number of header files loaded during compilation can be reduced, which can reduce the compilation time.
[0092] In one embodiment, the return type of the first function indicates that the first function has a return value, and the remaining part of the first function after being removed includes the code in the function body for outputting a return value matching the return type.
[0093] The return type is used to determine whether the function has a return value, and the data type of the return value if there is a return value. For example, the return type can be void, indicating that the function has no return value. The return type can also be int, long, char, etc., indicating that the function has a return value, and the data types of the return value are integer, long integer, and string type respectively. The code for outputting the return value that matches the return type can include a return statement formed based on a return identifier, and the return identifier can be "return", and the return statement can be "return 0".
[0094] If the return statement includes a return identifier and a return value that matches the return type, the code for outputting the return value that matches the return type may only include the return statement; if the return statement includes a return identifier and a variable, the code for outputting the return value that matches the return type may include the return statement in the function body and the statement in the function body that assigns the variable a value. It can be understood that the remaining part of the first function after elimination may include the function header of the first function, the function body start identifier, the code for outputting the return value that matches the return type, and the function body end identifier.
[0095] In this embodiment, the remaining part of the first function after elimination includes code for outputting a return value that matches the return type, so that the empty implementation function can include code for outputting a return value that matches the return type, so that when compiling the empty implementation code generated based on the empty implementation function, compilation failure due to an incorrect return value can be avoided.
[0096] In one embodiment, the step of generating an empty implementation code file for a function among multiple functions also includes: determining a programming language corresponding to the code project; determining, based on the grammatical rules of the programming language, a target function type necessary when compiling the code of the programming language; for a function among multiple functions, when the source code file of the function includes a second function that matches the target function type, generating an empty implementation code file for the function based on the second function.
[0097] The programming language may be C, C++, Java or others. The grammatical rules of the programming language are the grammatical rules that a code file written in the programming language must comply with so that the code file can be compiled.
[0098] The target function type may include a virtual function, a static member function or others. In the source code file, a virtual function may be modified by the virtual keyword. If the source code file includes a function modified by virtual, the function may be determined to be the second function. A static member function may be modified by the static keyword. If the source code file includes a function modified by static, the function may be determined to be the second function. The entire second function in the source code file may be generated as an empty implementation code file.
[0099] In this embodiment, an empty implementation code file of the function is generated based on the second function, and the second function matches the target function type necessary when compiling the code of the programming language corresponding to the code project. The empty implementation code file includes the functions necessary for compilation, so that it can be compiled.
[0100] In one embodiment, the step of generating an empty implementation code file for a function among multiple functions also includes: for a function among multiple functions, when a static variable is declared in the code header file of the function, obtaining the data type declared for the static variable; performing initial assignment on the static variable according to the data type of the static variable; and generating an empty implementation code file for the function based on the static variable after the initial assignment.
[0101] Among them, the code header file of the function is the header file corresponding to the function. Static variables are variables modified by the static keyword. The data type of a static variable can be an integer, a string, a Boolean, or other. The static variable can be initially assigned a preset value or a default value. For example, if the data type of the static variable is an integer, it can be assigned a value of "0". If the data type of the static variable is a string type, it can be assigned a value of "empty string" or "nullptr". If the data type of the static variable is a Boolean type, it can be assigned a value of "false".
[0102] In this embodiment, if static variables are declared in the code header file of the function, initial assignment is performed according to the data type of the static variables to avoid compilation errors.
[0103] In one embodiment, the above code compilation method specifically includes the following steps.
[0104] For a function among multiple functions, the computer device can determine, in the source code file of the targeted function, a first function called by other source code files; eliminate the function logic code in the function body of the first function; and determine an empty implementation function corresponding to the first function based on the remaining part of the first function after the elimination.
[0105] The computer device can determine the programming language corresponding to the code project; determine the target function type necessary when compiling the code of the programming language according to the grammatical rules of the programming language; and determine a second function in the source code file of the targeted function that matches the target function type.
[0106] When a static variable is declared in a code header file of a targeted function, the computer device can obtain the data type declared for the static variable; and perform initial assignment of the static variable according to the data type of the static variable.
[0107] The computer device may determine multiple header file identifiers introduced in the source code file of the targeted function, and determine a target header file identifier that matches the preconfigured necessary header file type from the multiple header file identifiers. The target header file identifier may include at least header file identifiers required for the empty implementation function, the second function, and the static variable.
[0108] The computer device can generate an empty implementation code file for the function according to the empty implementation function, the second function, the static variables after initial assignment, and the target header file identifier. Among the functions included in the source code file of the function, except for the called first function and the second function required for compilation, the functions may not participate in the generation of the empty implementation code file, thereby reducing the amount of code in the empty implementation code file, reducing the amount of compiled code, and shortening the compilation time. In addition, the risk of the empty implementation code file exists in the compilation stage. If there is a problem with the empty implementation code file, an error will be reported in the subsequent compilation process. After the library file is successfully compiled and generated, the empty implementation code file will not introduce new risks to the program that loads the library file.
[0109] Referring to the on-demand compilation process diagram shown in FIG2 , after starting to compile a code project (which may be a C++ project), the computer device may obtain a compilation configuration file of the code project, and determine the empty implementation switch information of each of the multiple functions that can be implemented by the code project based on the compilation configuration file.
[0110] The computer device can determine the first type of functions that are closed by empty implementation and the second type of functions that are opened by empty implementation among multiple functions based on the empty implementation switch information; obtain the source code file path of the first type of function, and obtain the source code file of the first type of function under the source code file path; obtain the empty implementation code file path of the first type of function, and obtain the empty implementation code file of the second type of function under the empty implementation code file path. Through the above steps, the source code files to be compiled can be collected (the file extension is ".cpp"). Among them, "EMPTY_xxx" in Figure 2 is used to refer to the empty implementation variable of the function, for example, the empty implementation variable of the beauty eye function is "EMPTY_Eye". If the value of "EMPTY_xxx" is "on", it means that the empty implementation is turned on, pointing to the corresponding empty implementation code file path (under the empty implementation code file directory "emptySrc"). If the value of "EMPTY_xxx" is "off", it means that the empty implementation is turned off, pointing to the corresponding source code file path (under the source code file directory "src"). The "other related steps" before "collecting all .cpp files" in Figure 2, for example, can be to obtain the compilation configuration file.
[0111] The computer device may obtain a common supporting source code file shared by multiple functions, compile based on the common supporting source code file, the source code file of the first type of function, and the empty implementation code file of the second type of function, and output a library file for loading into the program to implement the first type of function. Among them, the "other related steps" after "compile .cpp file" in Figure 2 can be, for example, a step of loading the library file into the program.
[0112] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0113] Based on the same inventive concept, the embodiment of the present application also provides a code compilation device for implementing the code compilation method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more code compilation device embodiments provided below can refer to the limitations on the code compilation method above, and will not be repeated here.
[0114] In an exemplary embodiment, as shown in FIG3 , a code compiling device 300 is provided, including: an acquisition module 310 and a compiling module 320, wherein:
[0115] An acquisition module 310 is used to acquire a compilation configuration file of a code project, and determine the empty implementation switch information of each of multiple functions that can be implemented by the code project based on the compilation configuration file; determine, based on the empty implementation switch information, a first type of function that is closed by empty implementation among multiple functions, and a second type of function that is turned on by empty implementation; acquire source code files of the first type of functions; acquire empty implementation code files of the second type of functions, the empty implementation code files including part of the code in the source code files of the second type of functions, where the part of the code is the code required for compilation without implementing the second type of functions.
[0116] The compiling module 320 is used to compile based on the source code file of the first type of function and the empty implementation code file of the second type of function, and output a library file for loading into the program to implement the first type of function.
[0117] In one embodiment, the code compilation device 300 may include an empty implementation processing module, which is used to determine, in the source code file of the function, a first function called by other source code files for a function among multiple functions; eliminate the function logic code in the function body of the first function; determine an empty implementation function based on the remaining part of the first function after elimination; and generate an empty implementation code file of the function according to the empty implementation function.
[0118] In one embodiment, the empty implementation processing module is also used to determine multiple header file identifiers introduced in the source code file of the function; determine the target header file identifier that matches the preconfigured necessary header file type from the multiple header file identifiers; and generate an empty implementation code file of the function based on the target header file identifier and the empty implementation function.
[0119] In one embodiment, the return type of the first function indicates that the first function has a return value, and the remaining part of the first function after being removed includes the code in the function body for outputting a return value matching the return type.
[0120] In one embodiment, the empty implementation processing module is also used to determine the programming language corresponding to the code project; determine the target function type necessary when compiling the code of the programming language according to the grammatical rules of the programming language; for a function among multiple functions, when the source code file of the function includes a second function that matches the target function type, generate an empty implementation code file of the function based on the second function.
[0121] In one embodiment, the empty implementation processing module is also used to obtain the data type declared for the static variable for a function among multiple functions when a static variable is declared in the code header file of the function; perform initial assignment on the static variable according to the data type of the static variable; and generate an empty implementation code file of the function based on the static variable after the initial assignment.
[0122] Each module in the above code compilation device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0123] In an exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be shown in FIG4. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store the data required for executing the above-mentioned code compilation method. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a code compilation method is implemented.
[0124] Those skilled in the art will understand that the structure shown in FIG. 4 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0125] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0126] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0127] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0128] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method 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 the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0129] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0130] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A code compilation method, characterized in that: The method comprises: Obtaining a compilation configuration file of the code project, and determining, based on the compilation configuration file, respective empty implementation switch information of a plurality of functions that can be implemented by the code project; Based on the empty implementation switch information, determining a first type of function that is closed by empty implementation and a second type of function that is opened by empty implementation among the multiple functions; Obtain source code files of the first category of functions; Obtaining an empty implementation code file of the second-category function, wherein the empty implementation code file includes a portion of code in the source code file of the second-category function, wherein the portion of code is code required for compiling without implementing the second-category function; Compile based on the source code file of the first category of functions and the empty implementation code file of the second category of functions, and output a library file for loading into a program to implement the first category of functions.
2. The method according to claim 1, characterized in that The method further comprises: For a function among the multiple functions, determining, in a source code file of the function, a first function called by other source code files; Eliminate the function logic code in the function body of the first function; Determine an empty implementation function based on the remaining portion of the first function after elimination; According to the empty implementation function, an empty implementation code file of the function is generated.
3. The method according to claim 2, characterized in that The step of generating an empty implementation code file of the function according to the empty implementation function comprises: Determine multiple header file identifiers introduced in the source code file of the function; Determine, from the plurality of header file identifiers, a target header file identifier that matches a preconfigured necessary header file type; Generate an empty implementation code file of the function according to the target header file identifier and the empty implementation function.
4. The method according to claim 2, characterized in that: The return type of the first function indicates that the first function has a return value, and the remaining part of the first function after being removed includes the code in the function body for outputting a return value matching the return type.
5. The method according to claim 1, characterized in that The method further comprises: Determine the programming language corresponding to the code project; Determining, according to the grammatical rules of the programming language, the target function type necessary when compiling the code of the programming language; For a function among the multiple functions, when the source code file of the function includes a second function matching the target function type, an empty implementation code file of the function is generated based on the second function.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: For a function among the multiple functions, when a static variable is declared in a code header file of the function, obtaining a data type declared for the static variable; According to the data type of the static variable, initially assign a value to the static variable; Based on the static variables after initial assignment, an empty implementation code file of the function is generated.
7. A code compiling device, characterized in that: The device comprises: An acquisition module is used to acquire a compilation configuration file of a code project, and determine the empty implementation switch information of each of a plurality of functions that can be realized by the code project based on the compilation configuration file; determine, based on the empty implementation switch information, a first type of function whose empty implementation is turned off and a second type of function whose empty implementation is turned on among the plurality of functions; acquire a source code file of the first type of function; acquire an empty implementation code file of the second type of function, the empty implementation code file including a portion of code in the source code file of the second type of function, the portion of code being code required for compilation without realizing the second type of function; A compiling module is used to compile based on the source code file of the first category of functions and the empty implementation code file of the second category of functions, and output a library file for loading into a program to implement the first category of functions.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
