# HG changeset patch # User Olaf Wintermann # Date 1766181758 -3600 # Node ID eef1439666f73eaa89b01c59873950263370111b # Parent 2e9b3f85c949c9c5735dd72ffdca1a2f57d2eb69 add powershell build script template diff -r 2e9b3f85c949 -r eef1439666f7 UwBuild.psm1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UwBuild.psm1 Fri Dec 19 23:02:38 2025 +0100 @@ -0,0 +1,4 @@ +function UwBuildShell { + &{Import-Module "C:\Program Files\Microsoft Visual Studio\18\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" } + Enter-VsDevShell a295baa3 +} diff -r 2e9b3f85c949 -r eef1439666f7 build.ps1.template --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build.ps1.template Fri Dec 19 23:02:38 2025 +0100 @@ -0,0 +1,147 @@ +# ------------------------- +# Utility functions +# ------------------------- + +function Is-Platform { + param([string]$Name) + return $PLATFORM -contains $Name +} + +function Not-IsPlatform { + param([string]$Name) + return -not ($PLATFORM -contains $Name) +} + +# ------------------------- +# Platform (fixed) +# ------------------------- + +Write-Host "detect platform... windows" + +$PLATFORM = @('windows') +$PLATFORM_NAME = 'windows' + +# ------------------------- +# Result directories +# ------------------------- + +New-Item -ItemType Directory -Force -Path result | Out-Null +$result_dir = (Resolve-Path result).Path + +$configure_log = "configure.log" +$compile_log = "compile.log" +$check_log = "check.log" + +$result_file = Join-Path $result_dir "result.json" + +"[" | Out-File -FilePath $result_file -Encoding utf8 + +# ------------------------- +# Source directory +# ------------------------- + +Set-Location src + +{{ $nbuild := len .Build }} +{{ range $i, $build := .Build}} + +# Build isplatform="{{ .IsPlatform }}" not="{{ .NotPlatform }}" +while ($true) { + + $log_dir = Join-Path $result_dir "build{{$i}}" + New-Item -ItemType Directory -Force -Path $log_dir | Out-Null + if (-not $?) { + Write-Error "failed to create log dir $log_dir" + exit 1 + } + + {{- if .IsPlatform}} + if (Not-IsPlatform "{{ $build.IsPlatform }}") { + break + } + {{- end}} + + {{- range $build.NotList}} + if (Is-Platform "{{.}}") { + break + } + {{- end}} + + # ------------------------- + # configure + # ------------------------- + + $configure = $null + {{- if $build.Configure}} +@" +{{ $build.Configure }} +"@ | Out-File uwbuild-configure.ps1 -Encoding utf8 + + .\uwbuild-configure.ps1 *> (Join-Path $log_dir $configure_log) + + $configure = $LASTEXITCODE + {{- end}} + + # ------------------------- + # compile + # ------------------------- + + $compile = $null + {{- if $build.Compile}} +@" +{{ $build.Compile }} +"@ | Out-File uwbuild-compile.ps1 -Encoding utf8 + + .\uwbuild-compile.ps1 *> (Join-Path $log_dir $compile_log) + + $compile = $LASTEXITCODE + {{- end}} + + # ------------------------- + # check + # ------------------------- + + $check = $null + {{- if $build.Check}} +@" +{{ $build.Check }} +"@ | Out-File uwbuild-check.ps1 -Encoding utf8 + + .\uwbuild-check.ps1 *> (Join-Path $log_dir $check_log) + + $check = $LASTEXITCODE + {{- end}} + + # ------------------------- + # write result + # ------------------------- + + Add-Content $result_file "{ `"build`": `"{{$i}}`"," + + {{- if $build.Name}} + Add-Content $result_file " `"name`": `"{{$build.Name}}`"," + {{- end}} + + if ($null -ne $configure) { + Add-Content $result_file " `"configure`": `"$configure`"," + } + if ($null -ne $compile) { + Add-Content $result_file " `"compile`": `"$compile`"," + } + if ($null -ne $check) { + Add-Content $result_file " `"check`": `"$check`"" + } + + {{- if eq $i (sub $nbuild 1)}} + Add-Content $result_file "}" + {{ else }} + Add-Content $result_file "}," + {{- end}} + + break +} + +# End Build +{{ end}} + +"]" | Add-Content $result_file diff -r 2e9b3f85c949 -r eef1439666f7 src/main.go --- a/src/main.go Fri Dec 19 22:38:10 2025 +0100 +++ b/src/main.go Fri Dec 19 23:02:38 2025 +0100 @@ -106,6 +106,11 @@ log.Fatal(err) } + templateStr2, err := os.ReadFile("build.ps1.template") + if err != nil { + log.Fatal(err) + } + funcs := template.FuncMap{ "add": func(i int, n int) int { return i + n @@ -120,6 +125,11 @@ log.Fatal(err) } + tpl2, err := template.New("").Funcs(funcs).Parse(string(templateStr2)) + if err != nil { + log.Fatal(err) + } + err = os.Mkdir("tmp", 0755) if err != nil && !os.IsExist(err) { log.Fatal(err) @@ -141,7 +151,7 @@ continue } - if err := create_repo_archive(&repo, tpl, tmp); err != nil { + if err := create_repo_archive(&repo, tpl, tpl2, tmp); err != nil { log.Fatal(err) } @@ -154,7 +164,7 @@ } } -func create_repo_archive(repo *Repository, tpl *template.Template, tmp_dir string) error { +func create_repo_archive(repo *Repository, tpl *template.Template, tpl2 *template.Template, tmp_dir string) error { // create a build directory, that contains the repository source // and build scripts buildPath := path.Join(tmp_dir, "build") @@ -229,8 +239,20 @@ } file.Chmod(0755) + file2, err := os.Create(path.Join(buildPath, "build.ps1")) + if err != nil { + log.Print("cannot create build.ps1") + return err + } + defer file2.Close() + err = tpl2.Execute(file2, repo) + if err != nil { + log.Print("cannot execute build.ps1 template") + return err + } + // create tarball - cmd = exec.Command("tar", "cvf", "../build.tar", "src", "build.sh") + cmd = exec.Command("tar", "cvf", "../build.tar", "src", "build.sh", "build.ps1") cmd.Dir = buildPath if err := cmd.Run(); err != nil { log.Print("tar error")