From 5f764b2999bbe01924b711edb102a4b1cc286d94 Mon Sep 17 00:00:00 2001 From: Devon Frind Date: Wed, 4 Oct 2023 05:36:13 +0000 Subject: [PATCH 1/8] Add clean build script and task --- .vscode/tasks.json | 10 ++++++++++ scripts/clean_build.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 scripts/clean_build.sh diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4f901fb..3685a44 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -25,6 +25,16 @@ "problemMatcher": [], "group": "build" }, + { + "label": "Clean Build", + "detail": "Restore the source tree to a pristine state and remove all generated files", + "type": "shell", + "command": "./clean_build.sh", + "options": { + "cwd": "${env:WORKSPACE_DIR}/scripts" + }, + "problemMatcher": [] + }, { "label": "Run Kernel", "detail": "Run the OS161 kernel", diff --git a/scripts/clean_build.sh b/scripts/clean_build.sh new file mode 100755 index 0000000..f8cb7fe --- /dev/null +++ b/scripts/clean_build.sh @@ -0,0 +1,33 @@ +#/bin/bash + +# Removes all generated files +prev_dir=$(pwd) + +# Clean src directory +if [[ -d ${OS161_SRC} ]]; then + echo "Cleaning src directory" + cd ${OS161_SRC} + bmake clean + bmake distclean +else + echo "Cannot clean ${OS161_SRC}. It does not exist." +fi + +# Clean kern/compile directories +compile_directory=${OS161_SRC}/kern/compile +if [[ -d ${compile_directory} ]]; then + cd ${compile_directory} + kernel_directories=$(ls -d *) + + for subdir in ${kernel_directories}; do + echo "Cleaning ${subdir}" + cd ${compile_directory}/${subdir} + bmake clean + done +else + echo "Cannot clean ${compile_directory}. It does not exist." +fi + +cd ${prev_dir} + +echo "Clean done!" From 088b338d6780e4df75c32ab0b6d1ed47374fa08e Mon Sep 17 00:00:00 2001 From: Devon Frind Date: Wed, 4 Oct 2023 06:35:11 +0000 Subject: [PATCH 2/8] Add build scripts --- scripts/build.sh | 3 ++ scripts/build_helpers/compile_userland.sh | 14 ++++++++++ .../configure_and_compile_kernel.sh | 28 +++++++++++++++++++ scripts/build_helpers/configure_os_tree.sh | 24 ++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100755 scripts/build.sh create mode 100755 scripts/build_helpers/compile_userland.sh create mode 100755 scripts/build_helpers/configure_and_compile_kernel.sh create mode 100755 scripts/build_helpers/configure_os_tree.sh diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..cb61272 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,3 @@ +#/bin/bash + + diff --git a/scripts/build_helpers/compile_userland.sh b/scripts/build_helpers/compile_userland.sh new file mode 100755 index 0000000..98a9f21 --- /dev/null +++ b/scripts/build_helpers/compile_userland.sh @@ -0,0 +1,14 @@ +#/bin/bash + +# Compiles userland +prev_dir=$(pwd) +if [[ -d ${OS161_SRC} ]]; then + cd ${OS161_SRC} + bmake -j$(nproc) + bmake install +else + echo "Cannot compile userland because ${OS161_SRC} does not exist." +fi + +cd ${prev_dir} +echo "Done compiling userland" diff --git a/scripts/build_helpers/configure_and_compile_kernel.sh b/scripts/build_helpers/configure_and_compile_kernel.sh new file mode 100755 index 0000000..6ccae5e --- /dev/null +++ b/scripts/build_helpers/configure_and_compile_kernel.sh @@ -0,0 +1,28 @@ +#/bin/bash + +# Configures a kernel +# Accepts one argument: The kernel to configure. Can be one of: +# DUMBVM, DUMBVM-OPT, GENERIC, GENERIC-OPT, SYNCHPROBS +kernel=$1 +prev_dir=$(pwd) +kernel_conf_dir=${OS161_SRC}/kern/conf +kernel_dir=${OS161_SRC}/kern/compile/${kernel} + +if [[ -d ${kernel_conf_dir} && ! -z ${kernel} ]]; then + cd ${kernel_conf_dir} + ./config ${kernel} +else + echo "Cannot configure kernel ${kernel} because ${kernel_dir} does not exist." +fi + +if [[ -d ${kernel_dir} && ! -z ${kernel} ]]; then + cd ${kernel_dir} + bmake depend + bmake -j$(nproc) + bmake install +else + echo "Cannot compile kernel ${kernel} because ${kernel_dir} does not exist." +fi + +cd ${prev_dir} +echo "Done configuring the kernel" diff --git a/scripts/build_helpers/configure_os_tree.sh b/scripts/build_helpers/configure_os_tree.sh new file mode 100755 index 0000000..81d351f --- /dev/null +++ b/scripts/build_helpers/configure_os_tree.sh @@ -0,0 +1,24 @@ +#/bin/bash + +# Configures the OS tree +# Accepts one optional argument: The absolute path to the os tree +ostree_path=$1 +default_ostree_path=${WORKSPACE_DIR}/os161/root + +prev_dir=$(pwd) + +# If first argument empty, set to default path +if [[ -z ${ostree_path} ]]; then + ostree_path=${default_ostree_path} +fi + +# Set the ostree path +if [[ -d ${OS161_SRC} ]]; then + cd ${OS161_SRC} + ./configure --ostree=${ostree_path} +else + echo "Cannot configure os tree because ${OS161_SRC} does not exist." +fi + +cd ${prev_dir} +echo "Done configuring OS tree path" From 9ad28a70713c106183ae9bac7c6711eb4fd81107 Mon Sep 17 00:00:00 2001 From: Devon Frind Date: Wed, 4 Oct 2023 20:38:11 +0000 Subject: [PATCH 3/8] Add help messages and CLI arguments to build helpers --- scripts/build_helpers/compile_userland.sh | 15 +++++++- .../configure_and_compile_kernel.sh | 34 ++++++++++++++++--- scripts/build_helpers/configure_os_tree.sh | 26 ++++++++++++-- 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/scripts/build_helpers/compile_userland.sh b/scripts/build_helpers/compile_userland.sh index 98a9f21..2db4470 100755 --- a/scripts/build_helpers/compile_userland.sh +++ b/scripts/build_helpers/compile_userland.sh @@ -1,6 +1,19 @@ #/bin/bash -# Compiles userland +function helpMessage() { + echo "Usage: ./compile_userland.sh" + echo "Compile userland" +} + +# Grab CLI arguments +while getopts ":h" flag; do + case ${flag} in + h) helpMessage; exit 0 ;; + \?) echo "Invalid option: -${OPTARG}"; helpMessage; exit 1 ;; + *) echo "Unhandled option: -${OPTARG}"; helpMessage; exit 1 ;; + esac +done + prev_dir=$(pwd) if [[ -d ${OS161_SRC} ]]; then cd ${OS161_SRC} diff --git a/scripts/build_helpers/configure_and_compile_kernel.sh b/scripts/build_helpers/configure_and_compile_kernel.sh index 6ccae5e..09b94c0 100755 --- a/scripts/build_helpers/configure_and_compile_kernel.sh +++ b/scripts/build_helpers/configure_and_compile_kernel.sh @@ -1,9 +1,35 @@ #/bin/bash -# Configures a kernel -# Accepts one argument: The kernel to configure. Can be one of: -# DUMBVM, DUMBVM-OPT, GENERIC, GENERIC-OPT, SYNCHPROBS -kernel=$1 +function helpMessage() { + echo "Usage: ./configure_and_compile_kernel.sh [OPTIONS]..." + echo "Configures and compiles a kernel" + echo "Example: ./configure_and_compile_kernel.sh -k DUMBVM" + echo "" + echo "Options" + echo -e "\t-k: The kernel to configure and compile. Must be one of:" \ + "DUMBVM, DUMBVM-OPT, GENERIC, GENERIC-OPT, SYNCHPROBS" + echo -e "\t-h: Display this message" +} + +kernel="" + +# Grab CLI arguments +while getopts ":hk:" flag; do + case ${flag} in + h) helpMessage; exit 0 ;; + k) kernel=${OPTARG} ;; + \?) echo "Invalid option: -${OPTARG}"; helpMessage; exit 1 ;; + *) echo "Unhandled option: -${OPTARG}"; helpMessage; exit 1 ;; + esac +done + +# Assert that the kernel argument is non-empty +if [[ -z ${kernel} ]]; then + echo "ERROR: Option -k is missing or argument value is empty" + helpMessage + exit 1 +fi + prev_dir=$(pwd) kernel_conf_dir=${OS161_SRC}/kern/conf kernel_dir=${OS161_SRC}/kern/compile/${kernel} diff --git a/scripts/build_helpers/configure_os_tree.sh b/scripts/build_helpers/configure_os_tree.sh index 81d351f..4efe1be 100755 --- a/scripts/build_helpers/configure_os_tree.sh +++ b/scripts/build_helpers/configure_os_tree.sh @@ -1,10 +1,30 @@ #/bin/bash -# Configures the OS tree -# Accepts one optional argument: The absolute path to the os tree -ostree_path=$1 +# Most of the devcontainer is configured to use the "default" directory, +# so it's advised to not change it unless you really want to change it +function helpMessage() { + echo "Usage: ./configure_os_tree.sh [OPTIONS]..." + echo "Configures the OS Tree" + echo "Example: ./configure_os_tree.sh -p /workspace/os161/root" + echo "" + echo "Options" + echo -e "\t-p: The absolute path to the OS tree (optional). Default: ${WORKSPACE_DIR}/os161/root" + echo -e "\t-h: Display this message" +} + +ostree_path="" default_ostree_path=${WORKSPACE_DIR}/os161/root +# Grab CLI arguments +while getopts ":hp" flag; do + case ${flag} in + h) helpMessage; exit 0 ;; + p) ostree_path=${OPTARG} ;; + \?) echo "Invalid option: -${OPTARG}"; helpMessage; exit 1 ;; + *) echo "Unhandled option: -${OPTARG}"; helpMessage; exit 1 ;; + esac +done + prev_dir=$(pwd) # If first argument empty, set to default path From 431bebe9932283c4469dc6bbb4413da75b54a207 Mon Sep 17 00:00:00 2001 From: Devon Frind Date: Wed, 4 Oct 2023 20:52:45 +0000 Subject: [PATCH 4/8] Implement full build script --- scripts/build.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/scripts/build.sh b/scripts/build.sh index cb61272..8b5e439 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,3 +1,40 @@ #/bin/bash +function helpMessage() { + echo "Usage: ./build.sh [OPTIONS]..." + echo "Builds OS161" + echo "Example: ./build.sh -k DUMBVM" + echo "" + echo "Options" + echo -e "\t-k: The kernel to configure and compile. Must be one of:" \ + "DUMBVM, DUMBVM-OPT, GENERIC, GENERIC-OPT, SYNCHPROBS" + echo -e "\t-p: The absolute path to the OS tree (optional). Default: ${WORKSPACE_DIR}/os161/root" + echo -e "\t-h: Display this message" +} +ostree_path="" +kernel="" + +default_ostree_path=${WORKSPACE_DIR}/os161/root + +# Grab CLI arguments +while getopts ":hk:p" flag; do + case ${flag} in + h) helpMessage; exit 0 ;; + k) kernel=${OPTARG} ;; + p) ostree_path=${OPTARG} ;; + \?) echo "Invalid option: -${OPTARG}"; helpMessage; exit 1 ;; + *) echo "Unhandled option: -${OPTARG}"; helpMessage; exit 1 ;; + esac +done + +# If os tree path is empty, set to default path +if [[ -z ${ostree_path} ]]; then + ostree_path=${default_ostree_path} +fi + +# Perform the build process +scripts_directory=${WORKSPACE_DIR}/scripts +bash ${scripts_directory}/build_helpers/configure_os_tree.sh -p ${ostree_path} +bash ${scripts_directory}/build_helpers/compile_userland.sh +bash ${scripts_directory}/build_helpers/configure_and_compile_kernel.sh -k ${kernel} From 236f533e814ad002f633c3b64aeadb36abedb722 Mon Sep 17 00:00:00 2001 From: Devon Frind Date: Wed, 4 Oct 2023 21:07:31 +0000 Subject: [PATCH 5/8] Tweak argument configurations --- scripts/build.sh | 4 +++- scripts/build_helpers/configure_and_compile_kernel.sh | 2 +- scripts/build_helpers/configure_os_tree.sh | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 8b5e439..f5c546e 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -18,7 +18,7 @@ kernel="" default_ostree_path=${WORKSPACE_DIR}/os161/root # Grab CLI arguments -while getopts ":hk:p" flag; do +while getopts ":hk:p:" flag; do case ${flag} in h) helpMessage; exit 0 ;; k) kernel=${OPTARG} ;; @@ -38,3 +38,5 @@ scripts_directory=${WORKSPACE_DIR}/scripts bash ${scripts_directory}/build_helpers/configure_os_tree.sh -p ${ostree_path} bash ${scripts_directory}/build_helpers/compile_userland.sh bash ${scripts_directory}/build_helpers/configure_and_compile_kernel.sh -k ${kernel} + +echo "Build done" diff --git a/scripts/build_helpers/configure_and_compile_kernel.sh b/scripts/build_helpers/configure_and_compile_kernel.sh index 09b94c0..a1f9bb5 100755 --- a/scripts/build_helpers/configure_and_compile_kernel.sh +++ b/scripts/build_helpers/configure_and_compile_kernel.sh @@ -51,4 +51,4 @@ else fi cd ${prev_dir} -echo "Done configuring the kernel" +echo "Done configuring and compiling the kernel" diff --git a/scripts/build_helpers/configure_os_tree.sh b/scripts/build_helpers/configure_os_tree.sh index 4efe1be..bdc7753 100755 --- a/scripts/build_helpers/configure_os_tree.sh +++ b/scripts/build_helpers/configure_os_tree.sh @@ -16,7 +16,7 @@ ostree_path="" default_ostree_path=${WORKSPACE_DIR}/os161/root # Grab CLI arguments -while getopts ":hp" flag; do +while getopts ":hp:" flag; do case ${flag} in h) helpMessage; exit 0 ;; p) ostree_path=${OPTARG} ;; From 6a78a699a6d90005ee13d02bd0d41a9c017f34fd Mon Sep 17 00:00:00 2001 From: Devon Frind Date: Wed, 4 Oct 2023 21:08:43 +0000 Subject: [PATCH 6/8] Update VS Code tasks to use new build scripts when possible --- .vscode/tasks.json | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3685a44..c93d01a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -13,15 +13,12 @@ }, { "label": "Build", - "detail": "Does a full build of the OS161 kernel", + "detail": "Does a full build of OS161", "type": "shell", - "dependsOrder": "sequence", - "dependsOn":[ - "Configure OS Tree", - "Compile Userland", - "Configure Kernel", - "Compile Kernel" - ], + "command": "./build.sh -p ${input:tree_path} -k ${input:kernel}", + "options": { + "cwd": "${env:WORKSPACE_DIR}/scripts" + }, "problemMatcher": [], "group": "build" }, @@ -49,39 +46,29 @@ "label": "Configure OS Tree", "detail": "Configures the OS tree with the provided path", "type": "shell", - "command": "./configure --ostree=${input:tree_path}", + "command": "./configure_os_tree.sh -p ${input:tree_path}", "options": { - "cwd": "${env:WORKSPACE_DIR}/os161/src", + "cwd": "${env:WORKSPACE_DIR}/scripts/build_helpers", }, "problemMatcher": [], }, { "label": "Compile Userland", "detail": "Compiles userland in src/", - "command": "bmake && bmake install", + "command": "./compile_userland.sh", "type": "shell", "options": { - "cwd": "${env:WORKSPACE_DIR}/os161/src", + "cwd": "${env:WORKSPACE_DIR}/scripts/build_helpers", }, "problemMatcher": [], }, { - "label": "Configure Kernel", - "detail": "Configures the type of kernel to be compiled", - "command": "./config ${input:kernel}", - "type": "shell", - "options": { - "cwd": "${env:WORKSPACE_DIR}/os161/src/kern/conf" - }, - "problemMatcher": [] - }, - { - "label": "Compile Kernel", - "detail": "Compile the kernel with the configured type", - "command": "bmake depend && bmake && bmake install", + "label": "Configure and Compile Kernel", + "detail": "Configure and compile a specified kernel", + "command": "./configure_and_compile_kernel.sh -k ${input:kernel}", "type": "shell", "options": { - "cwd": "${env:WORKSPACE_DIR}/os161/src/kern/compile/${input:kernel}", + "cwd": "${env:WORKSPACE_DIR}/scripts/build_helpers", }, "problemMatcher": [] }, From d8e678194abd464d86d16d68da09d9cfb6cf7275 Mon Sep 17 00:00:00 2001 From: Devon Frind Date: Wed, 4 Oct 2023 21:10:30 +0000 Subject: [PATCH 7/8] Update echo statements in setup script --- scripts/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index edbcb01..f905d10 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -17,7 +17,7 @@ function install() { } if [[ -d $OS161_DEPENDENCIES_DIR/tools ]]; then - echo "${OS161_DEPENDENCIES_DIR}/tools already exists. Delete the tools directory " + \ + echo "${OS161_DEPENDENCIES_DIR}/tools already exists. Delete the tools directory" \ "if rebuilding is desired. Skipping build..." else install From 1d77f51ebe12b92fe35549d4fad367396958967e Mon Sep 17 00:00:00 2001 From: Devon Frind Date: Wed, 4 Oct 2023 21:17:50 +0000 Subject: [PATCH 8/8] Check for valid kernel in the build script --- scripts/build.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/build.sh b/scripts/build.sh index f5c546e..dbfe65b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -28,6 +28,13 @@ while getopts ":hk:p:" flag; do esac done +# Assert that the kernel argument is non-empty +if [[ -z ${kernel} ]]; then + echo "ERROR: Option -k is missing or argument value is empty" + helpMessage + exit 1 +fi + # If os tree path is empty, set to default path if [[ -z ${ostree_path} ]]; then ostree_path=${default_ostree_path}