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 = [[businessCodeCpp] 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/arkui/napi:ace_napi", 34 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", 35 ] 36 remove_configs = [ "//build/config/compiler:no_rtti" ] 37 cflags=[ 38 ] 39 cflags_cc=[ 40 "-frtti", 41 ] 42 ldflags = [ 43 ] 44 45 relative_install_dir = "module" 46 part_name = "[partName]" 47 subsystem_name = "[subsystemName]" 48} 49` 50 51/**创建nodejs编译文件,用于在ubuntu测试 */ 52function generateGN(destDir, implName, license, partName, buildCpp) { 53 let subsystemName = implName; 54 let gnFile = gnTemplete.replaceAll("[implName]", implName); 55 gnFile = gnFile.replaceAll("[businessCodeCpp]", buildCpp) 56 gnFile = gnFile.replaceAll("[subsystemName]", subsystemName); 57 gnFile = gnFile.replaceAll("[partName]", partName); 58 if (license) { 59 let s2 = license.substring(2, license.length - 2).split("\n"); 60 license = ""; 61 for (let i = 1; i < s2.length; i++) { 62 if (s2[i].length > 0) { 63 while (s2[i][0] == " ") s2[i] = s2[i].substring(1); 64 if (s2[i].length > 3 && s2[i][0] == "*") { 65 license += "#" + s2[i].substring(1) + "\n"; 66 } 67 } 68 } 69 } 70 writeFile(re.pathJoin(destDir, "BUILD.gn"), null != license ? (license + "\n" + gnFile) : gnFile) 71} 72 73module.exports = { 74 generateGN 75}