• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15const { writeFile } = require('../tools/FileRW');
16const re = require('../tools/re');
17
18let gypTemplete = `
19{
20    "targets": [
21        {
22          "target_name": "[implName]",
23          "sources": [[businessCodeCpp]
24              "./[implName].cpp",
25              "./[implName]_middle.cpp",
26              "./tool_utility.cpp"],
27          "include_dirs": ["."],
28          "cflags_cc": [ "-frtti","-std=c++17" ]
29        }
30    ]
31}
32`;
33
34/**创建nodejs编译文件,用于在ubuntu测试 */
35function generateGYP(destDir, implName, license, bindingCpp) {
36    let ss = gypTemplete.replaceAll('[implName]', implName);
37    ss = ss.replaceAll('[businessCodeCpp]', bindingCpp);
38    if (license) {
39        let s2 = license.substring(2, license.length - 2).split('\n');
40        license = '';
41        for (let i = 1; i < s2.length; i++) {
42            license = getLicense(s2, i, license);
43        }
44    }
45    writeFile(re.pathJoin(destDir, 'binding.gyp'), (null !== license && undefined !== license) ?
46      (license + '\n' + ss) : ss);
47
48    writeFile(re.pathJoin(destDir, 'test.sh'), 'node-gyp configure build && sleep 0.5 && node --expose-gc test.js');
49
50}
51
52function getLicense(s2, i, license) {
53  if (s2[i].length > 0) {
54    while (s2[i][0] === ' ')
55    {
56      s2[i] = s2[i].substring(1);
57    }
58    if (s2[i].length > 3 && s2[i][0] === '*') {
59      license += '#' + s2[i].substring(1) + '\n';
60    }
61  }
62  return license;
63}
64
65module.exports = {
66  generateGYP
67};