plugin_development.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>xmake</title>
  6. <link rel="icon" href="/assets/img/favicon.ico">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  8. <meta name="description" content="Description">
  9. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  10. <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
  11. <style>
  12. .markdown-body {
  13. box-sizing: border-box;
  14. min-width: 200px;
  15. max-width: 980px;
  16. margin: 0 auto;
  17. padding: 45px;
  18. }
  19. @media (max-width: 767px) {
  20. .markdown-body {
  21. padding: 15px;
  22. }
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <article class="markdown-body">
  28. <h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/plugin/plugin_development">https://xmake.io/#/plugin/plugin_development</a>
  29. </br>
  30. <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
  31. <style>
  32. #carbonads {
  33. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  34. Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
  35. }
  36. #carbonads {
  37. display: flex;
  38. max-width: 330px;
  39. background-color: hsl(0, 0%, 98%);
  40. box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
  41. }
  42. #carbonads a {
  43. color: inherit;
  44. text-decoration: none;
  45. }
  46. #carbonads a:hover {
  47. color: inherit;
  48. }
  49. #carbonads span {
  50. position: relative;
  51. display: block;
  52. overflow: hidden;
  53. }
  54. #carbonads .carbon-wrap {
  55. display: flex;
  56. }
  57. .carbon-img {
  58. display: block;
  59. margin: 0;
  60. line-height: 1;
  61. }
  62. .carbon-img img {
  63. display: block;
  64. }
  65. .carbon-text {
  66. font-size: 13px;
  67. padding: 10px;
  68. line-height: 1.5;
  69. text-align: left;
  70. }
  71. .carbon-poweredby {
  72. display: block;
  73. padding: 8px 10px;
  74. background: repeating-linear-gradient(-45deg, transparent, transparent 5px, hsla(0, 0%, 0%, .025) 5px, hsla(0, 0%, 0%, .025) 10px) hsla(203, 11%, 95%, .4);
  75. text-align: center;
  76. text-transform: uppercase;
  77. letter-spacing: .5px;
  78. font-weight: 600;
  79. font-size: 9px;
  80. line-height: 1;
  81. }
  82. </style>
  83. <h2 id="introduction">Introduction</h2>
  84. <p>XMake supports the plugin module and we can develop ourself plugin module conveniently.</p>
  85. <p>We can run command <code>xmake -h</code> to look over some builtin plugins of xmake</p>
  86. <pre><code>Plugins:
  87. l, lua Run the lua script.
  88. m, macro Run the given macro.
  89. doxygen Generate the doxygen document.
  90. hello Hello xmake!
  91. project Create the project file.
  92. </code></pre><ul>
  93. <li>lua: Run a given lua script.</li>
  94. <li>macro: Record and playback some xmake commands repeatably.</li>
  95. <li>doxygen:Generate doxygen document automatically.</li>
  96. <li>hello: The demo plugin and only print: &#39;hello xmake!&#39;</li>
  97. <li>project:Generate project file for IDE, and now it can generate make, cmake, vs, xcode (need cmake), ninja project file and compile_commands.json and compile_flags.txt</li>
  98. </ul>
  99. <h2 id="quickstart">Quick Start</h2>
  100. <p>Now we write a simple plugin demo for printing &#39;hello xmake!&#39;</p>
  101. <pre><code class="lang-lua">-- define a plugin task
  102. task("hello")
  103. -- set the category for showing it in plugin category menu (optional)
  104. set_category("plugin")
  105. -- the main entry of the plugin
  106. on_run(function ()
  107. -- print &#39;hello xmake!&#39;
  108. print("hello xmake!")
  109. end)
  110. -- set the menu options, but we put empty options now.
  111. set_menu {
  112. -- usage
  113. usage = "xmake hello [options]"
  114. -- description
  115. , description = "Hello xmake!"
  116. -- options
  117. , options = {}
  118. }
  119. </code></pre>
  120. <p>The file tree of this plugin:</p>
  121. <pre><code>plugins
  122. |-- hello
  123. | |-- xmake.lua
  124. |...
  125. | notice no xmake.lua in plugins directory
  126. </code></pre><p>Now one of the most simple plugin finished, how was it to be xmake detected it, there are three ways:</p>
  127. <ol>
  128. <li>Put this plugin directory into xmake/plugins the source codes as the builtin plugin.</li>
  129. <li>Put this plugin directory into ~/.xmake/plugins as the global user plugin.</li>
  130. <li>Put this plugin directory (hello) to the <code>./plugins</code> directory of the current project and call <code>add_plugindirs("plugins")</code> in xmake.lua as the local project plugin.</li>
  131. </ol>
  132. <h2 id="runplugin">Run Plugin</h2>
  133. <p>Next we run this plugin</p>
  134. <pre><code class="lang-bash">xmake hello
  135. </code></pre>
  136. <p>The results is </p>
  137. <pre><code>hello xmake!
  138. </code></pre><p>Finally, we can also run this plugin in the custom scripts of <code>xmake.lua</code></p>
  139. <pre><code class="lang-lua">
  140. target("demo")
  141. -- run this plugin after building target
  142. after_build(function (target)
  143. -- import task module
  144. import("core.project.task")
  145. -- run the plugin task
  146. task.run("hello")
  147. end)
  148. </code></pre>
  149. </article>
  150. </body>
  151. </html>