From 2587f5c8c7b5c85ad10de7562ae9a4583f48df5d Mon Sep 17 00:00:00 2001 From: Yiyang Wu Date: Wed, 2 Oct 2024 16:07:51 +0800 Subject: [PATCH] feat: add cleanup script for musl-libc Signed-off-by: Yiyang Wu --- Lab3/user/chcore-libc/CMakeLists.txt | 9 ++- .../chcore-libc/libchcore/cmake/do_cleanup.sh | 60 +++++++++++++++++++ 2 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 Lab3/user/chcore-libc/libchcore/cmake/do_cleanup.sh diff --git a/Lab3/user/chcore-libc/CMakeLists.txt b/Lab3/user/chcore-libc/CMakeLists.txt index 9ef562d9..8d8a6a81 100644 --- a/Lab3/user/chcore-libc/CMakeLists.txt +++ b/Lab3/user/chcore-libc/CMakeLists.txt @@ -74,6 +74,7 @@ set(_libc_target_dir ${CMAKE_CURRENT_SOURCE_DIR}/musl-libc) set(_libchcore_porting_dir ${CMAKE_CURRENT_SOURCE_DIR}/libchcore/porting) set(_libchcore_overrides_dir ${_libchcore_porting_dir}/overrides) set(_libchcore_patches_dir ${_libchcore_porting_dir}/patches) +set(_libchcore_cleanup_script ${CMAKE_CURRENT_SOURCE_DIR}/libchcore/cmake/do_cleanup.sh) do_overrides(${_libchcore_overrides_dir} ${_libc_target_dir}) do_patches(${_libchcore_patches_dir} ${_libc_target_dir}) @@ -94,7 +95,7 @@ add_custom_target(libc-configure ALL # Compile libc add_custom_target(libc-build ALL WORKING_DIRECTORY ${_libc_target_dir} - COMMAND bear make -j${nproc} || make -j${_nproc} + COMMAND make -j${_nproc} DEPENDS libc-configure) # Install libc as usual @@ -105,7 +106,5 @@ add_custom_target(libc-install ALL # clean target add_custom_target(libc-clean - WORKING_DIRECTORY ${_libc_target_dir} - COMMAND git clean -fdx || : - COMMAND git reset --hard HEAD || : - COMMAND make clean) + COMMAND make -C ${_libc_target_dir} clean + COMMAND bash ${_libchcore_cleanup_script} ${_libc_target_dir}) diff --git a/Lab3/user/chcore-libc/libchcore/cmake/do_cleanup.sh b/Lab3/user/chcore-libc/libchcore/cmake/do_cleanup.sh new file mode 100644 index 00000000..f022ce21 --- /dev/null +++ b/Lab3/user/chcore-libc/libchcore/cmake/do_cleanup.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU) +# Licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. + +set -e + +self=$(basename "$0") + +function usage { + echo "Usage: $self [target_absolute_path]" + exit 1 +} + +if [ "$#" -ne 1 ]; then + usage +fi + +if [[ $1 != /* ]]; then + usage +fi + +target=$1 + +# Cleaning up is based on mirror structure of the original backups. +# We recursively iterate over each subdirectories and files under $target, for each file, check whether it's a symlink. If it's a symlink, then delete it and check whether its backup file exists. +# For remaining backup files, we recover it without cleaning up the symlink. + +function traverse { + for file in "$1"/*; do + if [[ -d "$file" ]]; then + if [[ -L "$file" ]]; then + rm "$file" + echo "--- Cleanup ${file} symlink" + else + traverse "$file" + fi + elif [[ -f "$file" && "$file" != *.bak ]]; then + if [[ -L "$file" ]]; then + rm "$file" + echo "--- Cleanup ${file} symlink" + fi + if [[ -f "$file.bak" ]]; then + mv "$file.bak" "$file" + echo "--- Recover ${file}" + fi + elif [[ -f "$file" && "$file" == *.bak ]]; then + mv $file ${file%.bak} + echo "--- Recover ${file}" + fi + done +} + +traverse $target