From 78e5c225440a1dbac511d22f1dec39fa51702e6d Mon Sep 17 00:00:00 2001
From: dam1n19 <dam1n19@soton.ac.uk>
Date: Fri, 28 Apr 2023 11:10:16 +0100
Subject: [PATCH] SOC1-169: Added basic cleaning functionality to socsim

---
 flow/socsim | 43 +++++++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/flow/socsim b/flow/socsim
index a2f4372..194c887 100755
--- a/flow/socsim
+++ b/flow/socsim
@@ -6,19 +6,42 @@
 #
 # David Mapstone (d.a.mapstone@soton.ac.uk)
 #
-# Copyright  2022, SoC Labs (www.soclabs.org)
+# Copyright 2023, SoC Labs (www.soclabs.org)
 #-----------------------------------------------------------------------------
 
 #!/usr/bin/env bash
 
-DEFAULT_SIMULATOR="ivlog"
-if [[ -z "${SIMULATOR}" ]]; then 
-    SIMULATOR=$DEFAULT_SIMULATOR
-fi
-# $PROJECT_DIR"/flow/simulators/"$SIMULATOR"_sim.sh" $@
+# Check arguments passed to SoCSim
+if [ $# -eq 0 ]
+  then
+    echo "No arguments supplied"
+else 
 
-# Find a simulation script in the SoCSim environments of all subrepos
-simscript=$(find ${SOCSIM_PATH//:/\ } -name "${1}.sh")
+    # If clean command passed in clean a specific directory or all
+    if [ ${1} == "clean" ]; then
+        if [ $# -eq 1 ];  then
+            echo "No clean arguments supplied"
+        else
+            if [ ${2} == "all" ]; then
+                # Clean all simualation directories
+                echo "Cleaning all Project Simulation Directories"
+                rm -rf $PROJECT_DIR/simulate/sim
+                mkdir -p $PROJECT_DIR/simulate/sim
+            else
+                # Remove specific simulaiton directory
+                SIM_DIR=$PROJECT_DIR/simulate/sim/${2}
+                if [ -d "$SIM_DIR" ]; then
+                    rm -rf $SIM_DIR
+                else 
+                    echo "Simulation Directory '${2}' doesn't exist"
+                fi
+            fi
+        fi
+    fi
 
-# Run Script if Found
-$simscript $@
\ No newline at end of file
+    # Find a simulation script in the SoCSim environments of all subrepos
+    simscript=$(find ${SOCSIM_PATH//:/\ } -name "${1}.sh")
+
+    # Run Script if Found
+    $simscript $@
+fi
\ No newline at end of file
-- 
GitLab