Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,25 @@
},
{
"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"
},
{
"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",
Expand All @@ -39,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": []
},
Expand Down
49 changes: 49 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#/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

# 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}
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}

echo "Build done"
27 changes: 27 additions & 0 deletions scripts/build_helpers/compile_userland.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#/bin/bash

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}
bmake -j$(nproc)
bmake install
else
echo "Cannot compile userland because ${OS161_SRC} does not exist."
fi

cd ${prev_dir}
echo "Done compiling userland"
54 changes: 54 additions & 0 deletions scripts/build_helpers/configure_and_compile_kernel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#/bin/bash

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}

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 and compiling the kernel"
44 changes: 44 additions & 0 deletions scripts/build_helpers/configure_os_tree.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#/bin/bash

# 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
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"
33 changes: 33 additions & 0 deletions scripts/clean_build.sh
Original file line number Diff line number Diff line change
@@ -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!"
2 changes: 1 addition & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down