mirror of
https://github.com/Ed94/WATL_Exercise.git
synced 2025-08-04 22:32:43 -07:00
some more progress
This commit is contained in:
150
scripts/build.ps1
Normal file
150
scripts/build.ps1
Normal file
@@ -0,0 +1,150 @@
|
||||
$misc = Join-Path $PSScriptRoot 'helpers/misc.psm1'
|
||||
import-module $misc
|
||||
|
||||
$devshell = join-path $PSScriptRoot 'helpers/devshell.ps1'
|
||||
$path_root = Get-ScriptRepoRoot
|
||||
|
||||
if ($IsWindows) {
|
||||
& $devshell -arch amd64
|
||||
}
|
||||
|
||||
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
|
||||
$flag_all_c = '/TC'
|
||||
$flag_c11 = '/std:c11'
|
||||
$flag_all_cpp = '/TP'
|
||||
$flag_compile = '/c'
|
||||
$flag_charset_utf8 = '/utf-8'
|
||||
$flag_debug = '/Zi'
|
||||
$flag_define = '/D'
|
||||
$flag_exceptions_disabled = '/EHsc-'
|
||||
$flag_RTTI_disabled = '/GR-'
|
||||
$flag_include = '/I'
|
||||
$flag_full_src_path = '/FC'
|
||||
$flag_nologo = '/nologo'
|
||||
$flag_dll = '/LD'
|
||||
$flag_dll_debug = '/LDd'
|
||||
$flag_linker = '/link'
|
||||
# $flag_link_lib = '/lib'
|
||||
$flag_link_dll = '/DLL'
|
||||
$flag_link_no_incremental = '/INCREMENTAL:NO'
|
||||
$flag_link_mapfile = '/MAP:'
|
||||
$flag_link_optimize_references = '/OPT:REF'
|
||||
$flag_link_win_debug = '/DEBUG'
|
||||
$flag_link_win_pdb = '/PDB:'
|
||||
$flag_link_win_machine_32 = '/MACHINE:X86'
|
||||
$flag_link_win_machine_64 = '/MACHINE:X64'
|
||||
$flag_link_win_path_output = '/OUT:'
|
||||
$flag_link_win_rt_dll = '/MD'
|
||||
$flag_link_win_rt_dll_debug = '/MDd'
|
||||
$flag_link_win_rt_static = '/MT'
|
||||
$flag_link_win_rt_static_debug = '/MTd'
|
||||
$flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
|
||||
$flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
|
||||
$flag_no_optimization = '/Od'
|
||||
$flag_optimize_fast = '/O2'
|
||||
$flag_optimize_size = '/O1'
|
||||
$flag_optimize_intrinsics = '/Oi'
|
||||
$flag_optimized_debug_forceinline = '/d2Obforceinline'
|
||||
$flag_optimized_debug = '/Zo'
|
||||
$flag_preprocess_to_file = '/P'
|
||||
$flag_preprocess_preserve_comments = '/C'
|
||||
# $flag_out_name = '/OUT:'
|
||||
$flag_path_interm = '/Fo'
|
||||
$flag_path_debug = '/Fd'
|
||||
$flag_path_output = '/Fe'
|
||||
$flag_preprocess_conform = '/Zc:preprocessor'
|
||||
$flag_updated_cpp_macro = "/Zc:__cplusplus"
|
||||
$flag_set_stack_size = '/F'
|
||||
$flag_syntax_only = '/Zs'
|
||||
$flag_wall = '/Wall'
|
||||
$flag_warnings_as_errors = '/WX'
|
||||
$flag_lib_list = '/LIST'
|
||||
|
||||
$archiver = 'lib'
|
||||
$compiler = 'cl'
|
||||
$linker = 'link'
|
||||
|
||||
$path_build = join-path $path_root 'build'
|
||||
if ( -not(test-path -Path $path_build) ) {
|
||||
new-item -ItemType Directory -Path $path_build
|
||||
}
|
||||
|
||||
push-location $path_build
|
||||
|
||||
$compiler_args = @()
|
||||
$compiler_args += $flag_nologo
|
||||
|
||||
# Constraints on interpeting all files as C code
|
||||
$compiler_args += $flag_all_c
|
||||
$compiler_args += $flag_c11
|
||||
# Constraints on C program code-gen
|
||||
$compiler_args += $flag_exceptions_disabled
|
||||
$compiler_args += $flag_RTTI_disabled
|
||||
$compiler_args += $flag_preprocess_conform
|
||||
|
||||
# Set charset encoding for both execution and source to UTF-8
|
||||
|
||||
# Dump preprocess file
|
||||
if ($false) {
|
||||
$compiler_args += $flag_preprocess_to_file
|
||||
$compiler_args += $flag_preprocess_preserve_comments
|
||||
}
|
||||
|
||||
# Diagnostic logging
|
||||
$compiler_args += $flag_full_src_path
|
||||
|
||||
# Specifing output pathing
|
||||
$compiler_args += ( $flag_path_interm + $path_build + '\' )
|
||||
$compiler_args += ( $flag_path_output + $path_build + '\' )
|
||||
|
||||
$compiler_args += $flag_no_optimization
|
||||
|
||||
# Debug setup
|
||||
$compiler_args += $flag_debug
|
||||
$compiler_args += ( $flag_path_debug + $path_build + '\' )
|
||||
$compiler_args += $flag_link_win_rt_static_debug
|
||||
|
||||
# Include setup
|
||||
$compiler_args += ($flag_include + $path_root)
|
||||
|
||||
# Specify unit to compile
|
||||
$unit = join-path $path_root 'C\watl.v0.msvc.c'
|
||||
$compiler_args += $flag_compile, $unit
|
||||
|
||||
# Diagnoistc print for the args
|
||||
$compiler_args | ForEach-Object { Write-Host $_ }
|
||||
write-host
|
||||
|
||||
# $compiler_args += ( $flag_define + 'DEMO_STR_SLICE' )
|
||||
# $compiler_args += ( $flag_define + 'DEMO__FILE_READ_CONTENTS_V1' )
|
||||
|
||||
# Compile the unit
|
||||
& $compiler $compiler_args
|
||||
|
||||
$binary = join-path $path_build 'watl.v0.msvc.exe'
|
||||
$object = join-path $path_build 'watl.v0.msvc.obj'
|
||||
|
||||
$pdb = join-path $path_build 'watl.v0.msvc.pdb'
|
||||
$map = join-path $path_build 'watl.v0.msvc.map'
|
||||
|
||||
if ($true) {
|
||||
$linker_args = @()
|
||||
$linker_args += $flag_nologo
|
||||
$linker_args += $flag_link_win_machine_64
|
||||
$linker_args += $flag_link_no_incremental
|
||||
$linker_args += ($flag_link_win_path_output + $binary)
|
||||
|
||||
$linker_args += $flag_link_win_debug
|
||||
$linker_args += $flag_link_win_pdb + $pdb
|
||||
$linker_args += $flag_link_mapfile + $map
|
||||
|
||||
$linker_args += $object
|
||||
|
||||
# Diagnoistc print for the args
|
||||
$linker_args | ForEach-Object { Write-Host $_ }
|
||||
write-host
|
||||
|
||||
& $linker $linker_args
|
||||
}
|
||||
|
||||
Pop-Location
|
28
scripts/helpers/devshell.ps1
Normal file
28
scripts/helpers/devshell.ps1
Normal file
@@ -0,0 +1,28 @@
|
||||
if ($env:VCINSTALLDIR) {
|
||||
return
|
||||
}
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Use vswhere to find the latest Visual Studio installation
|
||||
$vswhere_out = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath
|
||||
if ($null -eq $vswhere_out) {
|
||||
Write-Host "ERROR: Visual Studio installation not found"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Find Launch-VsDevShell.ps1 in the Visual Studio installation
|
||||
$vs_path = $vswhere_out
|
||||
$vs_devshell = Join-Path $vs_path "\Common7\Tools\Launch-VsDevShell.ps1"
|
||||
|
||||
if ( -not (Test-Path $vs_devshell) ) {
|
||||
Write-Host "ERROR: Launch-VsDevShell.ps1 not found in Visual Studio installation"
|
||||
Write-Host Tested path: $vs_devshell
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Launch the Visual Studio Developer Shell
|
||||
Push-Location
|
||||
write-host @args
|
||||
& $vs_devshell @args
|
||||
Pop-Location
|
73
scripts/helpers/incremental_checks.ps1
Normal file
73
scripts/helpers/incremental_checks.ps1
Normal file
@@ -0,0 +1,73 @@
|
||||
# This is meant to be used with build.ps1, and is not a standalone script.
|
||||
|
||||
function check-FileForChanges
|
||||
{
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$path_file
|
||||
)
|
||||
|
||||
if (-not (Test-Path $path_file -PathType Leaf)) {
|
||||
Write-Error "The provided path is not a valid file: $path_file"
|
||||
return $false
|
||||
}
|
||||
$file_name = Split-Path $path_file -Leaf
|
||||
$path_csv = Join-Path $path_build ($file_name + "_file_hash.csv")
|
||||
|
||||
$csv_file_hash = $null
|
||||
if (Test-Path $path_csv) {
|
||||
$csv_file_hash = Import-Csv $path_csv | Select-Object -ExpandProperty value
|
||||
}
|
||||
|
||||
$current_hash_info = Get-FileHash -Path $path_file -Algorithm MD5
|
||||
$current_file_hash = $current_hash_info.Hash
|
||||
|
||||
# Save the current hash to the CSV
|
||||
[PSCustomObject]@{
|
||||
name = $path_file
|
||||
value = $current_file_hash
|
||||
} | Export-Csv $path_csv -NoTypeInformation
|
||||
|
||||
if ($csv_file_hash -and $csv_file_hash -eq $current_file_hash) {
|
||||
return $false
|
||||
} else {
|
||||
return $true
|
||||
}
|
||||
}
|
||||
|
||||
# Check to see if the module has changed files since the last build
|
||||
function check-ModuleForChanges
|
||||
{
|
||||
param( [string]$path_module, [array]$excludes )
|
||||
|
||||
$module_name = split-path $path_module -leaf
|
||||
$path_csv = Join-Path $path_build ($module_name + "_module_hashes.csv")
|
||||
|
||||
$csv_file_hashes = $null
|
||||
if ( test-path $path_csv ) {
|
||||
$csv_file_hashes = @{}
|
||||
import-csv $path_csv | foreach-object {
|
||||
$csv_file_hashes[ $_.name ] = $_.value
|
||||
}
|
||||
}
|
||||
|
||||
$file_hashes = @{}
|
||||
get-childitem -path $path_module -recurse -file -Exclude $excludes | foreach-object {
|
||||
$id = $_.fullname
|
||||
$hash_info = get-filehash -path $id -Algorithm MD5
|
||||
$file_hashes[ $id ] = $hash_info.Hash
|
||||
}
|
||||
|
||||
$file_hashes.GetEnumerator() | foreach-object { [PSCustomObject]$_ } |
|
||||
export-csv $path_csv -NoTypeInformation
|
||||
|
||||
if ( -not $csv_file_hashes ) { return $true }
|
||||
if ( $csv_file_hashes.Count -ne $file_hashes.Count ) { return $true }
|
||||
|
||||
foreach ( $key in $csv_file_hashes.Keys ) {
|
||||
if ( $csv_file_hashes[ $key ] -ne $file_hashes[ $key ] ) {
|
||||
return $true
|
||||
}
|
||||
}
|
||||
return $false
|
||||
}
|
20
scripts/helpers/misc.psm1
Normal file
20
scripts/helpers/misc.psm1
Normal file
@@ -0,0 +1,20 @@
|
||||
function Get-ScriptRepoRoot {
|
||||
$currentPath = $PSScriptRoot
|
||||
while ($currentPath -ne $null -and $currentPath -ne "")
|
||||
{
|
||||
if (Test-Path (Join-Path $currentPath ".git")) {
|
||||
return $currentPath
|
||||
}
|
||||
# Also check for .git file which indicates a submodule
|
||||
$gitFile = Join-Path $currentPath ".git"
|
||||
if (Test-Path $gitFile -PathType Leaf)
|
||||
{
|
||||
$gitContent = Get-Content $gitFile
|
||||
if ($gitContent -match "gitdir: (.+)") {
|
||||
return $currentPath
|
||||
}
|
||||
}
|
||||
$currentPath = Split-Path $currentPath -Parent
|
||||
}
|
||||
throw "Unable to find repository root"
|
||||
}
|
Reference in New Issue
Block a user