Compare commits

..

2 Commits

Author SHA1 Message Date
Joe ace80e39ce
bump version 2024-02-14 12:09:05 -06:00
Joe d769da7254
add initial support for modules 2024-02-14 12:08:33 -06:00
11 changed files with 148 additions and 4 deletions

View File

@ -6,6 +6,7 @@ Clean
Log
LogTerm
LogFile
modules/
ProcessBuildFile
BuildProject
InitProject
@ -15,6 +16,7 @@ PrintInfo
SubInit
SubBump
SubBuild
SubGet
SubHelp
SubCommand
Main

View File

@ -1,5 +1,5 @@
projectName='LINAC'
projectDescription='LINAC is not a compiler'
projectVersion=0.9.4
projectVersion=0.10.0
projectAuthor='Joe <joe@thisisjoes.site>'
projectLicense='GPLv3'

View File

@ -33,10 +33,14 @@ BuildProject() {
esac
Log debug "Using target '$target'"
MakeStub "$target"
local paths
mapfile -t paths < <(ProcessBuildFile "$target")
local -a paths
local -a module_paths
GetModulePaths module_paths
local -a local_paths
mapfile -t local_paths < <(ProcessBuildFile "$target")
paths+=(${module_paths[@]})
paths+=(${local_paths[@]})
Log debug "Paths are '${paths[*]}'"
local files
@ -53,6 +57,11 @@ BuildProject() {
local strip_comments=false
;;
m ) Log info "Got option '$option', building as submodule without stub or entrypoint."
local is_submodule=true
local strip_comments=true
;;
'' ) Log debug "No option passed, stripping comments."
local strip_comments=true
;;
@ -62,6 +71,14 @@ BuildProject() {
;;
esac
if [[ ! "$is_submodule" == true ]]; then
Log info "Creating stub..."
MakeStub
else
local name="${projectName,,}"
[[ -f "${config[build_path]}$name" ]] && rm "${config[build_path]}$name"
fi
if [[ "$strip_comments" == true ]]; then
local args='-Ehrv'
local pattern='^\s*#'

View File

@ -9,5 +9,6 @@ Configure() {
[log_file]="linac.log"
[src_path]="src/"
[build_path]="build/"
[module_path]="modules"
)
}

View File

@ -2,6 +2,7 @@ CreateFiles() {
if [ ! -d "${config[config_path]}" ]; then
mkdir "${config[config_path]}"
mkdir "${config[src_path]}"
mkdir "${config[module_path]}"
mkdir "${config[build_path]}"
touch "${config[config_path]}"/"${config[config_file]}"
fi

4
src/SubGet Normal file
View File

@ -0,0 +1,4 @@
SubGet() {
InitCheck
GetModuleDependencies "$@"
}

10
src/modules/BuildModule Normal file
View File

@ -0,0 +1,10 @@
BuildModule() {
Log debug "Got args '$*'"
local module="$1"
local version="$2"
local module_path="${config[module_path]}"
cd "$module_path/${module}/${version}"
linac get && linac build -m "${module}.build"
}

View File

@ -0,0 +1,20 @@
CheckModuleCache() {
local module="$1"
local version="$2"
local url="$3"
local module_path="${config[module_path]}"
if [[ ! -d "$module_path" ]]; then
mkdir "$module_path"
# Log error "Module cache directory missing. Aborting."
# exit 1
fi
if [[ -d "${module_path}/${module}/${version}" ]]; then
Log info "Module '$module', version '$version' found in local cache."
else
Log info "Module '$module', version '$version' not in local cache."
return 1
fi
}

View File

@ -0,0 +1,38 @@
GetModuleDependencies() {
local module_file="${projectName,,}.module"
local -A depends
if [[ -f "$module_file" ]]; then
. "$module_file" ||
{
Log error "Failed to load LINAC module file '$module_file'"
return 1
}
else
Log info "'${projectName}' has no module file, skipping"
return 0
fi
local module
for module in "${!depends[@]}"; do
Log debug "$module"
Log debug "${depends[$module]}"
declare -A "$module"'='"${depends[$module]}"
done
for module in "${!depends[@]}"; do
local -n ref
ref=${module}
local version
version="${ref[v]}"
local url
url="${ref[u]}"
CheckModuleCache "$module" "$version" || {
RetrieveModule "$module" "$version" "$url"
}
BuildModule "$module" "$version"
# WriteModuleInfo "$module" "$url"
unset -n ref
done
}

View File

@ -0,0 +1,35 @@
GetModulePaths() {
local -n __GetModulePaths_paths="$1"
local module_file="${projectName,,}.module"
local -A depends
if [[ -f "$module_file" ]]; then
. "$module_file" ||
{
Log error "Failed to load LINAC module file '$module_file'"
return 1
}
else
Log info "'${projectName}' has no module file, skipping"
return 0
fi
local module
for module in "${!depends[@]}"; do
Log debug "$module"
Log debug "${depends[$module]}"
declare -Ag "$module"'='"${depends[$module]}"
done
for module in "${!depends[@]}"; do
local -n ref
ref=${module}
local version
version="${ref[v]}"
__GetModulePaths_paths+=("${config[module_path]}/${module}/${version}/build/")
unset -n ref
done
}

View File

@ -0,0 +1,16 @@
RetrieveModule() {
local module="$1"
local version="$2"
local url="https://$3"
Log info "Retreiving module '$module' version '$version' from '$url'"
if [[ "$version" =~ ^[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}.*$ ]]; then
local clone_version="v${version}"
else
local clone_version="$version"
fi
git clone -b "$clone_version" --depth 1 "$url" "${config[module_path]}/$module/$version" -c advice.detachedHead=false --quiet >/dev/null || {
Log error "Failed to retrieve module '$module' version '$version'. Aborting."
exit 1
}
}