• 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 gnTemplete = `\
19import("//build/ohos.gni")
20
21ohos_shared_library("[implName]")
22{
23    sources = [
24        "[implName]_middle.cpp",
25        "[implName].cpp",
26        "tool_utility.cpp",
27    ]
28    include_dirs = [
29        ".",
30        "//third_party/node/src",
31    ]
32    deps=[
33        "//foundation/ace/napi:ace_napi",
34    ]
35    remove_configs = [ "//build/config/compiler:no_rtti" ]
36    cflags=[
37    ]
38    cflags_cc=[
39        "-frtti",
40    ]
41    ldflags = [
42    ]
43
44    relative_install_dir = "module"
45    part_name = "[partName]"
46    subsystem_name = "[subsystemName]"
47}
48`
49
50/**创建nodejs编译文件,用于在ubuntu测试 */
51function generateGN(destDir, implName, license, partName) {
52    let subsystemName = implName;
53    let gnFile = gnTemplete.replaceAll("[implName]", implName);
54    gnFile = gnFile.replaceAll("[subsystemName]", subsystemName);
55    gnFile = gnFile.replaceAll("[partName]", partName);
56    if (license) {
57        let s2 = license.substring(2, license.length - 2).split("\n");
58        license = "";
59        for (let i = 1; i < s2.length; i++) {
60            if (s2[i].length > 0) {
61                while (s2[i][0] == " ") s2[i] = s2[i].substring(1);
62                if (s2[i].length > 3 && s2[i][0] == "*") {
63                    license += "#" + s2[i].substring(1) + "\n";
64                }
65            }
66        }
67    }
68    writeFile(re.pathJoin(destDir, "BUILD.gn"), null != license ? (license + "\n" + gnFile) : gnFile)
69}
70
71module.exports = {
72    generateGN
73}