File compilation method and device
By dividing the compilation units according to the hierarchical directory of the source file for compilation, the compilation efficiency problem under the limitations of hardware devices and compiler performance is solved, the compilation efficiency and stability of large-scale projects are improved, redundant compilation and template instantiation are avoided, and an efficient file compilation process is achieved.
Patent Information
- Application Number
- CN202210759391.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-30
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2042-06-30
AI Technical Summary
In the existing technology, due to the limitations of hardware devices and compiler performance, the compilation efficiency of code source files is insufficient. In particular, in large-scale projects, there are problems such as hardware performance mismatch caused by an excessive number of compilation units, redundant compilation of header files, and excessive number of template instantiation preprocessing times, resulting in insufficient compilation efficiency.
By obtaining the file information of the source file, determining the hierarchical directory to which it belongs, and dividing the source file into corresponding compilation units for compilation based on the preset correspondence between the hierarchical directory and the compilation unit, multiple source files are compiled using the compilation unit to avoid repeated data calls and template instantiations, thereby improving compilation efficiency.
It improves compilation efficiency in large-scale projects, avoids redundant compilation of header files and multiple instantiation preprocessing of templates, improves overall compilation speed and stability, and reduces the risk of blocking during the compilation process.
Smart Images

Figure CN115033249B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of file compilation technology, and more particularly to a file compilation method. Background Art
[0002] With the development of Internet technology, computer programs play an increasingly important role in people's production and life.
[0003] After writing the code source file, the program developer needs to compile the code source file and convert it into a binary executable file that can be recognized by the computer to obtain a computer program product.
[0004] However, as the functionality of computer program products continues to improve, more and more complex source code files need to be compiled. However, due to performance limitations of hardware devices and compilers, the compilation efficiency of source code files is insufficient. Therefore, a file compilation method that can achieve efficient compilation is urgently needed. Summary of the Invention
[0005] In view of this, embodiments of this specification provide a file compilation method. One or more embodiments of this specification also relate to a file compilation device, a computing device, a computer-readable storage medium, and a computer program to address technical deficiencies in the prior art.
[0006] According to a first aspect of an embodiment of this specification, a file compilation method is provided, comprising:
[0007] Acquire multiple source files, wherein the source files include file information;
[0008] According to the file information of each source file, determine the hierarchical directory to which each source file belongs;
[0009] According to the preset correspondence between the hierarchical directory and the compilation unit, each source file is divided into the compilation unit corresponding to the hierarchical directory to which each source file belongs;
[0010] Call each compilation unit to compile multiple source files and generate target executable files.
[0011] According to a second aspect of the embodiments of this specification, a file compilation device is provided, comprising:
[0012] An acquisition module is configured to acquire a plurality of source files, wherein the source files include file information;
[0013] The determination module is configured to determine the hierarchical directory to which each source file belongs based on the file information of each source file;
[0014] an allocation module configured to allocate each source file to a compilation unit corresponding to the hierarchical directory to which each source file belongs according to a preset correspondence between the hierarchical directory and the compilation unit;
[0015] The generation module is configured to call each compilation unit, compile multiple source files, and generate a target executable file.
[0016] According to a third aspect of an embodiment of this specification, a computing device is provided, including:
[0017] memory and processor;
[0018] The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the above-mentioned file compilation method are implemented.
[0019] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores computer-executable instructions, and when the instructions are executed by a processor, the steps of the above-mentioned file compilation method are implemented.
[0020] According to a fifth aspect of the embodiments of this specification, a computer program is provided, wherein when the computer program is executed in a computer, the computer is caused to execute the steps of the above-mentioned file compilation method.
[0021] In one embodiment of the present specification, multiple source files are obtained, and based on the file information of each source file, the hierarchical directory to which each source file belongs is determined. Based on the preset correspondence between the hierarchical directory and the compilation unit, each source file is divided into the compilation unit corresponding to the hierarchical directory to which each source file belongs, and each compilation unit is called to compile the multiple source files to generate a target executable file. By utilizing the preset correspondence between the hierarchical directory to which each source file belongs and the compilation unit, the source files are divided into corresponding compilation units, which satisfies the requirement that one compilation unit can compile multiple source files, thereby improving compilation efficiency. In addition, the multiple source files of a compilation unit are divided according to the directory hierarchy and have a high degree of similarity, which can avoid repeatedly calling the same data and methods from storage to cache for compilation, further improving compilation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is a source file compilation processing diagram of a file compilation method;
[0023] Figure 2 It is a source file compilation processing diagram of another file compilation method;
[0024] Figure 3 This is a flowchart of a file compilation method provided by an embodiment of this specification;
[0025] Figure 4A This is a flowchart of a processing process of a file compilation method applied to a cmake compilation platform provided by an embodiment of this specification;
[0026] Figure 4B This is a schematic diagram of a processing process of a rule description file generation platform provided by an embodiment of this specification;
[0027] Figure 5 This is a schematic diagram of a processing process of a joint compilation method using a rule description file generation platform provided in one embodiment of this specification;
[0028] Figure 6 This is a schematic diagram of the structure of a file compilation device provided by an embodiment of this specification;
[0029] Figure 7 This is a structural block diagram of a computing device provided by one embodiment of this specification. DETAILED DESCRIPTION
[0030] The following description sets forth many specific details to facilitate a thorough understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the scope of this specification. Therefore, this specification is not limited to the specific implementations disclosed below.
[0031] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "a," "the," and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0032] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0033] First, the terms involved in one or more embodiments of this specification are explained.
[0034] Compilation: The process of using the compiler of the compilation platform to convert source files written in a high-level programming language into binary target executable files.
[0035] Header file: A carrier file in a source file used to define global variables, functions, and data interfaces.
[0036] STL (Standard Template Library): is a C++ software library that contains four components: algorithms, containers, functions, and iterators.
[0037] Boost: A generic term for C++ libraries that extend the C++ language standard library. It is a portable, source-code-available C++ library that serves as a backup to the standard library.
[0038] Link processing: merge the segment tables and merge and redefine the symbol tables after compiling and assembling the codes of all source files.
[0039] Traditionally, the compilation process of code source files written in high-level programming languages is a separate compilation process.
[0040] Taking the C++ high-level programming language as an example, due to computer hardware limitations, it's impossible to package and compile multiple CPP source files all at once. Each CPP source file needs to be divided into compilation units, and each compilation unit independently parses the header files contained in the CPP source file. In engineering applications, N CPP source files may share a single header file, requiring the header file to be parsed N times before compilation. In particular, the header files of CPP source files often contain STL or Boost templates, which require instantiation preprocessing before they can be used. Therefore, during the compilation of N source files, the template content must be instantiated and preprocessed N times within the std namespace.
[0041] Figure 1 A schematic diagram of source file compilation processing of a file compilation method is shown.
[0042] Taking the C high-level programming language as an example, there are three code source files foo1.c, foo2.c, and foo3.c. First, the three code source files are preprocessed to obtain the corresponding source files to be compiled foo1.i, foo2.i, and foo3.i. The three source files to be compiled are divided into three compilation units. Using the compilation units, the three source files to be compiled are separately compiled to obtain target compilation files foo1.o, foo2.o, and foo3.o. The three target compilation files are linked to obtain the target executable file target.
[0043] This one-to-one correspondence between code source files and compilation units consumes a lot of time due to multiple redundant compilations of header files and multiple instantiation preprocessing of templates, resulting in insufficient overall compilation efficiency.
[0044] In many high-level programming languages, such as Golang and Java, compilation units are compiled based on project (module) units, that is, multiple source files are divided into compilation units. By drawing on this concept, Unity Build divides all or part of the source files into compilation units, which can reduce redundant compilation of header files and multiple instantiation preprocessing of templates.
[0045] Figure 2 A schematic diagram of source file compilation processing of another file compilation method is shown.
[0046] continue Figure 1 In the C high-level programming language example, there are three code source files foo1.c, foo2.c, and foo3.c. First, the three code source files are jointly processed to obtain the joint code source file unity.c. Then, the joint code source file unity.c is preprocessed to obtain the corresponding joint source file to be compiled unity.i. A compilation unit is configured for the joint source file to be compiled unity.i. The compilation unit is used to jointly compile the joint source files to be compiled to obtain the joint target compiled file unity.o. The joint target compiled file is linked to obtain the target executable file target.
[0047] This joint compilation process avoids multiple redundant compilations of header files and multiple instantiation preprocessing of templates, saving preprocessing time and compilation time and improving overall compilation efficiency.
[0048] However, the above joint compilation method is an ideal processing method. In actual application, there are the following problems:
[0049] The configuration rules for compilation units that need to be set in joint compilation are uncertain. If the compilation units are not set in combination with the relevant characteristics of the code source files themselves, it is difficult to improve the overall compilation efficiency. Moreover, due to the uncertainty of the configuration rules, different compilation processes will have different reference standards. For example, the reference standard can generate different configuration rules for the number of code source files of each compilation unit, the header file relevance of the code source files, the number of code lines of the code source files, the complexity of the code source files, etc., making it impossible to perform repeatable compilation. If the compiler is adjusted for each configuration rule, the adjustment cost is too high.
[0050] Currently, the cmake compilation platform supports joint compilation starting from version 3.16, and has determined the reference standard for batch grouping to determine the configuration rules. The compilation units are configured according to the determined configuration rules for the joint source files to be compiled, and joint compilation is performed.
[0051] Specifically, the cmake compilation platform generates a rule description file CMakeList.txt based on the source code files to be compiled, determines the configuration rules, and when compiling, compiles multiple source code files to be compiled based on the rule description file CMakeList.txt.
[0052] The CMake compilation platform first determines the maximum number of source code files to be compiled for a compilation unit by setting the variable UNITY_BUILD_BATCH_SIZE. It then groups the files into batches, obtaining multiple groups of source code files to be compiled. It then configures a corresponding compilation unit for each group of source code files to be compiled, and then performs subsequent compilation. For example, if the number of source code files to be compiled is 32, setting the variable UNITY_BUILD_BATCH_SIZE to 10 results in four groups of source code files to be compiled, with the number of source code files in each group being 10, 10, 10, and 2, respectively. It then configures a corresponding compilation unit for each group of source code files to be compiled, and then performs subsequent compilation.
[0053] However, the above-mentioned joint compilation method based on batch grouping does not solve the following problems:
[0054] 1. For a current project that contains thousands or even tens of thousands of code source files, this batch grouping method will result in too many code source files to be compiled in each compilation unit, which will not match the performance of the hardware equipment and the compiler, resulting in blocking and other problems.
[0055] Second, there is no guarantee that code source files with high similarity are configured with the same compilation unit, that is, there is no guarantee that code source files with high similarity in header files are configured. Multiple redundant compilations of header files and multiple instantiation preprocessing of templates are performed, resulting in insufficient overall compilation efficiency.
[0056] 3. Configure compilation units based only on quantity. When the order of source code files changes, the determined groups will be different and non-repetitive. For example, if the source code files are foo1.c, foo2.c, foo3.c, ... foo20.c, and four groups are determined, and the corresponding compilation units are configured. If the order is foo1.c, foo2.c, foo3.c, ... foo20.c, then the groups are (foo1.c ... foo5.c) (foo6.c ... foo10.c) (foo11.c ... foo15.c) (foo16.c ... …foo20.c), if the order is foo3.c, foo11.c, foo14.c……foo18.c, then the grouping is (foo4.c……foo17.c)(foo2.c……foo20.c)(foo1.c……foo15.c)(foo16.c……foo18.c). Such configuration compilation units are not repeatable. However, due to the different coding habits of different code developers, it is difficult to unify the order of all code source files. Therefore, it is necessary to determine the configuration rules based on the characteristics of the code source files themselves.
[0057] In response to the above-mentioned problems, this specification provides a file compilation method. This specification also involves a file compilation device, a computing device, and a computer-readable storage medium, which are described in detail one by one in the following embodiments.
[0058] See also Figure 3 , Figure 3 A flowchart of a file compilation method provided according to an embodiment of this specification is shown, which specifically includes the following steps.
[0059] Step 102: Acquire multiple source files, wherein the source files include file information.
[0060] Source files are code source files, written in a computer programming language by computer program developers using appropriate development tools. Code source files cannot be directly recognized and executed by computer hardware, so they must be compiled to produce binary target executable code that can be recognized and executed by computer hardware. Computer programming languages are high-level programming languages, such as C, C++, Java, Python, and Go.
[0061] File information is information that can characterize the characteristics of a source file, that is, it can be obtained through, for example, the file name of the source file, the calling relationship between each source file recorded in the calling list of the source file, etc. The similarity between source files can be determined through the file information of multiple source files. For example, the file names of two source files are alloc / ob_alloc_common.cpp and alloc / ob_alloc_interface.cpp. Through the file names of the two, it can be determined that both are sub-directory files under the alloc level, and the variables, functions, objects, return types and execution logic of the two have a large number of intersections and are highly similar. For another example, source file 1 and source file 2, by querying the calling list of the source files, it is determined that source file 1 will call source file 2, and the variables, functions, objects, return types and execution logic of the two are strongly correlated and highly similar.
[0062] The method for obtaining multiple source files can be to obtain multiple code source files pre-written on a low-speed storage medium and store them on a high-speed storage medium by generating source file acquisition instructions, or to call multiple code source files pre-stored on a high-speed storage medium by generating source file acquisition instructions. Among them, low-speed storage media include hard disks, magnetic disks, USB flash drives, etc., and high-speed storage media include memory, cache, etc. This embodiment of the present specification is not limited to this.
[0063] Specifically, a plurality of source files are obtained, wherein the source files include file names of the source files or a call list between the source files.
[0064] For example, 10 pre-stored source files are retrieved from the cache:
[0065] Source file 1: code_generator / ob_code_generator.cpp
[0066] Source file 2: alloc / ob_alloc_common.cpp
[0067] Source file 3: case_alloc / sub_case_ob_alloc_def.cpp
[0068] Source file 4: case_alloc.h
[0069] Source file 5: code_generator / ob_column_index_provider.cpp
[0070] Source file 6: alloc.h
[0071] Source file 7: code_generator / ob_expr_generator_impl.cpp
[0072] Source file 8: code_generator.h
[0073] Source file 9: alloc / ob_alloc_interface.cpp
[0074] Source file 10: code_generator / ob_static_engine_cg.cpp
[0075] Among them, the source files include the call list between source files, and the call relationship between each source file is:
[0076] Source File 6 - Source File 2, Source File 9
[0077] Source File 8 - Source File 1, Source File 5, Source File 7, Source File 10
[0078] Source file 4 - source file 3
[0079] By including multiple source files with file information, a file foundation is laid for subsequent file compilation to obtain the target executable file, and an information foundation is laid for subsequent determination of the hierarchical directory to which each source file belongs.
[0080] Step 104: Determine the hierarchical directory to which each source file belongs based on the file information of each source file.
[0081] The hierarchical directory is a hierarchical directory that indicates the calling relationship between source files. For example, the source file main.c is the main function file, and main / class_mode.c is an object file that defines mode in the main function. By calling the object file in the main function file, the hierarchical directory of the source file is the first-level directory, and the hierarchical directory of the object file is the second-level directory.
[0082] The method of determining the hierarchical directory to which each source file belongs based on the file information of each source file is as follows: determining the directory hierarchy to which the source file belongs based on the file name of each source file, or determining the directory hierarchy of each source file based on the calling relationship of each source file recorded in the calling list of the source file.
[0083] Specifically, the hierarchical directory to which each source file belongs is determined according to the file name of each source file or the calling relationship between each source file in the calling list of the source file.
[0084] For example, according to the calling relationship of each source file in the calling list between the source files (source file 6 - source file 2, source file 9; source file 8 - source file 1, source file 5, source file 7, source file 10; source file 4 - source file 3), the directory level of source file 6, source file 8, and source file 4 is determined to be the first directory level, and the directory level of source file 2, source file 9, source file 1, source file 5, source file 7, source file 10, and source file 3 is determined to be the second directory level.
[0085] According to the file information of each source file, the hierarchical directory to which each source file belongs is determined respectively, which provides a reference basis for the subsequent division of each source file into editing units.
[0086] Step 106 : According to the preset correspondence between the hierarchical directories and the compilation units, each source file is divided into a compilation unit corresponding to the hierarchical directory to which the source file belongs.
[0087] Compilation units are pre-defined execution units within the compiler that can compile multiple source files. They can be either hardware or virtual logic units, with no specific limitations. Compilation units sequentially perform lexical analysis, syntax analysis, semantic checking, intermediate code generation, and code optimization on source files to produce the target executable file.
[0088] The correspondence between hierarchical directories and compilation units is that one or more compilation units are set for each hierarchical directory. Each compilation unit includes attribute information for the compilation unit. The attribute information is the file name of the directory one level above the source file or the name of the common compilation unit "common". For example, a common compilation unit is set for the first-level directory with the attribute information "common". For the second-level directory, multiple dedicated compilation units are set. For example, for the source files alloc / ob_alloc_common.cpp and alloc / ob_alloc_interface.cpp, the file name of the directory one level above the source file "alloc" is set as the compilation unit attribute information.
[0089] Specifically, according to the preset correspondence between the hierarchical directory and the compilation unit, the source files of the first-level directory are divided into pre-set general compilation units, corresponding compilation units are generated for other source files, and other source files are divided into general compilation units or corresponding compilation units.
[0090] For example, the correspondence between the preset hierarchical directories and the compilation units is as follows:
[0091] First-level directory - common compilation unit; second-level directory - common compilation unit, alloc compilation unit, code_generator compilation unit, case_alloc compilation unit, divide source file 6, source file 8, and source file 4 of the first directory level into the pre-set common compilation unit, and divide source file 2, source file 9, source file 1, source file 5, source file 7, source file 10, and source file 3 of the second directory level into the corresponding alloc compilation unit, code_generator compilation unit, and case_alloc compilation unit.
[0092] get:
[0093] Common compilation unit:
[0094] alloc.h
[0095] case_alloc.h
[0096] code_generator.h
[0097] alloc compilation unit:
[0098] alloc / ob_alloc_common.cpp
[0099] alloc / ob_alloc_interface.cpp
[0100] code_generator compilation unit:
[0101] code_generator / ob_code_generator.cpp
[0102] code_generator / ob_column_index_provider.cpp
[0103] code_generator / ob_expr_generator_impl.cpp
[0104] code_generator / ob_static_engine_cg.cpp
[0105] case_alloc compilation unit:
[0106] case_alloc / sub_case_ob_alloc_def.cpp
[0107] According to the preset correspondence between the hierarchical directory and the compilation unit, each source file is divided into the compilation unit corresponding to the hierarchical directory to which each source file belongs, so that similar source files can be divided into the compilation units of the corresponding directory level.
[0108] Step 108: Call each compilation unit to compile multiple source files to generate a target executable file.
[0109] The method of calling each compilation unit, compiling multiple source files, and generating a target executable file can be: each compilation unit can be called sequentially to compile multiple source files serially to generate a target executable file, each compilation unit can be called in parallel to compile multiple source files in parallel to generate a target executable file, or a fixed number of compilation units can be called according to a preset compilation group, a fixed number of compilation units can be compiled in parallel in the compilation group, and serial compilation can be performed between compilation groups to compile multiple source files to generate a target executable file.
[0110] The target executable file is a binary file that can be recognized and executed by a computer.
[0111] Specifically, according to the pre-sorted result of each compilation unit and / or the sorted result of the source files of any compilation unit, multiple source files of each compilation unit are compiled in sequence to generate a target executable file.
[0112] For example, the common compilation unit, alloc compilation unit, code_generator compilation unit, and case_alloc compilation unit are pre-sorted, and the sorting results are: common compilation unit, alloc compilation unit, case_alloc compilation unit, code_generator compilation unit. First, the source files of the common compilation unit are sorted, and the sorting results are: alloc.h, case_alloc.h, code_generator.h. Similarly, the sorting results of the alloc compilation unit, code_generator compilation unit, and case_alloc compilation unit are alloc / ob_alloc_common.cpp, alloc / ob_alloc_interface.cpp; code_generator / ob_code_generator.cpp, code_generator / ob_column_index_provider.cpp, code_generator / ob_expr_generator_impl.cpp, code_generator / ob_static_engine_cg.cpp; and case_alloc / sub_case_ob_alloc_def.cpp. According to the sorting results of each compilation unit and / or the sorting results of the source files of the compilation unit, multiple source files of each compilation unit are compiled in sequence to generate a target executable file:
[0113] Target executable file 1: code_generator / ob_code_generator.o
[0114] Target executable file 2: alloc / ob_alloc_common.o
[0115] Target executable file 3: case_alloc / sub_case_ob_alloc_def.o
[0116] Target executable file 4: case_alloc.o
[0117] Target executable file 5: code_generator / ob_column_index_provider.o
[0118] Target executable file 6: alloc.o
[0119] Target executable file 7: code_generator / ob_expr_generator_impl.o
[0120] Target executable file 8: code_generator.o
[0121] Target executable file 9: alloc / ob_alloc_interface.o
[0122] Target executable file 10: code_generator / ob_static_engine_cg.o
[0123] In the embodiments of this specification, multiple source files are obtained, and based on the file information of each source file, the hierarchical directory to which each source file belongs is determined respectively. Based on the preset correspondence between the hierarchical directory and the compilation unit, each source file is divided into the compilation unit corresponding to the hierarchical directory to which each source file belongs, and each compilation unit is called to compile the multiple source files to generate a target executable file. By utilizing the preset correspondence between the hierarchical directory to which each source file belongs and the compilation unit, the source files are divided into corresponding compilation units, which satisfies the requirement that one compilation unit can compile multiple source files, thereby improving compilation efficiency. In addition, the multiple source files of a compilation unit are divided according to the directory hierarchy and have a high degree of similarity, which can avoid repeatedly calling the same data and methods from the storage to the cache for compilation, further improving compilation efficiency.
[0124] Optionally, step 104 includes the following specific steps:
[0125] According to the file information of each source file, determine the initial level directory to which each source file belongs;
[0126] Count the number of source files in each initial level directory;
[0127] According to the number of source files in each initial level directory, the level directory to which each source file belongs is updated.
[0128] If there are too many source files assigned to a compilation unit, the compilation process will be blocked due to the limited performance of the hardware device and compiler. Therefore, it is necessary to limit the number of source files in compilation units under different levels of directories according to the performance of the hardware device and compiler to ensure the normal progress of the compilation process.
[0129] The initial hierarchical directory is the hierarchical directory directly determined in step 104 according to the file names of the source files or the calling relationships of the source files in the calling list of the source files.
[0130] According to the number of source files under each initial hierarchical directory, the hierarchical directory to which each source file belongs is updated as follows: according to the performance of the hardware device and the compiler, a threshold value of the number of source files of the compilation unit of the hierarchical directory is set, and the hierarchical directory of the source file is determined based on whether the number of source files of the compilation unit of the initial hierarchical directory of each source file reaches the threshold value.
[0131] Specifically, according to the file information of each source file, the initial level directory to which each source file belongs is determined, including:
[0132] The initial level directory to which each source file belongs is determined according to the file name of each source file or the calling relationship between each source file in the calling list of the source file.
[0133] Optionally, based on the number of source files in each initial level directory, the level directory to which each source file belongs is updated, including:
[0134] It is determined whether the number of each compilation unit under each initial level directory reaches a threshold; if so, the initial level directory to which the source file belongs is determined to be the level directory of the source file.
[0135] For example, the 10 source files are as follows:
[0136] Source file 1: source / main.cpp
[0137] Source file 2: source / backlight / main.cpp
[0138] Source file 3: source / backlight / moc_mainwindow.cpp
[0139] Source file 4: source / backlight / mainwindow.cpp
[0140] Source file 5: source / 3g / main.cpp
[0141] Source file 6: source / 3g / moc_mainwindow.cpp
[0142] Source file 7: source / 3g / mainwindow.cpp
[0143] Source file 8: source / 3g / subwindow.cpp
[0144] Source file 9: source / 4g / main.cpp
[0145] Source file 10: source / 4g / mainwindow.cpp
[0146] According to the file names of each source file, the initial level directory and compilation unit to which each source file belongs are determined as follows:
[0147] Source file 1: second-level directory common compilation unit
[0148] Source file 2: third-level directory backlight compilation unit
[0149] Source file 3: third-level directory backlight compilation unit
[0150] Source file 4: third-level directory backlight compilation unit
[0151] Source file 5: third-level directory 3g compilation unit
[0152] Source file 6: third-level directory 3g compilation unit
[0153] Source file 7: third-level directory 3g compilation unit
[0154] Source file 8: third-level directory 3g compilation unit
[0155] Source file 9: third-level directory 4g compilation unit
[0156] Source file 10: third-level directory 4g compilation unit
[0157] According to the performance of the hardware device and the compiler, the number of source files of the compilation unit under the third-level directory is limited, and the threshold is 3. It is judged whether the number of source files of each compilation unit under each initial-level directory reaches the threshold. If the number of source files of the 3g compilation unit reaches the threshold, the third-level directory of the initial-level directory is determined to be the level directory to which source files 5 to source files 8 belong.
[0158] According to the file information of each source file, the initial hierarchical directory to which each source file belongs is determined respectively, and the number of source files under each initial hierarchical directory is counted. By updating the hierarchical directory to which each source file belongs according to the number of source files under each initial hierarchical directory, flexible adjustment of the hierarchical directory of the source file is achieved. The hierarchical directory can be adjusted accordingly according to the number of source files, avoiding the blocking of the compilation thread due to excessive number of source files in the subsequent compilation process, thereby improving the compilation efficiency.
[0159] Optionally, based on the number of source files in each initial level directory, updating the level directory to which each source file belongs includes the following specific steps:
[0160] Determine whether the number of directories at the current level reaches the threshold;
[0161] If not reached, the source files in the current directory will be moved to the upper directory.
[0162] In the subsequent compilation process of the source files, because the number of source files in each compilation unit called varies greatly, the compilation process with a large number of source files takes a long time, while the compilation process with a small number of source files takes a short time. Such a large difference in the time consumption of the compilation process will reduce the user experience.
[0163] Specifically, it is determined whether the number of current-level directories reaches a threshold value. If not, the source files in the current-level directory are divided into upper-level directories until the number of all current-level directories reaches the threshold value.
[0164] For example, continuing the above example, where source file 1, source file 2-source file 4, and source file 9-source file 10 do not reach the quantity threshold, source file 1 is divided into the first-level directory, source file 2-source file 4 are divided into the second-level directory, and source files 9-10 are divided into the third-level directory. The updated initial level directory and compilation unit to which each source file belongs are obtained as follows:
[0165] Source file 1: first-level directory common compilation unit
[0166] Source file 2: Second-level directory backlight compilation unit
[0167] Source file 3: Second-level directory backlight compilation unit
[0168] Source file 4: Second-level directory backlight compilation unit
[0169] Source file 9: Second level directory 4g compilation unit
[0170] Source file 10: Second level directory 4g compilation unit
[0171] Source file 5: third-level directory 3g compilation unit
[0172] Source file 6: third-level directory 3g compilation unit
[0173] Source file 7: third-level directory 3g compilation unit
[0174] Source file 8: third-level directory 3g compilation unit
[0175] Determine whether the number of directories in the current level has reached the threshold. If not, the source files in the current level directory will be divided into the upper level directory, realizing the reasonable division of the hierarchical directories of the source files. The source files in the current level directory whose number does not reach the threshold can be divided into the upper directory level, ensuring that there will not be too large a difference in the number of source files between the directory levels, making the time consumption of the source file compilation process stable and improving the user experience.
[0176] Optionally, before step 108, the following specific steps are also included:
[0177] Get the attribute information of each compilation unit;
[0178] sorting the compilation units according to their attribute information;
[0179] Correspondingly, step 108 includes the following specific steps:
[0180] According to the sorting results of each compilation unit, each compilation unit is called to compile multiple source files to generate a target executable file.
[0181] Because during the source file writing process, code developers generally follow certain file name naming rules. Generally, file names with short character length, small number of file name characters, and half-width file name characters are of high importance, and the range of functions and objects they include is larger. Therefore, such source files will be compiled first, and their data will be in high-speed storage media and can be used directly in the subsequent source file compilation process, without having to transfer the data in the low-speed storage media to the high-speed storage media for reuse, resulting in insufficient compilation efficiency.
[0182] The attribute information of the compilation unit is the name of the compilation unit or the name “common” of the common compilation unit.
[0183] According to the attribute information of each compilation unit, the compilation units are sorted in the following manner: according to the character information of the name of each compilation unit, the compilation units are sorted. The character information of the compilation unit name can be the character length of the compilation unit name, the first or last letter of the compilation unit name, the half-width character of the compilation unit name and / or the numerical order, etc. For example, the attribute information of compilation unit 1 is "backlight" and the attribute information of compilation unit 2 is 3g. According to the length of the compilation unit names, compilation unit 2 is sorted before compilation unit 1; according to the first letters b and g of the compilation unit names, compilation unit 1 is sorted before compilation unit 2; according to the last letters t and g of the compilation unit names, compilation unit 2 is sorted before compilation unit 1; according to the half-width b and 3 of the compilation unit names, compilation unit 1 is sorted before compilation unit 2.
[0184] Specifically, character information of the name of each compilation unit is obtained, each compilation unit is sorted according to the character information of the name of the compilation unit, each compilation unit is called according to the sorting result of each compilation unit, multiple source files are compiled, and a target executable file is generated.
[0185] Exemplarily, the names of the compilation units are common, backlight, 4g, and 3g. The compilation units are sorted according to the character length and numerical order of the names of the compilation units. The sorting results of the compilation units are: 3g compilation unit, 4g compilation unit, common compilation unit, and backlight compilation unit. The 3g compilation unit, 4g compilation unit, common compilation unit, and backlight compilation unit are called to compile multiple source files in the four compilation units to generate a target executable file.
[0186] The method obtains attribute information of each compilation unit, sorts the compilation units according to the attribute information, and calls each compilation unit based on the sorting results to compile multiple source files to generate a target executable file. This prioritizes the compilation of more important compilation units, reduces repeated calls to related data during the compilation process, and improves compilation efficiency. Furthermore, by sorting the compilation units according to a predetermined sorting rule, compilation becomes repeatable.
[0187] Optionally, after sorting the compilation units according to their attribute information, the following specific steps are further included:
[0188] For any compilation unit, sort the multiple source files in the compilation unit based on the hierarchical directories to which the multiple source files belong;
[0189] Correspondingly, the step 108 of compiling multiple source files to generate a target executable file includes the following specific steps:
[0190] The plurality of source files are compiled according to the first sorting result of the plurality of source files to generate a target executable file.
[0191] Usually, source files with a smaller directory hierarchy will call source files with a larger directory hierarchy. That is, functions and objects defined in source files with a smaller directory hierarchy will be used in source files with a larger directory hierarchy, and data in source files with a smaller directory hierarchy will be used in source files with a larger directory hierarchy. Only by ensuring that source files with a smaller directory hierarchy are compiled first can the normal execution of the compilation process be guaranteed.
[0192] Based on the hierarchical directory to which the source files in the compilation unit belong, the source files are sorted as follows: if the compilation unit includes source files from multiple hierarchical directories, the source files are sorted from small to large according to the size of the directory hierarchy to which the source files belong.
[0193] Specifically, for any compilation unit, the source files are sorted from small to large according to the size of the directory hierarchy to which the source files belong to obtain a first sorting result, and multiple source files are compiled according to the first sorting result to generate a target executable file.
[0194] For example, compilation unit 1 includes five source files:
[0195] Source file 1: alloc.h - first level directory hierarchy
[0196] Source file 2: alloc / ob_alloc_common.cpp - Second level directory
[0197] Source file 3: alloc / ob_alloc_common / sub_alloc_main.cpp - three-level directory hierarchy
[0198] Source file 4: alloc / ob_alloc_interface.cpp - Second level directory
[0199] Source file 5: alloc_main.cpp - first level directory hierarchy
[0200] The five source files are sorted from smallest to largest according to the directory hierarchy to which they belong, and the first sorting result is: source file 1, source file 5, source file 2, source file 4, source file 3. Based on the first sorting result, the five source files are compiled to generate a target executable file.
[0201] For any compilation unit, the source files in the compilation unit are sorted based on the hierarchical directories to which they belong. Based on the first sorting result, the multiple source files are compiled to generate a target executable file. Source files with smaller directory hierarchies are compiled first, ensuring the normal execution of the compilation process. Furthermore, sorting the source files according to a predetermined sorting rule ensures repeatable compilation.
[0202] Optionally, after sorting the source files divided into the compilation units based on the hierarchical directories to which the source files belong, the following specific steps are further included:
[0203] For source files at any directory level, sort the source files at the same directory level based on the file information of the source files;
[0204] Correspondingly, the step 108 of compiling multiple source files to generate a target executable file includes the following specific steps:
[0205] The plurality of source files are compiled according to the second sorting result of the plurality of source files to generate a target executable file.
[0206] Because during the source file writing process, code developers generally follow certain file name naming rules. Generally, file names with short character length, small number of file name characters, and half-width file name characters are of high importance, and the range of functions and objects they include is larger. Therefore, such source files will be compiled first, and their data will be in high-speed storage media and can be used directly in the subsequent source file compilation process, without having to transfer the data in the low-speed storage media to the high-speed storage media for reuse, resulting in insufficient compilation efficiency.
[0207] Source file information is information that can characterize the properties of the source file content, such as the source file name, source file format, and source file complexity. Source file content attributes are properties of functions, objects, execution logic, and other content within the source file.
[0208] Based on the file information of each source file, the source files are sorted in the following manner: based on the character information of the file name of each source file, the source files are sorted. The character information of the file name of the source file may be the character length of the file name of the source file, the first different letter of the file name of the source file, the half-width and / or numerical sequence of the characters of the file name of the source file, etc. For example, the source files include:
[0209] Source file 1: alloc / alloc_main.h
[0210] Source file 2: alloc / alloc_main.cpp
[0211] Source file 3: alloc / alloc_main.c
[0212] Source file 4: alloc / ob_alloc_common.cpp
[0213] Source file 5: alloc / ob_alloc_interface.cpp
[0214] Sort the source files based on the first difference letter of the source file name, and you get:
[0215] Source file 1: alloc / alloc_main.h
[0216] Source file 3: alloc / alloc_main.c
[0217] Source file 2: alloc / alloc_main.cpp
[0218] Source file 4: alloc / ob_alloc_common.cpp
[0219] Source file 5: alloc / ob_alloc_interface.cpp
[0220] Alternatively, the source files are sorted based on their file formats. For example, the source files are sorted based on their file formats to obtain:
[0221] Source file 1: alloc / alloc_main.h
[0222] Source file 3: alloc / alloc_main.c
[0223] Source file 2: alloc / alloc_main.cpp
[0224] Source file 4: alloc / ob_alloc_common.cpp
[0225] Source file 5: alloc / ob_alloc_interface.cpp
[0226] Alternatively, the source files are sorted based on their complexity. The complexity of source file 1 is O(1) = 30200, the complexity of source file 2 is O(2) = 270, the complexity of source file 3 is O(3) = 3000, the complexity of source file 4 is O(4) = 430, and the complexity of source file 5 is O(5) = 200. Based on the complexity of each source file, the source files are sorted to obtain:
[0227] Source file 1: alloc / alloc_main.h
[0228] Source file 3: alloc / alloc_main.c
[0229] Source file 2: alloc / alloc_main.cpp
[0230] Source file 4: alloc / ob_alloc_common.cpp
[0231] Source file 5: alloc / ob_alloc_interface.cpp
[0232] Specifically, for source files at any directory level, the source files at the same directory level are sorted based on the file name of the source file, the file format of the source file or the complexity of the source file. According to the second sorting results of the multiple source files, the multiple source files are compiled to generate a target executable file.
[0233] For source files at any directory level, the source files are sorted based on the file information of the source files in the compilation unit. Based on the second sorting result of the multiple source files, the multiple source files are compiled to generate the target executable file. This prioritizes compilation of source files with a larger scope, improving compilation efficiency. In addition, sorting the source files according to the specified sorting rules ensures repeatable compilation.
[0234] Optionally, before step 104, the following specific steps are further included:
[0235] Reading a preset rule description file, wherein the preset rule description file includes a preset source file list;
[0236] Determine whether the preset source file list contains file information of multiple source files;
[0237] Correspondingly, step 104 includes the following specific steps:
[0238] In the case that the preset source file list includes file information of multiple source files, the hierarchical directory to which each source file belongs is determined according to the file information of each source file.
[0239] The compilation platform needs to compile multiple source files according to certain rules. Therefore, it is necessary to create a rule description file in advance to record the compilation rules for the multiple source files, and then compile the multiple source files according to the rule description file.
[0240] A rule description file is a file that records source file compilation rules. The source file compilation rules include a preset source file list that records multiple source files, division rules for multiple source files, sorting rules for multiple source files, the correspondence between hierarchical directories and compilation units, compilation parameters, etc.
[0241] Specifically, the preset rule description file is read to determine whether the preset source file list contains the file names of multiple source files. If the preset source file list contains the file names of all multiple source files, the hierarchical directory to which each source file belongs is determined according to the file name of each source file, wherein the preset rule description file includes the preset source file list.
[0242] Exemplarily, the preset rule description file List.txt is read to determine whether the preset source file list contains multiple source file names:
[0243] Source file 1: alloc / alloc_main.h
[0244] Source file 3: alloc / alloc_main.c
[0245] Source file 2: alloc / alloc_main.cpp
[0246] Source file 4: alloc / ob_alloc_common.cpp
[0247] Source file 5: alloc / ob_alloc_interface.cpp
[0248] In the case that the preset source file list includes the file names of all the multiple source files, the hierarchical directory to which each source file belongs is determined according to the file name of each source file.
[0249] By reading the preset rule description file including the preset source file list and determining whether the preset source file list contains file information of multiple source files, it is ensured that the multiple source files to be compiled are fully recorded in the rule description file. Subsequently, by compiling the multiple source files according to the rule description file, the corresponding complete target executable file can be obtained, ensuring the integrity of the compilation.
[0250] Optionally, after dividing each source file into a compilation unit corresponding to the hierarchical directory to which each source file belongs according to the preset correspondence between the hierarchical directory and the compilation unit, the following specific steps are further included:
[0251] Generate an updated rule description file based on the correspondence between each source file, each level directory and each compilation unit;
[0252] Correspondingly, calling each compilation unit to compile multiple source files to generate a target executable file includes the following specific steps:
[0253] Based on the updated rule description file, each compilation unit is called to compile multiple source files to generate a target executable file.
[0254] An updated rule description file is generated based on the correspondence between each source file, each hierarchical directory and each compilation unit. A pre-set algorithm can be used to perform hierarchical judgment on the file name of each source file, and then the compilation rules are determined according to the hierarchical directories and each compilation unit, and an updated rule description file is generated based on the compilation rules. Alternatively, the compilation rules in the initial rule description file can be manually obtained, and the compilation rules in the rule description file can be determined and replaced based on the correspondence between each source file, each hierarchical directory and each compilation unit to generate an updated rule description file.
[0255] Specifically, the compilation rules are determined based on the correspondence between each source file, each hierarchical directory and each compilation unit, and an updated rule description file is generated according to the compilation rules. Based on the updated rule description file, each compilation unit is called to compile multiple source files to generate a target executable file.
[0256] For example, the five source files are as follows:
[0257] Source file 1: alloc.h
[0258] Source file 2: alloc / ob_alloc_common.cpp
[0259] Source file 3: alloc / ob_alloc_common / sub_alloc_main.cpp
[0260] Source file 4: alloc / ob_alloc_interface.cpp
[0261] Source file 5: alloc_main.cpp
[0262] Pre-set algorithm: First-level judgment: If the file name of the source file contains the "alloc" character, the source file is determined to be at the first directory level, corresponding to the alloc compilation unit; Second-level judgment: If the file name of the source file in the first-level directory contains the "alloc / ob_alloc" character, the source file is determined to be at the second directory level, corresponding to the alloc compilation unit; Third-level judgment: If the file name of the source file in the second-level directory contains the "alloc / ob_alloc_common / sub_alloc" character, the source file is determined to be at the third directory level. The compilation rules are determined as follows:
[0263] alloc compilation unit:
[0264] Source file 1: alloc.h - first directory level
[0265] Source file 2: alloc / ob_alloc_common.cpp - second directory level
[0266] Source file 3: alloc / ob_alloc_common / sub_alloc_main.cpp - third directory level
[0267] Source file 4: alloc / ob_alloc_interface.cpp - second directory level
[0268] Source file 5: alloc_main.cpp - first directory level
[0269] Generate an updated rule description file List.txt based on the compilation rules.
[0270] Based on the correspondence between source files, hierarchical directories, and compilation units, an updated rule description file is generated. Based on the updated rule description file, each compilation unit is called to compile multiple source files to generate the target executable file. By updating the rule description file, the compilation rules can be adaptively adjusted to meet different compilation requirements, making it more versatile.
[0271] Optionally, before step 104, the following specific steps are further included:
[0272] Identify the file type of each source file according to the file information of each source file;
[0273] Filter out source files of the specified type from multiple source files.
[0274] The file type of each source file indicates whether the source file is required for compilation. These files include strong compilation source files and weak compilation source files. Strong compilation source files require compilation to ensure the normal execution of the compilation process or the subsequent execution of the target executable file. Weak compilation source files do not require compilation, but can still ensure the normal execution of the compilation process and the subsequent execution of the target executable file. Examples include header files and hardware parameter configuration files.
[0275] Filter out source files of a specified type from multiple source files, that is, do not divide the source files of the specified type into compilation units, and perform subsequent compilation.
[0276] Specifically, according to the file name of each source file, the file type of each source file is identified respectively, one or more weakly compiled source files are determined, source files of a specified type are determined from the weakly compiled source files, and the source files of the specified type are filtered.
[0277] For example, the five source files are:
[0278] Source file 1: alloc.h
[0279] Source file 2: alloc / ob_alloc_common.cpp
[0280] Source file 3: alloc / ob_alloc_common / sub_alloc_main.cpp
[0281] Source file 4: alloc / ob_alloc_interface.cpp
[0282] Source file 5: alloc_main.cpp
[0283] According to the file name of the source file, a weak compilation source file is identified and determined, the strong compilation source file is determined to be source file 1 of the header file type, and source file 1 is filtered.
[0284] Based on the file information of each source file, the file type of each source file is identified and source files of the specified type are filtered out from multiple source files. By filtering out source files of the specified type, unnecessary compilation is avoided, while ensuring compilation results and improving overall compilation efficiency.
[0285] The following combined Figure 4A and Figure 4B , taking the application of the file compilation method provided in this manual on the cmake compilation platform as an example, the file compilation method is further explained. Figure 4A A flowchart of a processing process of a file compilation method applied to a cmake compilation platform provided by an embodiment of this specification is shown, which specifically includes the following steps.
[0286] Step 202: Acquire multiple source files, where the source files include file names.
[0287] The multiple source files are fool1.c, fool1.h, fool2.c, fool2.h...fooln.c, fooln.h, and the file names are: fool1, fool2...fooln.
[0288] Step 204: Read the preset rule description file.
[0289] The rule description file CMakeList.txt includes the initial compilation rule input.cmake file and the source file list SourceList.
[0290] Step 206: Determine whether the source file list contains multiple source file names.
[0291] The source file list SourceList contains {foolN.c}. If it contains multiple source file names, step 206 is executed. If it does not contain multiple source file names, an exception instruction is sent to the client to terminate the compilation process.
[0292] Step 208: Identify the file type of each source file according to the file name of each source file, and filter out source files whose file type is a header file type among the multiple source files.
[0293] Filter out the source files fool1.h, fool2.h...fooln.h whose file type is header file (.h).
[0294] Step 210: Obtain the compilation rules in the preset rule description file.
[0295] Compilation rules:
[0296] A compilation unit:
[0297] fool1.c - first directory level
[0298] fool2.c - Second directory level
[0299] B compilation unit:
[0300] Fool3.c - Third directory level
[0301] Fool4.c - Second directory level
[0302] Fool5.c - First directory level
[0303] …
[0304] X compilation unit:
[0305] Fool(n-1).c - third directory level
[0306] fooln.c - third directory level
[0307] Step 212: Determine the hierarchical directory to which each source file belongs based on the file name of each source file.
[0308] According to the file names fool1, fool2...fooln of each source file, the hierarchical directory to which each source file belongs is determined respectively: the first-level directory, the second-level directory, and the third-level directory.
[0309] Step 214 : According to the preset correspondence between the hierarchical directories and the compilation units, each source file is divided into a compilation unit corresponding to the hierarchical directory to which the source file belongs.
[0310] According to the correspondence between the preset hierarchical directory and the compilation unit:
[0311] First-level directory: compilation unit A; second-level directory: compilation unit B, compilation unit C...; third-level directory: compilation unit H, compilation unit K...compilation unit X, and divide the source files fool1.c, fool2.c...fooln.c into compilation units A-compilation units X corresponding to the level directories to which each source file belongs.
[0312] Step 216: Determine updated compilation rules based on the correspondence between each source file, each level directory, and each compilation unit, and generate an updated rule description file.
[0313] According to the correspondence between each source file, each level directory and each compilation unit, determine the updated compilation rule output.cmake:
[0314] Compilation unit A:
[0315] fool1.c - first directory level
[0316] Fool3.c - First directory level
[0317] Compilation unit B:
[0318] Fool2.c - Second directory level
[0319] Fool3.c - Second directory level
[0320] Fool4.c - Second directory level
[0321] Fool5.c - Second directory level
[0322] …
[0323] Compilation unit X:
[0324] Fool(n-1).c - third directory level
[0325] fooln.c - third directory level
[0326] And generate the updated rule description file CMakeList.txt
[0327] Step 218: According to the updated rule description file, each compilation unit is called to compile multiple source files to generate a target executable file.
[0328] According to the updated rule description file CMakeList.txt, compilation unit A - compilation unit X are called to compile the source files fool1.c, fool2.c ... fooln.c to generate target executable files fool1.o, fool2.o ... fooln.o.
[0329] In the embodiments of this specification, the normal execution of the compilation process is ensured by determining whether the file name contains multiple source files. Secondly, source files of the header file type are filtered out, which improves the compilation efficiency while ensuring the compilation effect. Moreover, the source files are divided into corresponding compilation units using the preset correspondence between the hierarchical directory to which each source file belongs and the compilation unit, which satisfies the requirement that one compilation unit can compile multiple source files, further improving the compilation efficiency. In addition, the multiple source files of a compilation unit are divided according to the directory hierarchy and have a high similarity, which can avoid repeatedly calling the same data and methods from the storage to the cache for compilation, further improving the compilation efficiency. Finally, the update rule description file generated according to the determined compilation rules makes the compilation process repeatable.
[0330] Figure 4B A schematic diagram of the processing process of a rule description file generation platform provided in one embodiment of this specification is shown.
[0331] First, load the process:
[0332] Get multiple source files;
[0333] Read the preset rule description file;
[0334] Determines whether the source file list in the preset rule description file contains multiple source file names.
[0335] Next, perform preprocessing:
[0336] Filter out source files whose file type is header file type among multiple source files.
[0337] Then, perform core analysis:
[0338] Get the compilation rules in the preset rule description file;
[0339] Determine the hierarchical directory to which each source file belongs;
[0340] Divide each source file into the compilation unit corresponding to the hierarchical directory to which each source file belongs.
[0341] Finally generate:
[0342] Determine updated compilation rules based on the analysis results obtained from the core analysis;
[0343] Generate an updated rule description file according to the updated compilation rules.
[0344] Figure 5 FIG1 shows a processing diagram of a joint compilation method using a rule description file generation platform provided by an embodiment of this specification. Figure 5As shown, the method includes:
[0345] Get a common compilation project, such as the OceanBase project. Such a project includes thousands of lines of rule description files CMakeList.txt.
[0346] Input the common compilation project into the UCG joint compilation platform. The UCG joint compilation platform supports the joint compilation of multiple source files and updates the compilation rules of the compilation description file CMakeList.txt (input.cmake-output.cmake).
[0347] The UCG joint compilation platform performs joint compilation on common compilation projects according to updated compilation rules to obtain joint compilation projects.
[0348] Corresponding to the above method embodiment, this specification also provides a file compilation device embodiment, Figure 6 FIG. 1 shows a schematic diagram of the structure of a file compilation device provided by an embodiment of this specification. Figure 6 As shown, the device includes:
[0349] The acquisition module 602 is configured to acquire a plurality of source files, wherein the source files include file information;
[0350] The determination module 604 is configured to determine the hierarchical directory to which each source file belongs based on the file information of each source file;
[0351] The allocation module 606 is configured to allocate each source file to a compilation unit corresponding to the hierarchical directory to which each source file belongs according to a preset correspondence between the hierarchical directory and the compilation unit;
[0352] The generation module 608 is configured to call each compilation unit to compile multiple source files and generate a target executable file;
[0353] Optionally, the determination module 604 is further configured to: determine the initial hierarchical directory to which each source file belongs based on the file information of each source file, count the number of source files under each initial hierarchical directory, and update the hierarchical directory to which each source file belongs based on the number of source files under each initial hierarchical directory.
[0354] Optionally, the determination module 604 is further configured to: determine whether the number of directories in the current level reaches a threshold; if not, divide the source files in the directory in the current level into a directory in the previous level.
[0355] Optionally, the device further comprises:
[0356] A first sorting module is configured to obtain attribute information of each compilation unit and sort the compilation units according to the attribute information of each compilation unit;
[0357] Correspondingly, the generation module 608 is further configured to: call each compilation unit according to the sorting result of each compilation unit, compile multiple source files, and generate a target executable file.
[0358] Optionally, the device further comprises:
[0359] A second sorting module is configured to sort the multiple source files in any compilation unit based on the hierarchical directories to which the multiple source files in the compilation unit belong;
[0360] Correspondingly, the generating module 608 is further configured to: compile the multiple source files according to the first sorting result of the multiple source files to generate a target executable file.
[0361] Optionally, the device further comprises:
[0362] a third sorting module configured to sort the source files at the same directory level based on the file information of the source files for the source files at any directory level;
[0363] Correspondingly, the generating module 608 is further configured to: compile the multiple source files according to the second sorting result of the multiple source files to generate a target executable file.
[0364] Optionally, the device further comprises:
[0365] a judgment module configured to read a preset rule description file and determine whether the preset source file list contains file information of multiple source files, wherein the preset rule description file includes the preset source file list;
[0366] Correspondingly, the determining module 604 is further configured to: when the preset source file list includes file information of all the source files, determine the hierarchical directory to which each source file belongs according to the file information of each source file.
[0367] Optionally, the device further comprises:
[0368] A rule description file generation module is configured to generate an updated rule description file according to the correspondence between each source file, each level directory and each compilation unit;
[0369] Correspondingly, the generation module 608 is further configured to call each compilation unit based on the updated rule description file, compile multiple source files, and generate a target executable file.
[0370] Optionally, the device further comprises:
[0371] The filtering module is configured to identify the file type of each source file according to the file information of each source file, and filter out source files of a specified type from the plurality of source files.
[0372] In the embodiments of this specification, multiple source files are obtained, and based on the file information of each source file, the hierarchical directory to which each source file belongs is determined respectively. Based on the preset correspondence between the hierarchical directory and the compilation unit, each source file is divided into the compilation unit corresponding to the hierarchical directory to which each source file belongs, and each compilation unit is called to compile the multiple source files to generate a target executable file. By utilizing the preset correspondence between the hierarchical directory to which each source file belongs and the compilation unit, the source files are divided into corresponding compilation units, which satisfies the requirement that one compilation unit can compile multiple source files, thereby improving compilation efficiency. In addition, the multiple source files of a compilation unit are divided according to the directory hierarchy and have a high degree of similarity, which can avoid repeatedly calling the same data and methods from the storage to the cache for compilation, further improving compilation efficiency.
[0373] The above is a schematic diagram of a file compilation device according to this embodiment. It should be noted that the technical solution of the file compilation device and the technical solution of the file compilation method described above are based on the same concept. For details not described in detail in the technical solution of the file compilation device, please refer to the description of the technical solution of the file compilation method described above.
[0374] Figure 7 7. The block diagram of a computing device according to one embodiment of the present disclosure is shown. Components of the computing device 700 include, but are not limited to, a memory 710 and a processor 720. The processor 720 is connected to the memory 710 via a bus 730, and a database 750 is used to store data.
[0375] The computing device 700 also includes an access device 740 that enables the computing device 700 to communicate via one or more networks 760. Examples of such networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 740 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0376] In one embodiment of the present specification, the above components of the computing device 700 and Figure 7 Other components not shown in the figure may also be connected to each other, for example, via a bus. Figure 7 The computing device structure block diagram shown is for illustrative purposes only and is not intended to limit the scope of this specification. Those skilled in the art may add or replace other components as needed.
[0377] Computing device 700 can be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook computer, etc.), a mobile phone (e.g., a smartphone), a wearable computing device (e.g., a smartwatch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. Computing device 700 can also be a mobile or stationary server.
[0378] The processor 720 is configured to execute the following computer executable instructions, which implement the steps of the above-mentioned file compilation method when executed by the processor.
[0379] The above is a schematic diagram of a computing device according to this embodiment. It should be noted that the technical solution of the computing device and the technical solution of the above-mentioned file compilation method are based on the same concept. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solution of the above-mentioned file compilation method.
[0380] An embodiment of the present specification further provides a computer-readable storage medium storing computer-executable instructions, which implement the steps of the above-mentioned file compilation method when executed by a processor.
[0381] The above is a schematic diagram of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium and the technical solution of the above-mentioned file compilation method are based on the same concept. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solution of the above-mentioned file compilation method.
[0382] An embodiment of the present specification further provides a computer program, wherein when the computer program is executed in a computer, the computer is caused to execute the steps of the above-mentioned file compiling method.
[0383] The above is an illustrative solution of a computer program of this embodiment. It should be noted that the technical solution of this computer program and the technical solution of the above-mentioned file compilation method are based on the same concept. For details not described in detail in the technical solution of the computer program, please refer to the description of the technical solution of the above-mentioned file compilation method.
[0384] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0385] The computer instructions include computer program code, which may be in source code form, object code form, executable file, or some intermediate form. The computer-readable medium may include any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard drive, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunications signal, and a software distribution medium.
[0386] It should be noted that for the aforementioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.
[0387] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0388] The preferred embodiments disclosed above are intended only to help illustrate this specification. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and variations can be made based on the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that those skilled in the art can better understand and utilize this specification. This specification is limited only by the claims and their full scope and equivalents.
Claims
1. A file compilation method, comprising: Acquire multiple source files, wherein the source files include file information; Determining, based on the file information of each source file, the hierarchical directory to which each source file belongs, wherein the hierarchical directory indicates the calling relationship between the source files; According to a preset correspondence between hierarchical directories and compilation units, the source files are respectively divided into compilation units corresponding to the hierarchical directories to which the source files belong, wherein the compilation units are a plurality of execution units preset in the compiler that can perform compilation operations on a plurality of source files. After the source files are respectively divided into compilation units corresponding to the hierarchical directories to which the source files belong according to the preset correspondence between the hierarchical directories and the compilation units, the method further includes: generating an updated rule description file according to the correspondence between the source files, the hierarchical directories, and the compilation units, wherein the rule description file is a pre-created file for recording compilation rules for the plurality of source files; Based on the updated rule description file, each compilation unit is called to compile the multiple source files to generate a target executable file.
2. The method according to claim 1, wherein determining the hierarchical directory to which each source file belongs based on the file information of each source file comprises: Determine the initial level directory to which each source file belongs based on the file information of each source file; Count the number of source files in each initial level directory; According to the number of source files in each initial level directory, the level directory to which each source file belongs is updated.
3. The method according to claim 2, wherein updating the hierarchical directories to which the source files belong based on the number of the source files in the initial hierarchical directories comprises: Determine whether the number of directories at the current level reaches the threshold; If not reached, the source files in the current directory will be moved to the upper directory.
4. The method according to claim 1, before calling each compilation unit to compile the multiple source files to generate the target executable file, further comprising: Get the attribute information of each compilation unit; sorting the compilation units according to the attribute information of the compilation units; The calling of each compilation unit to compile the multiple source files to generate a target executable file includes: According to the sorting results of the compilation units, the compilation units are called to compile the multiple source files to generate a target executable file.
5. The method according to claim 4, further comprising, after sorting the compilation units according to the attribute information of the compilation units, For any compilation unit, sort the multiple source files in the compilation unit based on the hierarchical directories to which the multiple source files belong; Compiling the multiple source files to generate a target executable file includes: According to the first sorting result of the multiple source files, the multiple source files are compiled to generate a target executable file.
6. The method according to claim 5, further comprising, after sorting the plurality of source files in the compilation unit based on the hierarchical directories to which the plurality of source files belong: For source files at any directory level, sort the source files at the same directory level based on the file information of the source files; Compiling the multiple source files to generate a target executable file includes: According to the second sorting result of the multiple source files, the multiple source files are compiled to generate a target executable file.
7. The method according to claim 1, before determining the hierarchical directory to which each source file belongs based on the file information of each source file, further comprising: Reading a preset rule description file, wherein the preset rule description file includes a preset source file list; Determining whether the preset source file list includes file information of the multiple source files; Determining the hierarchical directory to which each source file belongs based on the file information of each source file includes: In a case where the preset source file list includes file information of the plurality of source files, the hierarchical directory to which each source file belongs is determined respectively according to the file information of each source file.
8. The method according to claim 1 or claim 7, before determining the hierarchical directory to which each source file belongs based on the file information of each source file, further comprising: Identifying the file type of each source file according to the file information of each source file; Filter out source files of a specified type from the multiple source files.
9. A file compilation device comprising: An acquisition module is configured to acquire a plurality of source files, wherein the source files include file information; a determination module configured to determine, based on file information of each source file, a hierarchical directory to which each source file belongs, wherein the hierarchical directory indicates a calling relationship between the source files; an allocation module configured to, based on a preset correspondence between hierarchical directories and compilation units, respectively allocate the source files to compilation units corresponding to the hierarchical directories to which the source files belong, wherein the compilation units are a plurality of execution units pre-set in the compiler that can perform compilation operations on a plurality of source files, and the allocation module is further configured to: generate an updated rule description file based on the correspondence between the source files, the hierarchical directories, and the compilation units, the rule description file being a pre-created file for recording compilation rules for the plurality of source files; The generation module is configured to call each compilation unit based on the updated rule description file, compile the multiple source files, and generate a target executable file.
10. A computing device comprising: memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the file compilation method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions, when executed by a processor, implement the steps of the file compilation method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Compiling duration processing method and device
CN112328259A
Compiling method, compiling device, electronic equipment, storage medium and program product
CN113031962A