Changed codebase to be foldered (breaking compiler's conventions)

I now generate the layout the compiler wants, eventually I'll just have a custom policy so that the compiler can accept the non-idiomatic layout

See scripts/build.ps1 & gen_staged_compiler_codebase.ps1 for how this is handled.
This commit is contained in:
Edward R. Gonzalez 2024-05-16 13:18:27 -04:00
parent 5ceef39410
commit 40ffed9538
70 changed files with 86 additions and 10 deletions

2
.gitignore vendored
View File

@ -4,4 +4,4 @@ build/**
logs
.ark
logs*.zip
code_virtual_view
code_compiler_staged

View File

@ -26,6 +26,8 @@ The dependencies are:
The client(sectr) module's organization is relatively flat due to the nature of odin's compiler, not allowing for cyclic dependencies across modules, and modules can only be in one directory.
This makes it difficult to unflatten, not something organic todo in a prototype...
I have the codebase by default in a non-idomatic layout that I stage to the compiler beforehand. There is a script(`scripts/gen_staged_compiler_codebase.ps1`) that stages a the idiomatic format of the codebase for the compiler to digest when `scripts/build.ps1` is run.
Even so the notable groups are:
* API : Provides the overarching interface of the app's general behavior. Host uses this to provide the client its necessary data and exection env.

View File

@ -117,13 +117,18 @@ push-location $path_root
function build-prototype
{
push-location $path_code
$gen_staged_compiler_codebase = join-path $PSScriptRoot 'gen_staged_compiler_codebase.ps1'
$path_code_compiler_staged = join-path $path_root 'code_compiler_staged'
. $gen_staged_compiler_codebase
push-location $path_code_compiler_staged
$project_name = 'sectr'
write-host "`nBuilding Sectr Prototype`n"
$module_host = join-path $path_code 'host'
$module_sectr = $path_code
$module_host = join-path $path_code_compiler_staged 'host'
$module_sectr = $path_code_compiler_staged
$pkg_collection_thirdparty = 'thirdparty=' + $path_thirdparty
@ -273,6 +278,8 @@ push-location $path_root
build-host
Pop-Location # path_code
if ( test-path $path_code_compiler_staged ) { Remove-Item -Path $path_code_compiler_staged -Force -Recurse }
}
build-prototype
pop-location # path_root

View File

@ -1,9 +1,9 @@
cls
$path_root = git rev-parse --show-toplevel
$path_code = join-path $path_root 'code'
$path_build = join-path $path_root 'build'
$path_root = git rev-parse --show-toplevel
$path_code = join-path $path_root 'code'
$path_code_compiler_staged = Join-Path $path_root 'code_compiler_staged'
$path_build = join-path $path_root 'build'
if ( test-path $path_build ) {
Remove-Item $path_build -Verbose -Force -Recurse
}
if ( test-path $path_build ) { Remove-Item $path_build -Verbose -Force -Recurse }
if ( test-path $path_code_compiler_staged) { Remove-Item $path_code_compiler_staged -Verbose -Force -Recurse }

View File

@ -0,0 +1,67 @@
cls
Write-Host "Reverse Build.ps1"
$path_root = git rev-parse --show-toplevel
$path_code = Join-Path $path_root 'code'
$path_code_compiler_staged = Join-Path $path_root 'code_compiler_staged'
if (Test-Path $path_code_compiler_staged) {
Remove-Item -Path $path_code_compiler_staged -Recurse -Force -ErrorAction Ignore
}
New-Item -ItemType Directory -Path $path_code_compiler_staged
$whitelist_package = 'sectr'
$files = Get-ChildItem -Path $path_code -File -Recurse
foreach ($file in $files)
{
# Read the file line by line to determine the package name, ignoring comments
$packageName = $null
Get-Content -Path $file.FullName | ForEach-Object {
if ($_ -notmatch '^\s*//')
{
if ($_ -match '^package\s+(\w+)$') {
$packageName = $Matches[1]
return $false
}
}
}
if ($packageName)
{
# Calculate relative path and prepend directory names to the file name
$relativePath = $file.FullName.Substring($path_code.Length + 1)
$relativeDir = Split-Path $relativePath -Parent
$relativeDir = $relativeDir.Replace('\', '_').Replace('/', '_')
if ($relativeDir -ne '') {
$targetFileName = "$relativeDir" + "_" + $file.Name
} else {
$targetFileName = $file.Name
}
# Determine target directory based on the package name
if ($packageName -eq $whitelist_package) {
$targetDir = $path_code_compiler_staged
} else {
$targetDir = Join-Path $path_code_compiler_staged $packageName
if (-not (Test-Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir
}
}
$targetFilePath = Join-Path $targetDir $targetFileName
# Check if the target file path already exists and handle it accordingly
if (-not (Test-Path $targetFilePath)) {
New-Item -ItemType SymbolicLink -Path $targetFilePath -Value $file.FullName
} else {
Write-Host "Warning: The link for $($file.FullName) already exists at $targetFilePath. Skipping..."
}
}
else {
Write-Host "Warning: The file $($file.FullName) does not contain a valid package declaration."
}
}
Write-Host "Compiler staged directory structure created successfully."