Script synchronization program compiling method and device, equipment and storage medium
By mounting the source code to the compiler in a read-only manner and using scripts to synchronize the code, the problem of misdeletion and synchronization inconvenience of source code when the development machine and the compiler are inconsistent, and fast, safe and efficient program compilation is achieved.
Patent Information
- Application Number
- CN202411722775.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-03-04
AI Technical Summary
During the software development process, when the development machine and the compiler are inconsistent, the existing technology has defects in the source code error deletion and the need for additional synchronization software, resulting in low synchronization efficiency and inconvenience.
By mounting the source code read-only to the compiler, copy the altered code to the compiled directory using the script, and start compiling after the copy is completed.
It realizes fast synchronization of code without being deleted by mistake, does not require installation of additional synchronization software, improves the convenience and cross-platformity of program compilation, and improves compilation efficiency.
Smart Images

Figure CN119556936A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software development, and in particular to a method, device, electronic device and computer storage medium for program compilation using script synchronization source code. Background Art
[0002] In the process of software development, it is often the case that the development machine and the compiler machine are not the same machine. In this case, the source code needs to be copied to the compiler machine before compiling, and then the compilation can begin. When there are a lot of source codes, in order to avoid the need to copy all the code for a small amount of code, the usual practice is to mount the directory on the development machine to the compiler machine or use synchronization software to synchronize the changed code to the compiler machine. The first method often clears and deletes directories during compilation, which may cause the code on the development machine to be accidentally deleted; the second method requires additional steps and some systems are inconvenient or unable to install synchronization software. This requires a synchronization method that can quickly synchronize the source code to the compiler machine and prevent it from being accidentally deleted. Summary of the invention
[0003] In order to overcome the deficiencies of the above-mentioned prior art, the purpose of the present invention is to provide a script-synchronized program compilation method, device, equipment and storage medium. By mounting the source code on the compiler machine in read-only mode, using a script to copy the changed code to the compilation directory, and compiling, the code can be synchronized quickly and will not be accidentally deleted, thus overcoming the defects of the prior art of accidental deletion of source code and the need to rely on additional synchronization software.
[0004] To achieve the above object, the present invention proposes a script synchronization program compilation method, comprising the following steps: Mount the source code directory of the development machine to the compiler in read-only mode; Set the directory, which includes the directory to be synchronized and the compilation directory; Use a script to copy the changed code in the directory that needs to be synchronized to the compilation directory; In response to the copying being completed, the compilation script is called to start compilation.
[0005] Preferably, the step of using a script to copy the changed code in the directory to be synchronized to the compilation directory comprises the following steps: Use the script to traverse the directory that needs to be synchronized to determine whether the original file is updated; In response to the original file being updated, the original file is copied to the compilation directory.
[0006] Preferably, the step of using a script to traverse the directory to be synchronized and determining whether the original file is updated comprises the following steps: Use a script to traverse the directory that needs to be synchronized, obtain the update time of the original file, and obtain the update time of the file in the same position as the original file in the compiled directory; The update time of the original file is compared with the update time of the file at the same position in the compilation directory. If the update time of the original file is later, it means that the original file has been updated.
[0007] Preferably, the step of using a script to traverse the directory to be synchronized and determine whether the original file is updated also includes the following steps: In response to obtaining the update time of the file in the same position in the compilation directory, determining whether there is a file in the same position as the original file in the compilation directory; If there is no file in the compiled directory at the same position as the original file, the update time of the file in the compiled directory at the same position is set to the oldest time.
[0008] To achieve the above object, the present invention also provides a script synchronization program compilation device, comprising: The mount module is used to mount the source code directory of the development machine to the compiler in a read-only manner; A directory module is used to set directories, including directories that need to be synchronized and compilation directories; A synchronization module, used to copy the changed code in the directory to be synchronized to the compilation directory using a script; The compiling module is used to call the compiling script to start compiling in response to the copying completion.
[0009] Preferably, the synchronization module includes: An update determination module, used to use a script to traverse the directory to be synchronized and determine whether the original file is updated; The file copy module is used for copying the original file to the compilation directory in response to the original file being updated.
[0010] Preferably, the update determination module includes: A file time acquisition module, used to use a script to traverse the directory to be synchronized, obtain the update time of the original file, and obtain the update time of the file in the same position as the original file in the compiled directory; The update time comparison module is used to compare the update time of the original file with the update time of the file at the same position in the compilation directory. If the update time of the original file is later, it means that the original file has been updated.
[0011] Preferably, the update determination module further includes: A compilation file determination module, configured to determine whether there is a file in the same position as the original file in the compilation directory in response to obtaining an update time of the file in the same position in the compilation directory; The oldest time setting module is used to set the update time of the file in the same position in the compilation directory to the oldest time if there is no file in the same position as the original file in the compilation directory.
[0012] To achieve the above object, the present invention also provides a script synchronization program compilation device, comprising: one or more processors; A storage device is used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement any one of the program compilation methods.
[0013] To achieve the above object, the present invention further provides a storage medium on which a computer program is stored, and when the program is executed by a processor, any one of the program compilation methods is implemented.
[0014] Compared with the prior art, an embodiment disclosed in the present invention has the beneficial effect that, by mounting the source code on the compiler in read-only mode, using a script to copy the changed code to the compilation directory, and then starting compilation, the present invention can quickly synchronize the code without accidentally deleting it, and does not require the installation and use of tool software, thereby improving the convenience of program compilation; the present invention only needs to use shell commands to complete, thereby improving the cross-platform nature of the synchronization method; the present invention only copies changed files, thereby further improving the efficiency of compilation. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 A flowchart of the steps of a script synchronization program compilation method disclosed in the present invention; Figure 2 A program flow chart of a script synchronization program compilation method disclosed in the present invention; Figure 3 This is a structural framework diagram of a script-synchronized program compiling device disclosed in the present invention. DETAILED DESCRIPTION
[0016] The following describes the implementation of the present invention through specific examples and in conjunction with the accompanying drawings. Those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific examples, and the details in this specification can also be modified and changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention.
[0017] Figure 1The following is a flowchart of the steps of a script synchronization program compilation method disclosed in the present invention. Figure 1 As shown, a script synchronization program compilation method disclosed in the present invention includes the following steps: Step S101, mounting the source code directory of the development machine to the compiler in a read-only manner; Step S102, setting a directory, the directory including a directory to be synchronized and a compilation directory; Step S103, using a script to copy the changed code in the directory to be synchronized to the compilation directory; Step S104, in response to the copying being completed, calling the compilation script to start compilation.
[0018] Specifically, the development machine refers to a machine for writing source code; the compiler refers to a machine for compiling source code into an executable program; and the mounting refers to mounting a remote device (usually a storage device) to an existing directory. In addition, the script is a shell script, and a program composed of shell commands written by a user is a shell script, wherein the shell refers to the main interface between the operating system and the outside, and the shell interprets the commands input by the user and sends them to the kernel. In other words, the present invention can be completed by using only shell commands, and does not require the installation and use of tool software, thereby improving the cross-platform nature of the synchronization method.
[0019] Preferably, step S103 includes the following steps: Use the script to traverse the directory that needs to be synchronized to determine whether the original file is updated; In response to the original file being updated, the original file is copied to the compilation directory.
[0020] Preferably, the step of using a script to traverse the directory to be synchronized and determining whether the original file is updated comprises the following steps: Use a script to traverse the directory that needs to be synchronized, obtain the update time of the original file, and obtain the update time of the file in the same position as the original file in the compiled directory; The update time of the original file is compared with the update time of the file at the same position in the compilation directory. If the update time of the original file is later, it means that the original file has been updated.
[0021] Preferably, the step of using a script to traverse the directory to be synchronized and determine whether the original file is updated also includes the following steps: In response to obtaining the update time of the file in the same position in the compilation directory, determining whether there is a file in the same position as the original file in the compilation directory; If there is no file in the compiled directory at the same position as the original file, the update time of the file in the compiled directory at the same position is set to the oldest time.
[0022] Figure 2 This is a program flow chart of a script synchronization program compilation method disclosed in the present invention, refer to Figure 2 , an embodiment disclosed by the present invention comprises the following steps: Step S201, mounting the source code directory of the development machine to the compilation machine in read-only mode; Step S202, setting the directory and compilation directory to be synchronized; Step S203, using a script to traverse the directories that need to be synchronized; Step S204, obtaining the original file update time; Step S205, obtaining the update time of the file at the same location in the compilation directory, and if the file does not exist, setting it to the oldest time; Step S206, comparing the two times in step S204 and step S205, if the original file is updated, copy the file to the compilation directory; Step S207, traversal ends; Step S208, calling the compilation script to start compilation.
[0023] It should be noted that steps S201 to S208 are not indicated in the drawings.
[0024] The present invention also discloses a specific embodiment, which is an application of the present invention in actual development. In this specific embodiment, the development machine is Windows, the compiler machine is Linux, and the source code synchronization compilation process is specifically as follows: (1) Mount the development directory under Windows system to Linux . / mnt / src in read-only mode; (2) Set the development directory to . / mnt / src and the compilation directory to . / compile / src; (3) Traverse the development directory; (4) Get the update date of the . / mnt / src / src1.c file; (5) Get the update date of the . / compile / src / src1.c file; (6) Compare the two update dates in step (4) and step (5); (7) If the update is in the development directory, copy the file to the same location as comilie / src; (8) The traversal ends; (9) Call the compilation script to compile.
[0025] Figure 3 The following is a program flow chart of a script synchronization program compilation method disclosed in the present invention. Figure 3 As shown, the present invention discloses a script synchronization program compilation device, comprising: The mounting module 31 is used to mount the source code directory of the development machine to the compiler in a read-only manner; A directory module 32, used to set a directory, which includes a directory to be synchronized and a compilation directory; A synchronization module 33, used to copy the changed code in the directory to be synchronized to the compilation directory using a script; The compiling module 34 is used to call the compiling script to start compiling in response to the copying being completed.
[0026] Specifically, the development machine refers to a machine for writing source code; the compiler machine refers to a machine for compiling source code into an executable program; and the mounting refers to mounting a remote device (usually a storage device) to an existing directory. In addition, the script is a shell script, and a program composed of shell commands written by a user is a shell script, wherein Shell refers to the main interface between the operating system and the outside, and the shell interprets the commands input by the user and sends them to the kernel. In other words, the present invention can be completed by using only shell commands, and does not require the installation and use of tool software, thereby improving the cross-platform nature of the synchronization method.
[0027] Preferably, the synchronization module 33 includes: An update determination module 331 is used to use a script to traverse the directory that needs to be synchronized to determine whether the original file is updated; The file copy module 332 is used to copy the original file to the compilation directory in response to the original file being updated.
[0028] Preferably, the update determination module 331 includes: The file time acquisition module 3311 is used to use a script to traverse the directory to be synchronized, obtain the update time of the original file, and obtain the update time of the file in the same position as the original file in the compiled directory; The update time comparison module 3312 is used to compare the update time of the original file with the update time of the file at the same position in the compilation directory. If the update time of the original file is later, it means that the original file has been updated.
[0029] Preferably, the update determination module 331 further includes: A compiled file determination module 3313, configured to determine whether there is a file in the compiled directory at the same position as the original file in response to obtaining an update time of the file in the same position in the compiled directory; The oldest time setting module 3314 is used to set the update time of the file in the same position as the original file in the compilation directory to the oldest time if there is no file in the same position as the original file in the compilation directory.
[0030] It should be noted that module 3311 to module 3314 are not marked in the drawings.
[0031] It should be pointed out that this device corresponds to the above-mentioned script synchronization program compilation method. For other undescribed parts, please refer to the corresponding content in the method, which will not be repeated here.
[0032] An embodiment of the present invention further discloses a script synchronization program compilation device, comprising: one or more processors; A storage device is used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement any one of the above-mentioned program compilation methods.
[0033] An embodiment of the present invention further discloses a storage medium on which a computer program is stored. When the program is executed by a processor, any one of the above-mentioned program compilation methods is implemented.
[0034] In summary, the present invention provides a script-synchronized program compilation method, device, equipment and storage medium, which mounts the source code on the compiler in read-only mode, uses a script to copy the changed code to the compilation directory, and then starts compiling; avoids the situation of accidental deletion of source code, and does not need to install and use tool software, thereby improving the convenience of program compilation; only needs to use shell commands to complete it, thereby improving the cross-platform nature of the synchronization method; only changes are copied, thereby improving the efficiency of program compilation.
[0035] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0036] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Any person skilled in the art may modify and alter the above embodiments without violating the spirit and scope of the present invention. Therefore, the scope of protection of the present invention shall be as set forth in the claims.
Claims
1. A script synchronization program compilation method, comprising the following steps: Mount the source code directory of the development machine to the compiler in read-only mode; Set the directory, which includes the directory to be synchronized and the compilation directory; Use a script to copy the changed code in the directory that needs to be synchronized to the compilation directory; In response to the copying being completed, the compilation script is called to start compilation.
2. A script-synchronous program compiling method as claimed in claim 1, characterized in that: The use of a script to copy the changed code in the directory to be synchronized to the compilation directory includes the following steps: Use the script to traverse the directory that needs to be synchronized to determine whether the original file is updated; In response to the original file being updated, the original file is copied to the compilation directory.
3. A script-synchronous program compiling method as claimed in claim 2, characterized in that: The script is used to traverse the directory to be synchronized to determine whether the original file is updated, including the following steps: Use a script to traverse the directory that needs to be synchronized, obtain the update time of the original file, and obtain the update time of the file in the same position as the original file in the compiled directory; The update time of the original file is compared with the update time of the file at the same position in the compilation directory. If the update time of the original file is later, it means that the original file has been updated.
4. A script-synchronous program compiling method as claimed in claim 3, characterized in that: The script is used to traverse the directory to be synchronized to determine whether the original file is updated, and the following steps are also included: In response to obtaining the update time of the file in the same position in the compilation directory, determining whether there is a file in the same position as the original file in the compilation directory; If there is no file in the compiled directory at the same position as the original file, the update time of the file in the compiled directory at the same position is set to the oldest time.
5. A script-synchronized program compilation device, comprising: The mount module is used to mount the source code directory of the development machine to the compiler in a read-only manner; A directory module is used to set directories, including directories that need to be synchronized and compilation directories; A synchronization module, used to copy the changed code in the directory to be synchronized to the compilation directory using a script; The compiling module is used to call the compiling script to start compiling in response to the copying completion.
6. A script-synchronized program compiling device as claimed in claim 5, characterized in that: The synchronization module comprises: An update determination module, used to use a script to traverse the directory to be synchronized and determine whether the original file is updated; The file copy module is used for copying the original file to the compilation directory in response to the original file being updated.
7. A script-synchronized program compiling device as claimed in claim 6, characterized in that: The update determination module comprises: A file time acquisition module, used to use a script to traverse the directory to be synchronized, obtain the update time of the original file, and obtain the update time of the file in the same position as the original file in the compiled directory; The update time comparison module is used to compare the update time of the original file with the update time of the file at the same position in the compilation directory. If the update time of the original file is later, it means that the original file has been updated.
8. A script-synchronized program compiling device as claimed in claim 7, characterized in that: The update determination module also includes: A compilation file determination module, configured to determine whether there is a file in the same position as the original file in the compilation directory in response to obtaining an update time of the file in the same position in the compilation directory; The oldest time setting module is used to set the update time of the file in the same position in the compilation directory to the oldest time if there is no file in the same position as the original file in the compilation directory.
9. A script-synchronized program compilation device, comprising: one or more processors; A storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 4.
10. A storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.