1/* 2 * Copyright (c) 2025 Huawei Device 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 */ 15 16const fs = require('fs'); 17const path = require('path'); 18 19const projectRoot = path.join(__dirname, '..', '..'); 20const buildDir = path.join(projectRoot, 'build'); 21const coverageDir = path.join(projectRoot, 'coverage'); 22const buildInstrumentDir = path.join(coverageDir, 'build_instrument'); 23 24function copyDirectory(src, dest) { 25 fs.mkdirSync(dest, { recursive: true }); 26 27 const entries = fs.readdirSync(src, { withFileTypes: true }); 28 29 for (const entry of entries) { 30 const srcPath = path.join(src, entry.name); 31 const destPath = path.join(dest, entry.name); 32 33 if (entry.isDirectory()) { 34 copyDirectory(srcPath, destPath); 35 } else { 36 fs.copyFileSync(srcPath, destPath); 37 } 38 } 39} 40 41function prepareCoverage() { 42 try { 43 if (fs.existsSync(coverageDir)) { 44 fs.rmSync(coverageDir, { recursive: true, force: true }); 45 } 46 47 fs.mkdirSync(coverageDir, { recursive: true }); 48 fs.mkdirSync(buildInstrumentDir, { recursive: true }); 49 50 copyDirectory(buildDir, buildInstrumentDir); 51 52 const dataDir = path.join(projectRoot, 'src', 'data'); 53 const instrumentDataDir = path.join(buildInstrumentDir, 'data'); 54 55 if (fs.existsSync(dataDir)) { 56 copyDirectory(dataDir, instrumentDataDir); 57 } 58 } catch (error) { 59 console.error('Error during coverage preparation:', error); 60 process.exit(1); 61 } 62} 63 64prepareCoverage();