|
| 1 | +$ErrorActionPreference = 'Stop' |
| 2 | +$PSNativeCommandUseErrorActionPreference = $true |
| 3 | + |
| 4 | +try {{ |
| 5 | + |
| 6 | + # List of files to ignore |
| 7 | + $ignoreList = @({excluded_files}) |
| 8 | + |
| 9 | + # List of components |
| 10 | + $components = @({components_list}) |
| 11 | + |
| 12 | + # Function to check if a file is in the ignore list |
| 13 | + function ShouldIgnore {{ |
| 14 | + param ( |
| 15 | + [string]$fileName |
| 16 | + ) |
| 17 | + return $ignoreList -contains $fileName |
| 18 | + }} |
| 19 | + |
| 20 | + # Function to determine which component a file belongs to |
| 21 | + function GetFileComponent {{ |
| 22 | + param ( |
| 23 | + [string]$filePath |
| 24 | + ) |
| 25 | + |
| 26 | + $fileName = [System.IO.Path]::GetFileNameWithoutExtension($filePath) |
| 27 | + |
| 28 | + foreach ($component in $components) {{ |
| 29 | + # Check if filename starts with component name (e.g., Com_*, BswM_*, etc.) |
| 30 | + if ($fileName -like "${{component}}_*" -or $fileName -eq $component) {{ |
| 31 | + return $component |
| 32 | + }} |
| 33 | + }} |
| 34 | + |
| 35 | + return "main" # Default to main if no component match |
| 36 | + }} |
| 37 | + |
| 38 | + # Create all destination folders |
| 39 | + $allDirs = @("{sources_dir}", "{headers_dir}"{component_dirs_list}) |
| 40 | + foreach ($dir in $allDirs) {{ |
| 41 | + if (-not (Test-Path -Path $dir)) {{ |
| 42 | + New-Item -ItemType Directory -Path $dir -Force |
| 43 | + }} |
| 44 | + }} |
| 45 | + |
| 46 | + # Process .h files. Ignore all files from the RteAnalyzer folder |
| 47 | + Get-ChildItem -Path {generator_output_dir} -Filter *.h -Recurse | Where-Object {{ $_.FullName -notlike "*RteAnalyzer*" }} | ForEach-Object {{ |
| 48 | + #if (-not (ShouldIgnore -fileName $_.Name)) {{ |
| 49 | + # Always copy to main headers directory first |
| 50 | + Copy-Item -Path $_.FullName -Destination {headers_dir} |
| 51 | + #}} |
| 52 | + }} |
| 53 | + |
| 54 | + # Define the list of file patterns to include |
| 55 | + $sourceFilePatterns = @("*.c", "*.asm", "*.inc", "*.inl", "*.S", "*.s", "*.a") |
| 56 | + |
| 57 | + if ({additional_source_file_endings} -and {additional_source_file_endings} -ne @("")) {{ |
| 58 | + $sourceFilePatterns += {additional_source_file_endings} |
| 59 | + }} |
| 60 | + |
| 61 | + # Process source files. Ignore all files from the RteAnalyzer folder |
| 62 | + foreach ($pattern in $sourceFilePatterns) {{ |
| 63 | + Get-ChildItem -Path {generator_output_dir} -Filter $pattern -Recurse | Where-Object {{ $_.FullName -notlike "*RteAnalyzer*" }} | ForEach-Object {{ |
| 64 | + if (-not (ShouldIgnore -fileName $_.Name)) {{ |
| 65 | + # Always copy to main sources directory first |
| 66 | + Copy-Item -Path $_.FullName -Destination {sources_dir} |
| 67 | + }} |
| 68 | + }} |
| 69 | + }} |
| 70 | + |
| 71 | + # Move component-specific files from main directories to component directories |
| 72 | + # Process headers first |
| 73 | + Get-ChildItem -Path {headers_dir} -Filter *.h | ForEach-Object {{ |
| 74 | + $component = GetFileComponent -filePath $_.FullName |
| 75 | + |
| 76 | + # If this file belongs to a specific component, move it to component directory |
| 77 | + if ($component -ne "main") {{ |
| 78 | + $componentHeadersDir = "{headers_dir}/../generated_headers_${{component}}" |
| 79 | + if (Test-Path $componentHeadersDir) {{ |
| 80 | + Move-Item -Path $_.FullName -Destination $componentHeadersDir |
| 81 | + }} |
| 82 | + }} |
| 83 | + }} |
| 84 | + |
| 85 | + # Process sources |
| 86 | + foreach ($pattern in $sourceFilePatterns) {{ |
| 87 | + Get-ChildItem -Path {sources_dir} -Filter $pattern | ForEach-Object {{ |
| 88 | + $component = GetFileComponent -filePath $_.FullName |
| 89 | + |
| 90 | + # If this file belongs to a specific component, move it to component directory |
| 91 | + if ($component -ne "main") {{ |
| 92 | + $componentSourcesDir = "{sources_dir}/../generated_sources_${{component}}" |
| 93 | + if (Test-Path $componentSourcesDir) {{ |
| 94 | + Move-Item -Path $_.FullName -Destination $componentSourcesDir |
| 95 | + }} |
| 96 | + }} |
| 97 | + }} |
| 98 | + }} |
| 99 | + |
| 100 | + Write-Output "Files have been moved successfully." |
| 101 | +}} catch {{ |
| 102 | + Write-Error "An error occurred: $_" |
| 103 | + exit 1 |
| 104 | +}} |
0 commit comments