Macro script record used by xmake plug-in

2016/06/20 09:10
Reading number 248

Xmake provides some built-in practical plug-ins, among which the macro script plug-in is the most representative and practical, and it is also a plug-in recommended by xmake. What are its functions?

Let's first look at: xmake macro --help

 Usage: xmake macro|m [options] [name] [arguments] Run the given macro. Options:  --backtrace                         Print backtrace information for debugging. --version                           Print the version number and exit. -h, --help                              Print this help message and exit. -F FILE, --file=FILE                    Read a given xmake.lua file. -P PROJECT, --project=PROJECT           Change to the given project directory. Search priority: 1. The Given Command Argument 2. The Envirnoment Variable: XMAKE_PROJECT_DIR 3. The Current Directory -v, --verbose                           Print lots of verbose information. -b, --begin                             Start to record macro. .e.g Record macro with name: test xmake macro --begin xmake config --plat=macosx xmake clean xmake -r xmake package xmake macro --end test -e, --end                               Stop to record macro. --show                              Show the content of the given macro. -l, --list                             List all macros. -d, --delete                            Delete the given macro. -c, --clear                             Clear the all macros. --import=IMPORT                     Import the given macro file or directory. .e.g xmake macro --import=/xxx/macro.lua test xmake macro --import=/xxx/macrodir --export=EXPORT                     Export the given macro to file or directory. .e.g xmake macro --export=/xxx/macro.lua test xmake macro --export=/xxx/macrodir name                                   Set the macro name. (default: .) .e.g Run the given macro:     xmake macro test Run the anonymous macro: xmake macro . arguments ...                          Set the macro arguments.

See the help menu description. It provides some functions:

  1. Manually record and play back multiple executed xmake commands
  2. Support fast anonymous macro creation and playback
  3. Support long-term recording and reuse of named macros
  4. Support the batch import and export of macro scripts
  5. Support macro script deletion, display and other management functions
  6. Support user-defined advanced macro script and parameter configuration

There are many functions. What scenarios is this macro script mainly used for, such as:

We need to compile and package all the architecture libraries of each platform

 xmake f -p android --ndk=/xxx/ndk -a armv7-a xmake p xmake f -p mingw --sdk=/mingwsdk xmake p xmake f -p linux --sdk=/toolsdk --toolchains=/xxxx/bin xmake p xmake f -p iphoneos -a armv7 xmake p xmake f -p iphoneos -a arm64 xmake p xmake f -p iphoneos -a armv7s xmake p xmake f -p iphoneos -a i386 xmake p xmake f -p iphoneos -a x86_64 xmake p

It's quite tiring, and these commands may need to be executed repeatedly. It's tiring to knock them out every time. If there are more and more complex configuration parameters like cross compilation, it will be more tiring

At this time, macro scripts need to appear, and after these macros are recorded, you can export them for others to use, without having to ask them how to configure and compile each time

Less gossip, let's first look at how to record a simple macro script..

 #Start recording macros xmake macro --begin #Execute some xmake commands xmake f -p android --ndk=/xxx/ndk -a armv7-a xmake p xmake f -p mingw --sdk=/mingwsdk xmake p xmake f -p linux --sdk=/toolsdk --toolchains=/xxxx/bin xmake p xmake f -p iphoneos -a armv7 xmake p xmake f -p iphoneos -a arm64 xmake p xmake f -p iphoneos -a armv7s xmake p xmake f -p iphoneos -a i386 xmake p xmake f -p iphoneos -a x86_64 xmake p #End macro recording. The macro name is not set here, so it is an anonymous macro xmake macro --end

Ok, let's play back and execute this macro..

 #Last Anonymous Macro Recorded Previously xmake macro .

The advantage of anonymous macros is that they can be recorded and played back quickly. If you want to save them for a long time, you need to give them a name. It is also very simple:

 --End recording and name it as test macro xmake macro --end test --Play back the test macro xmake macro test

Macro management: deletion, import and export are relatively simple. You can click: xmake macro --help See for yourself

Let's look at the content recorded by the macro script: xmake macro --show test

 function main() os.exec("xmake f -p android --ndk=/xxx/ndk -a armv7-a") os.exec("xmake p") os.exec("xmake f -p mingw --sdk=/mingwsdk") os.exec("xmake p") os.exec("xmake f -p linux --sdk=/toolsdk --toolchains=/xxxx/bin") os.exec("xmake p") os.exec("xmake f -p iphoneos -a armv7") os.exec("xmake p") os.exec("xmake f -p iphoneos -a arm64") os.exec("xmake p") os.exec("xmake f -p iphoneos -a armv7s") os.exec("xmake p") os.exec("xmake f -p iphoneos -a i386") os.exec("xmake p") os.exec("xmake f -p iphoneos -a x86_64") os.exec("xmake p")   end

It is actually a lua script, in which you can use all the class libraries and built-in apis used in plug-in development. You can import them through import and write some advanced macro scripts..

For more advanced macro script writing methods, please refer to: Batch packaging for plug-ins


Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
zero Collection
zero fabulous
 Back to top
Top