Skip to content

Commit

Permalink
feat: add cleanup script for musl-libc
Browse files Browse the repository at this point in the history
Signed-off-by: Yiyang Wu <[email protected]>
  • Loading branch information
ToolmanP committed Oct 2, 2024
1 parent 65cc9eb commit 2587f5c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Lab3/user/chcore-libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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
Expand All @@ -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})
60 changes: 60 additions & 0 deletions Lab3/user/chcore-libc/libchcore/cmake/do_cleanup.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2587f5c

Please sign in to comment.