CN114416057A - Project code packaging method and device, terminal equipment and storage medium - Google Patents

Project code packaging method and device, terminal equipment and storage medium Download PDF

Info

Publication number
CN114416057A
CN114416057A CN202210059385.3A CN202210059385A CN114416057A CN 114416057 A CN114416057 A CN 114416057A CN 202210059385 A CN202210059385 A CN 202210059385A CN 114416057 A CN114416057 A CN 114416057A
Authority
CN
China
Prior art keywords
variable
statement
import
party library
variables
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210059385.3A
Other languages
Chinese (zh)
Inventor
徐俊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Pingan Payment Technology Service Co Ltd
Original Assignee
Pingan Payment Technology Service Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Pingan Payment Technology Service Co Ltd filed Critical Pingan Payment Technology Service Co Ltd
Priority to CN202210059385.3A priority Critical patent/CN114416057A/en
Publication of CN114416057A publication Critical patent/CN114416057A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The application is applicable to the technical field of software development, and provides a project code packaging method, a project code packaging device and terminal equipment, wherein the method comprises the following steps: traversing all codes of the third party library, and determining a dependency mapping path of a target variable of the third party library so as to store the dependency mapping path of the target variable of the third party library in a configuration file of the third party library; when a project code packing instruction is received, traversing all import statements in a project, and determining import variables existing in the project; carrying out address replacement processing on the imported variable according to the configuration file of the third-party library; the project codes subjected to address replacement processing are packaged, only files of the imported variables containing the variables in the third-party library are packaged into the projects, the redundancy of the projects can be reduced, directories do not need to be created according to specified rules when the codes of the third-party library are compiled, and the coding difficulty is effectively reduced.

Description

Project code packaging method and device, terminal equipment and storage medium
Technical Field
The application belongs to the technical field of software development, and particularly relates to a project code packaging method and device, a terminal device and a computer readable storage medium.
Background
In the process of daily software project development, with the improvement of functional complexity and the development of framework technology, the completion of a project depends on the reference of a third-party library more and more. In the process of packaging the software project codes, the third-party library is usually required to be packaged together, so that redundant codes are packaged into the project, the project file is too large, and the access speed of a user and the system performance are affected.
The existing project code packaging method provides a method for loading a third-party library as required, but the method needs a developer to specify a detailed address of an introduced variable when writing a code, so that the developer needs to be very clear of a directory corresponding to a third-party library export function, the development efficiency is low, and the like, and the problems of reference error and the like are caused by the change of a reference path after the third-party library is iterated. The existing method also provides a method for loading and packaging a third-party library as required through a specific packaging optimization plug-in of the third-party library, however, the method can only map the path under a single incoming directory, cannot process the path replacement under a nested directory, and meanwhile, when the third-party library is developed, the directory needs to be created according to the rule of the packaging optimization plug-in, so that the encoding difficulty is increased.
In summary, the existing method for loading the third-party library on demand has the problems of low development efficiency, easy reference error, poor adaptability and high coding difficulty.
Disclosure of Invention
The embodiment of the application provides a project code packaging method, a project code packaging device, a terminal device and a computer readable storage medium, and can solve the problems that the existing method for loading a third-party library on demand is low in development efficiency, easy to cause reference errors, poor in adaptability and high in coding difficulty.
In a first aspect, an embodiment of the present application provides a project code packaging method, including:
traversing all codes of a third party library, determining a dependency mapping path of a target variable of the third party library, and storing the dependency mapping path of the target variable of the third party library in a configuration file of the third party library;
when a project code packing instruction is received, traversing all import statements in a project, and determining import variables existing in the project;
carrying out address replacement processing on the imported variable according to the configuration file of the third-party library;
and packaging the item codes subjected to the address replacement processing.
In an implementation manner of the first aspect, the traversing all codes of the third party library, and determining a dependency mapping path of a target variable of the third party library, so as to store the dependency mapping path of the target variable of the third party library in a configuration file of the third party library, includes:
traversing all codes in the third-party library to determine an abstract syntax tree corresponding to the third-party library;
classifying and collecting all variables of the third party library according to the abstract syntax tree to obtain an import statement variable set, a type definition statement variable set and an export statement variable set;
determining a target variable according to the import statement variable set, the type definition statement variable set and the export statement variable set;
and acquiring a dependency mapping path of the target variable.
In an implementation manner of the first aspect, the determining a target variable according to the import statement variable set, the type definition statement variable set, and the export statement variable set includes:
traversing variables in the import statement variable set, and judging whether variables with the same names as the variables in the import statement variable set exist in the export statement variable set or not;
if the variable with the same name as the variable in the import statement variable set exists in the export statement variable set, acquiring a path of the variable, and judging whether the path of the variable in the import statement is consistent with the path of the variable in the export statement or not;
if the path of the variable in the import statement is consistent with the path of the variable in the export statement, deleting the variable from the export statement variable set;
traversing variables in the type definition statement variable set, and judging whether variables with the same names as the variables in the type definition statement variable set exist in the derived statement variable set or not;
if the variable with the same name as the variable in the type definition statement variable set exists in the derived statement variable set, acquiring a path of the variable, and judging whether the path of the variable in the type definition statement is consistent with the path of the variable in the derived statement or not;
and if the path of the variable in the type definition statement is consistent with the path of the variable in the derivation statement, deleting the variable from the derivation statement variable set.
In an implementation manner of the first aspect, when a plurality of third party libraries are referred to in a project development process, the traversing all codes of the third party libraries to determine a dependency mapping path of a target variable of the third party libraries, so as to store the dependency mapping path of the target variable of the third party libraries in a configuration file of the third party libraries includes:
and when the third-party library is loaded, automatically executing the dependency collection command and generating the configuration file of the loaded third-party library.
In an implementation manner of the first aspect, traversing all import statements in a project and determining an import variable existing in the project when receiving a project code packaging instruction includes:
traversing all codes in the project, and identifying an import statement of which the reference path is the library name of the third-party library;
and identifying variables in the import statement to obtain the import variables.
In an implementation manner of the first aspect, traversing all import statements in a project and determining an import variable existing in the project when receiving a project code packaging instruction includes:
determining the library names of all third-party libraries referenced by the item;
respectively identifying import sentences with reference paths as the library names of the third-party libraries;
and identifying variables in the import statement to obtain the import variables.
In an implementation manner of the first aspect, the performing, according to the configuration file of the third party library, address replacement processing on the import variable includes:
determining a dependency mapping address corresponding to the import variable according to the configuration file;
and replacing the original address of the import variable in the item with the dependency mapping address corresponding to the import variable.
In a second aspect, an embodiment of the present application provides an item code packaging apparatus, including:
the dependency determining unit is used for traversing all codes of a third party library, determining a dependency mapping path of a target variable of the third party library, and storing the dependency mapping path of the target variable of the third party library in a configuration file of the third party library;
the variable determining unit is used for traversing all import statements in the project and determining the import variables existing in the project when receiving a project code packing instruction;
the address replacement unit is used for carrying out address replacement processing on the import variable according to the configuration file of the third-party library;
and the packing unit is used for packing the item codes subjected to the address replacement processing.
In a third aspect, an embodiment of the present application provides a terminal device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of the item code packaging method according to any one of the above first aspects when executing the computer program.
In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the computer program implements the steps of the item code packaging method according to any one of the above first aspects.
In a fifth aspect, the present application provides a computer program product, which when run on a terminal device, enables the terminal device to execute the item code packaging method according to any one of the above first aspects.
Compared with the prior art, the embodiment of the application has the advantages that:
according to the project code packaging method provided by the embodiment, the whole third-party library is not required to be packaged into a project, only the file of the imported variable containing the variable in the third-party library is required to be packaged into the project, the redundancy of the project can be reduced, the detailed replacement address of the imported variable can be determined only according to the dependent mapping path of the variable in the configuration file, a directory does not need to be created according to the specified rule when the code of the third-party library is written, the coding difficulty is effectively reduced, and the problems that the development efficiency is low, the reference error is easy to occur, the adaptability is poor and the coding difficulty is high in the existing method for loading the third-party library as required are solved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings without creative efforts.
Fig. 1 is a schematic flow chart illustrating an implementation of a project code packaging method according to an embodiment of the present application;
fig. 2 is a schematic diagram of a specific implementation flow of S11 in the project code packaging method according to an embodiment of the present application;
fig. 3 is a schematic diagram of a specific implementation flow of S13 in the project code packaging method according to an embodiment of the present application;
FIG. 4 is a schematic structural diagram of an item code packaging apparatus according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of a terminal device according to an embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It should also be understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
As used in this specification and the appended claims, the term "if" may be interpreted contextually as "when", "upon" or "in response to" determining "or" in response to detecting ". Similarly, the phrase "if it is determined" or "if a [ described condition or event ] is detected" may be interpreted contextually to mean "upon determining" or "in response to determining" or "upon detecting [ described condition or event ]" or "in response to detecting [ described condition or event ]".
Furthermore, in the description of the present application and the appended claims, the terms "first," "second," "third," and the like are used for distinguishing between descriptions and not necessarily for describing or implying relative importance.
Reference throughout this specification to "one embodiment" or "some embodiments," or the like, means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," or the like, in various places throughout this specification are not necessarily all referring to the same embodiment, but rather "one or more but not all embodiments" unless specifically stated otherwise. The terms "comprising," "including," "having," and variations thereof mean "including, but not limited to," unless expressly specified otherwise.
Referring to fig. 1, fig. 1 is a flowchart illustrating an implementation of a project code packaging method according to an embodiment of the present application. In the embodiment of the present application, the execution subject of the item code packaging method may be a device with data processing capability, such as a terminal device or a server. The terminal device can be an electronic device with data processing capability, such as a smart phone, a tablet computer, a desktop computer, and an intelligent wearable device. The server may be a conventional server or a cloud server, which is not limited in this application.
As shown in fig. 1, the project code packaging method provided by an embodiment of the present application may include S11 to S13, which are detailed as follows:
in S11, traversing all the codes of the third-party library, and determining the dependency mapping path of the target variable of the third-party library, so as to store the dependency mapping path of the target variable of the third-party library in the configuration file of the third-party library.
In the embodiment of the present application, the third party library refers to a third party code library cited in a project code development process. When the project code is required to be packaged, the third-party library referred by the project code can be determined through the project code, then all codes of the third-party library are traversed, and a dependency mapping path of a target variable of the third-party library is determined, namely the specific position of a source file containing the target variable in the third-party library is determined.
In a specific application, the source file containing the target variable at a specific position of the third-party library can be represented in the form of a storage path.
In the embodiment of the application, after the dependency mapping path of the target variable is determined, a configuration file is generated, the dependency mapping path of the target variable is stored in the configuration file of the third-party library, and when the project code is packaged, the storage position of the source file containing the target variable can be determined by accessing the configuration file, so that the source file containing the target variable is packaged in the project without specifying a specific file path or requiring a developer to create a directory according to the rule of the package optimization plug-in.
In a specific application, in order to reduce the size of the storage space occupied by the configuration file and improve the read-write efficiency of the configuration file, the configuration file of the third-party library may be stored in a JSON file format.
In the embodiment of the present application, the target variable refers to a variable in a derived statement that exists only in a third-party library.
Since many variables exist in the third-party library, which are not all variables in the export statement, in order to determine the target variable, all variables may be determined from all codes in the third-party library, and it is determined whether the variables exist only in the export statement, if the same variable also exists in the import statement or the type definition statement, when determining the dependency mapping path, the same variable may be exported in different source files, which results in the case that the path is assigned to a non-source file, and redundant packaged codes occur.
Referring to fig. 2, fig. 2 shows a specific implementation flow of S11 in the project code packaging method according to the embodiment of the present application. As shown in fig. 2, in the embodiment of the present application, the step S11 may include the following steps:
s111: traversing all codes in the third-party library to determine an abstract syntax tree corresponding to the third-party library;
s112: classifying and collecting all variables of the third party library according to the abstract syntax tree to obtain an import statement variable set, a type definition statement variable set and an export statement variable set;
s113: determining a target variable according to the import statement variable set, the type definition statement variable set and the export statement variable set;
s114: and acquiring a dependency mapping path of the target variable.
In the embodiment of the application, in order to determine the target variable and avoid packaging errors, the abstract syntax tree corresponding to the third-party library is determined by traversing the third-party library, and then all variables of the third-party library are determined from the abstract syntax data.
It should be noted that an Abstract Syntax Tree (AST), or simply Syntax Tree (Syntax Tree), is an Abstract representation of the Syntax structure of the source code. It represents the syntactic structure of the programming language in the form of a tree, each node on the tree representing a structure in the source code.
In a concrete implementation, the types of various sentences can be determined through the abstract syntax tree, and all variables of a third-party library can be classified and collected.
During concrete implementation, an import statement, an export statement and a type definition statement in a third party library can be determined through an abstract syntax tree, then the import statement, the export statement and the type definition statement are traversed, variables in the import statement, the export statement and the type definition statement are found out, the variables in the import statement are collected into an import statement variable set, the variables in the export statement are collected into an export statement variable set, and the variables in the type definition variable statement are collected into a type definition statement variable set.
In a concrete implementation, when the abstract syntax tree is determined by traversing the code, three preset hook functions can be executed, wherein a first hook function is used for collecting variables in the export statement, a second hook function is used for collecting variables in the import statement, and a third hook function is used for collecting variables in the type definition statement, so that the three collected variable sets are irrelevant.
In a specific implementation, a path corresponding to a variable in each variable set can be directly determined through the hook function, that is, a dependency mapping path of each variable can also be directly obtained. That is, when the first hook function is executed, variables in the derived sentence are collected into a derived sentence variable set, and a dependency mapping path corresponding to each variable in the derived sentence variable set is determined, when the second hook function is executed, variables in the introduced sentence are collected into an introduced sentence variable set, and a dependency mapping path corresponding to each variable in the introduced sentence variable set is determined, and when the third hook function is executed, variables in the type definition sentence are collected into a type definition sentence variable set, and a dependency mapping path corresponding to each variable in the type definition sentence variable set is determined. Therefore, after the target variable is determined, the dependency mapping path of the target variable can be determined.
In an embodiment of the application, the step S113 specifically includes the following steps:
traversing variables in the import statement variable set, and judging whether variables with the same names as the variables in the import statement variable set exist in the export statement variable set or not;
if the variable with the same name as the variable in the import statement variable set exists in the export statement variable set, acquiring a path of the variable, and judging whether the path of the variable in the import statement is consistent with the path of the variable in the export statement or not;
if the path of the variable in the import statement is consistent with the path of the variable in the export statement, deleting the variable from the export statement variable set;
traversing variables in the type definition statement variable set, and judging whether variables with the same names as the variables in the type definition statement variable set exist in the derived statement variable set or not;
if the variable with the same name as the variable in the type definition statement variable set exists in the derived statement variable set, acquiring a path of the variable, and judging whether the path of the variable in the type definition statement is consistent with the path of the variable in the derived statement;
and if the path of the variable in the type definition statement is consistent with the path of the variable in the derivation statement, deleting the variable from the variable set of the derivation statement.
In the embodiment of the present application, in order to avoid a situation that a variable of a source file of another third-party library is imported and the variable is exported, a variable that exists in an export statement and a variable (with the same variable name) in an import statement at the same time in the same path need to be deleted first, so that a generated configuration file does not include a mapping dependency relationship of the variables, and a package error situation can be effectively avoided. For variables in the type definition statement, paths of the variables do not need to be replaced during packaging, packaging errors can be caused by replacement, the variables only define a certain variable and are not actually applied, and in order to avoid packaging errors caused by replacement, the variables also need to be deleted from a derived statement variable set.
And deleting the variables of the two types of variables to obtain the variable set of the derived statement, wherein the variable set is the target variable.
It should be noted that if a variable in the import statement is just the same name as a variable in the export statement, but the path is different, it is stated that the variable is not a variable to be deleted, and therefore the variable is not deleted.
For variables in the type definition statement, if the variables are not in the same path, subsequent code packaging is not influenced, so that if the paths are different, the variables do not need to be deleted.
In an embodiment of the present application, in a case where a plurality of third party libraries are referred to in the project development process, the step S11 may include the following steps:
and when the third-party library is loaded, automatically executing the dependency collection command and generating the configuration file of the loaded third-party library.
In the embodiment of the application, when the third-party library is loaded, the dependency collection command is automatically triggered and executed, so that the dependency mapping path of the target variable in the third-party library is determined, the dependency mapping path is stored in the configuration file, the configuration file of the third-party library can be obtained, and the configuration file of each third-party library can be obtained by executing the dependency collection command on all the third-party libraries quoted by the project.
In a specific application, when a project code is operated, if a third-party library is referred, the third-party library is loaded in the operation process, and at the moment, a dependent collection command is triggered, so that the terminal equipment can automatically execute the dependent collection command and generate a configuration file corresponding to the loaded third-party library. After the terminal device generates the configuration file of the third-party library, the configuration file can be stored in a preset storage position, so that the configuration file is directly called to determine the dependency mapping path of the variable during item packaging.
The dependency collection command is used for triggering the terminal device to traverse all codes of the third-party library, determining a dependency mapping path of the target variable, and generating a configuration file according to the mapping relation between the target variable and the dependency mapping path of the target variable.
In a specific application, different third-party libraries may generate different configuration files, and the configuration files may be named by library names of the third-party libraries, so as to determine a corresponding relationship between the third-party libraries and the configuration files.
In S12, upon receiving the item code packing instruction, all import statements in the item are traversed to determine the import variables present in the item.
In the embodiment of the application, the project code packaging instruction may be initiated by a developer through development software, and the terminal device may automatically execute S12-S14 when receiving the project packaging instruction, so as to package the project code.
In the embodiment of the present application, the imported variable is a variable that refers to a third-party library.
The import statement is a program statement for importing a certain package/variable, for example, an import statement, and includes a dependency of the imported package/variable, that is, which library the imported variable depends on. When writing an import statement, a developer needs to write the library name of the library to which the variable belongs, so that after all import statements in a project are accessed, which variables in the project belong to the third-party library can be determined.
It should be further noted that, in the embodiment, since the dependency mapping address of the target variable in the third-party library is determined by the configuration file, in the process of the project development, if the third-party library needs to be referred to in the process of the project development, only the referred path needs to be uniformly written as the library name of the third-party library, so as to improve the development efficiency, and the specific path of the variable does not need to be specified.
Illustratively, the library name of the third party library is "thirdllibrary", the reference path of the import statement may be collectively written as "thirdllibrary".
In an implementation manner of the present application, the above S12 may include the following steps:
traversing all codes in the project, and identifying an import statement of which the reference path is the library name of the third-party library;
and identifying variables in the import statement to obtain the import variables.
In a specific application, taking the name of the third-party library as "thirdllibrary" as an example, matching a statement with a reference path of "thirdllibrary" by traversing all codes in the item, and acquiring an imported variable name to obtain an imported variable that references the third-party library in the item.
It should be noted that, if a plurality of third-party libraries are introduced in the process of developing a project, the import variables corresponding to the introduced third-party libraries need to be determined respectively.
In an implementation manner of this application, the above S12 may further include:
determining the library names of all third-party libraries referenced by the project;
respectively identifying import sentences with reference paths as the library names of the third-party libraries;
and identifying variables in the import statement to obtain the import variables.
In specific application, the library names of all third-party libraries quoted by a project are determined, then all codes in the project are traversed, the import sentences with the quoted paths being the library names of all third-party libraries are identified, and then variable names of variables in the import sentences are determined, so that the import variables of all third-party libraries can be determined.
In S13: and carrying out address replacement processing on the imported variable according to the configuration file of the third-party library.
In a specific application, the configuration file of the third-party library is used for describing a mapping relationship between a target variable in the third library and a reference path corresponding to the target variable, that is, a dependent mapping path of a variable corresponding to a variable name in the third-party library can be determined according to the variable name, that is, a storage location of a source file containing the variable can be determined.
In a specific application, after the terminal device determines an import variable in a project, in order to effectively package a source file corresponding to the import variable into the project, a specific storage location of the source file of the import variable in the third-party library needs to be determined according to the configuration file in S11.
In specific application, the terminal device determines a configuration file of a third party library corresponding to an imported variable according to the imported variable, then calls the configuration file, determines a storage path of a source file containing the imported variable according to a target variable in the configuration file and a mapping relation of a reference path corresponding to the target variable, and then replaces the reference path (namely, a third party library name) written by an original developer with the storage path of the source file of the imported variable, so as to realize address replacement.
Referring to fig. 3, fig. 3 shows a specific implementation flow of S13 in the code packaging method according to the embodiment of the present application. As shown in fig. 3, in an implementation manner, the step S13 may include the following steps:
s131: determining a dependency mapping address corresponding to an import variable according to a configuration file;
s132: and replacing the original address of the import variable in the item with the dependency mapping address corresponding to the import variable.
In the specific implementation, the dependency mapping address of the import variable, that is, the specific position of the source file containing the import variable in the third-party library, is determined from the configuration file, and then the original third-party library name is replaced by the specific position, so that the address replacement processing is completed.
For example, assuming that the import variable designation 1 is a variable referring to the third-party library thirdllibrary 1, when performing address replacement, the terminal device calls a configuration file corresponding to the third-party library thirdllibrary 1, queries a target variable designation 1 having the same name as the import variable designation 1 from the configuration file, determines a dependency mapping path of the variable 1 based on the mapping relationship, and replaces the original address "thirdllibrary 1" of the import variable designation 1 with "thirdllibrary 1\ Logistic regression \ \1 \.
In S14: and packaging the item codes subjected to the address replacement processing.
In the embodiment of the application, the address of the imported variable is already a detailed address of the imported variable in the third-party library after replacing the address, so that when the project code is packaged, the terminal device can directly package a source file corresponding to the detailed address in the third-party library, and does not package the whole third-party library, so that the size of the packaged file can be reduced, and useless codes are prevented from being input into the project.
It can be seen from the above that, according to the project code packaging method provided by this embodiment, the whole third-party library does not need to be packaged into a project, only the file in which the imported variable includes the variable in the third-party library needs to be packaged into a project, the redundancy of the project can be reduced, the detailed replacement address of the imported variable can be determined only according to the dependency mapping path of the variable in the configuration file, a directory does not need to be created according to the specified rule when the code of the third-party library is written, the encoding difficulty is effectively reduced, and the problems that the existing method for loading the third-party library as required is low in development efficiency, easy to cause reference errors, poor in adaptability and high in encoding difficulty are solved.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
Fig. 4 shows a block diagram of a project code packaging apparatus according to an embodiment of the present application, and for convenience of illustration, only the parts related to the embodiment of the present application are shown. Referring to fig. 4, the item code packaging apparatus 40 includes: a dependency determination unit 41, a variable determination unit 42, an address replacement unit 43, and a packing unit 44. Wherein:
the dependency determining unit 41 is configured to traverse all codes of the third party library, determine a dependency mapping path of a target variable of the third party library, and store the dependency mapping path of the target variable of the third party library in a configuration file of the third party library.
The variable determining unit 42 is configured to, when receiving the item code packing instruction, traverse all the import statements in the item, and determine an import variable existing in the item.
The address replacement unit 43 is configured to perform address replacement processing on the import variable according to the configuration file of the third party library.
The packing unit 44 is configured to pack the item code subjected to the address replacement processing.
In an embodiment of the present application, the dependency determining unit 41 may include an abstract syntax tree determining unit, a classification collecting unit, a target variable determining unit, and a dependency path determining unit. Wherein:
and the abstract syntax tree determining unit is used for traversing all codes in the third-party library and determining the abstract syntax tree corresponding to the third-party library.
And the classification collection unit is used for classifying and collecting all variables of the third-party library according to the abstract syntax tree to obtain an import statement variable set, a type definition statement variable set and an export statement variable set.
The target variable determining unit is used for determining a target variable according to the import statement variable set, the type definition statement variable set and the export statement variable set.
The dependent path determining unit is used for acquiring a dependent mapping path of the target variable.
In an embodiment of the application, the target variable determining unit is specifically configured to traverse variables in an import statement variable set, and determine whether a variable having the same name as a variable in the import statement variable set exists in the export statement variable set; if the variable with the same name as the variable in the import statement variable set exists in the export statement variable set, acquiring a path of the variable, and judging whether the path of the variable in the import statement is consistent with the path of the variable in the export statement or not; if the path of the variable in the import statement is consistent with the path of the variable in the export statement, deleting the variable from the export statement variable set; traversing variables in the type definition statement variable set, and judging whether variables with the same names as the variables in the type definition statement variable set exist in the derived statement variable set or not; if the variable with the same name as the variable in the type definition statement variable set exists in the derived statement variable set, acquiring a path of the variable, and judging whether the path of the variable in the type definition statement is consistent with the path of the variable in the derived statement or not; and if the path of the variable in the type definition statement is consistent with the path of the variable in the derivation statement, deleting the variable from the derivation statement variable set.
In an embodiment of the application, when a plurality of third-party libraries are referred to in a project development process, the dependency determination unit is specifically configured to automatically execute a dependency collection command when the third-party libraries are loaded, and generate a configuration file of the loaded third-party libraries.
In one embodiment of the present application, the variable identification unit 42 includes a first identification unit and a second identification unit. Wherein:
the first identification unit is used for traversing all codes in the item and identifying an import statement of which the reference path is the library name of the third-party library.
The second identification unit is used for identifying the variable in the import statement to obtain the import variable.
In one embodiment of the present application, the variable identifying unit 42 includes a library name determining unit, a third identifying unit, and a fourth identifying unit. Wherein:
the library name determining unit is used for determining the library names of all the third-party libraries referenced by the project.
The third identification unit is used for respectively identifying the import sentences of which the reference paths are the library names of the third-party libraries;
and the fourth identification unit is used for identifying the variable in the import statement to obtain the import variable.
In an embodiment of the present application, the address replacing unit 43 includes: an address determination unit and a replacement unit. Wherein:
and the address determining unit is used for determining a dependency mapping address corresponding to the import variable according to the configuration file.
And the replacing unit is used for replacing the original address of the import variable in the item with the dependency mapping address corresponding to the import variable.
It can be seen from the above that, according to the project code packaging apparatus provided in the embodiment of the present application, it is also not necessary to package the entire third-party library into a project, and it is only necessary to package a file, which contains an imported variable in the third-party library, into a project, so that the redundancy of the project can be reduced, and it is only necessary to determine a detailed replacement address of the imported variable according to a dependency mapping path of the variable in a configuration file, and it is also not necessary to create a directory according to a specified rule when writing a code of the third-party library, so that the encoding difficulty is effectively reduced, and the problems of low development efficiency, easy occurrence of a reference error, poor adaptability, and high encoding difficulty in the existing method of loading the third-party library as required are solved.
Fig. 5 is a schematic structural diagram of a terminal device according to an embodiment of the present application. As shown in fig. 5, the terminal device 5 of this embodiment includes: at least one processor 50 (only one is shown in fig. 5), a memory 51, and a computer program 52 stored in the memory 51 and executable on the at least one processor 50, wherein the processor 50 implements the steps of any one of the above-mentioned embodiments of the item code packing method when executing the computer program 52.
Those skilled in the art will appreciate that fig. 5 is only an example of the terminal device 5, and does not constitute a limitation to the terminal device 5, and may include more or less components than those shown, or combine some components, or different components, such as an input-output device, a network access device, and the like.
The Processor 50 may be a Central Processing Unit (CPU), and the Processor 50 may be other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, a discrete hardware component, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 51 may in some embodiments be an internal storage unit of the terminal device 5, such as a hard disk or a memory of the terminal device 5. The memory 51 may also be an external storage device of the terminal device 5 in other embodiments, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the terminal device 5. Further, the memory 51 may also include both an internal storage unit and an external storage device of the terminal device 5. The memory 51 is used for storing an operating system, an application program, a BootLoader (BootLoader), data, and other programs, such as program codes of the computer program. The memory 51 may also be used to temporarily store data that has been output or is to be output.
An embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the steps in any one of the above embodiments of the item code packaging method can be implemented.
The embodiments of the present application provide a computer program product, which when running on a terminal device, enables the terminal device to implement the steps in any one of the above embodiments of the project code packaging method when executed.
It should be noted that, for the information interaction, execution process, and other contents between the above-mentioned devices/units, the specific functions and technical effects thereof are based on the same concept as those of the embodiment of the method of the present application, and specific reference may be made to the part of the embodiment of the method, which is not described herein again.
An embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the steps in any one of the above embodiments of the item code packaging method can be implemented.
The embodiment of the present application provides a computer program product, which when running on a terminal device, enables the terminal device to implement the steps in any one of the above embodiments of the project code packaging method when executed.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one first processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method for packaging item codes can be implemented in other ways. For example, the above-described embodiments of the apparatus/terminal device are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.

Claims (10)

1. A method for packaging item codes, comprising:
traversing all codes of a third party library, determining a dependency mapping path of a target variable of the third party library, and storing the dependency mapping path of the target variable of the third party library in a configuration file of the third party library;
when a project code packing instruction is received, traversing all import statements in a project, and determining import variables existing in the project;
carrying out address replacement processing on the imported variable according to the configuration file of the third-party library;
and packaging the item codes subjected to the address replacement processing.
2. The project code packaging method of claim 1, wherein traversing all codes of a third party library, determining a dependency mapping path of a target variable of the third party library, so as to save the dependency mapping path of the target variable of the third party library in a configuration file of the third party library, comprises:
traversing all codes in the third-party library to determine an abstract syntax tree corresponding to the third-party library;
classifying and collecting all variables of the third party library according to the abstract syntax tree to obtain an import statement variable set, a type definition statement variable set and an export statement variable set;
determining a target variable according to the import statement variable set, the type definition statement variable set and the export statement variable set;
and acquiring a dependency mapping path of the target variable.
3. The item code packing method of claim 2, wherein said determining a target variable from the set of import statement variables, the set of type definition statement variables, and the set of export statement variables comprises:
traversing variables in the import statement variable set, and judging whether variables with the same names as the variables in the import statement variable set exist in the export statement variable set or not;
if the variable with the same name as the variable in the import statement variable set exists in the export statement variable set, acquiring a path of the variable, and judging whether the path of the variable in the import statement is consistent with the path of the variable in the export statement or not;
if the path of the variable in the import statement is consistent with the path of the variable in the export statement, deleting the variable from the export statement variable set;
traversing variables in the type definition statement variable set, and judging whether variables with the same names as the variables in the type definition statement variable set exist in the derived statement variable set or not;
if the variable with the same name as the variable in the type definition statement variable set exists in the derived statement variable set, acquiring a path of the variable, and judging whether the path of the variable in the type definition statement is consistent with the path of the variable in the derived statement or not;
and if the path of the variable in the type definition statement is consistent with the path of the variable in the derivation statement, deleting the variable from the derivation statement variable set.
4. The project code packaging method of claim 1, wherein when a plurality of third party libraries are referred to in a project development process, the traversing all codes of the third party libraries to determine the dependency mapping path of the target variable of the third party libraries, so as to store the dependency mapping path of the target variable of the third party libraries in the configuration file of the third party libraries comprises:
and when the third-party library is loaded, automatically executing the dependency collection command and generating the configuration file of the loaded third-party library.
5. The item code packaging method of claim 1, wherein the traversing all import statements in an item and determining the import variables present in the item upon receiving an item code packaging instruction comprises:
traversing all codes in the project, and identifying an import statement of which the reference path is the library name of the third-party library;
and identifying variables in the import statement to obtain the import variables.
6. The item code packaging method of claim 1, wherein the traversing all import statements in an item and determining the import variables present in the item upon receiving an item code packaging instruction comprises:
determining the library names of all third-party libraries referenced by the item;
respectively identifying import sentences with reference paths as the library names of the third-party libraries;
and identifying variables in the import statement to obtain the import variables.
7. The item code packaging method of claim 1, wherein the address replacement processing of the import variable according to the configuration file of the third-party library comprises:
determining a dependency mapping address corresponding to the import variable according to the configuration file;
and replacing the original address of the import variable in the item with the dependency mapping address corresponding to the import variable.
8. An item code packaging apparatus, comprising:
the dependency determining unit is used for traversing all codes of a third party library, determining a dependency mapping path of a target variable of the third party library, and storing the dependency mapping path of the target variable of the third party library in a configuration file of the third party library;
the variable determining unit is used for traversing all import statements in the project and determining the import variables existing in the project when receiving a project code packing instruction;
the address replacement unit is used for carrying out address replacement processing on the import variable according to the configuration file of the third-party library;
and the packing unit is used for packing the item codes subjected to the address replacement processing.
9. A terminal device comprising a memory, a processor and a computer program stored in said memory and executable on said processor, characterized in that said processor implements the steps of the item code packaging method according to any one of claims 1 to 7 when executing said computer program.
10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the item code packaging method according to any one of claims 1 to 7.
CN202210059385.3A 2022-01-19 2022-01-19 Project code packaging method and device, terminal equipment and storage medium Pending CN114416057A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210059385.3A CN114416057A (en) 2022-01-19 2022-01-19 Project code packaging method and device, terminal equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210059385.3A CN114416057A (en) 2022-01-19 2022-01-19 Project code packaging method and device, terminal equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114416057A true CN114416057A (en) 2022-04-29

Family

ID=81274031

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210059385.3A Pending CN114416057A (en) 2022-01-19 2022-01-19 Project code packaging method and device, terminal equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114416057A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114816369A (en) * 2022-06-29 2022-07-29 广州易方信息科技股份有限公司 Method and device for safely cutting third-party library supported by Android terminal

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114816369A (en) * 2022-06-29 2022-07-29 广州易方信息科技股份有限公司 Method and device for safely cutting third-party library supported by Android terminal
CN114816369B (en) * 2022-06-29 2022-10-04 易方信息科技股份有限公司 Method and device for safely cutting third-party library supported by Android terminal

Similar Documents

Publication Publication Date Title
US5146593A (en) Procedure call interface
US9043757B2 (en) Identifying differences between source codes of different versions of a software when each source code is organized using incorporated files
CN111176717B (en) Method and device for generating installation package and electronic equipment
CN112597153A (en) Data storage method and device based on block chain and storage medium
CN111124872A (en) Branch detection method and device based on difference code analysis and storage medium
CN114327776A (en) Debugging method, debugging equipment and debugging system for intelligent contract
CN114138281A (en) Compiling method, device, equipment and medium of software engineering
US10839124B1 (en) Interactive compilation of software to a hardware language to satisfy formal verification constraints
CN114416057A (en) Project code packaging method and device, terminal equipment and storage medium
CN111159301A (en) Data creating method, device, equipment and storage medium based on intelligent contract
CN113987337A (en) Search method, system, equipment and storage medium based on componentized dynamic arrangement
CN111694992A (en) Data processing method and device
US9064042B2 (en) Instrumenting computer program code by merging template and target code methods
CN114816772B (en) Debugging method, debugging system and computing device for application running based on compatible layer
CN109409037B (en) Method, device and equipment for generating data confusion rule
CN111352631A (en) Interface compatibility detection method and device
CN117312420A (en) Data sharing method and related system
CN113760237A (en) Compiling address updating method and device, terminal equipment and readable storage medium
CN117234466B (en) Enterprise management software development method, system, equipment and storage medium
CN118193032B (en) Method, apparatus, device, medium and program product for eliminating invalid dependency library
CN113495727B (en) Business component development method, device, electronic equipment and medium
CN116700841B (en) Method and device for calling native API (application program interface)
CN112445491B (en) File sequence processing method, device, terminal equipment and storage medium
CN116028027A (en) Code format standardization method, device, electronic equipment and storage medium
CN113704289A (en) Method, system, equipment and medium based on DBIO interface

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination