From d58a707484d304ffeea935fa4397de6408519914 Mon Sep 17 00:00:00 2001 From: "Charlton, Scott R" Date: Wed, 11 May 2022 21:41:29 -0600 Subject: [PATCH] Added vtk-9.1.0-leaks build --- .gitattributes | 1 + .github/workflows/build-vtk-9.1.0-leaks.yml | 309 ++++++++++++++++++++ misc/0001-update-for-memory-leaks.patch | 26 ++ 3 files changed, 336 insertions(+) create mode 100644 .gitattributes create mode 100644 .github/workflows/build-vtk-9.1.0-leaks.yml create mode 100644 misc/0001-update-for-memory-leaks.patch diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..991959d --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +misc/0001-update-for-memory-leaks.patch text eol=lf \ No newline at end of file diff --git a/.github/workflows/build-vtk-9.1.0-leaks.yml b/.github/workflows/build-vtk-9.1.0-leaks.yml new file mode 100644 index 0000000..8de1bee --- /dev/null +++ b/.github/workflows/build-vtk-9.1.0-leaks.yml @@ -0,0 +1,309 @@ +name: build-vtk-9.1.0-leaks + +on: + push: + branches: + - main + - develop* + paths: + - .github/workflows/build-vtk-9.1.0-leaks.yml + - misc/CMakePresets-vtk-9.1.0.json + +env: + CL: /MP + VTK_VERSION: 9.1.0 + VS_VERSION: vs2019 + PRESET: VTK-9.1.0-leaks-vs2019-x64 + +jobs: + + cache-vtk-debug: + # comment the next line if you want to compile vtk + if: github.repository == 'MODFLOW-USGS/modelviewer-mf6' + + runs-on: windows-2019 + + steps: + + - uses: actions/checkout@v2 + + - name: Export env + env: + type: debug + zipfile: v${{env.VTK_VERSION}}.zip + instdir: C:/VTK-${{env.VTK_VERSION}}-leaks-${{env.VS_VERSION}}-x64 + builddir: C:/VTK-${{env.VTK_VERSION}}-leaks-${{env.VS_VERSION}}-x64-build + srcdir: C:/VTK-${{env.VTK_VERSION}} + shell: pwsh + run: | + echo "type=$env:type" >> $env:GITHUB_ENV + echo "zipfile=$env:zipfile" >> $env:GITHUB_ENV + echo "instdir=$env:instdir" >> $env:GITHUB_ENV + echo "builddir=$env:builddir" >> $env:GITHUB_ENV + echo "srcdir=$env:srcdir" >> $env:GITHUB_ENV + + - name: Cache vtk + id: cache-vtk-debug + uses: actions/cache@v2 + with: + path: ${{env.instdir}} + key: windows-2019-vtk-leaks-${{env.type}}-${{hashFiles('misc\CMakePresets-vtk-9.1.0.json')}} + + - name: Download vtk + if: steps.cache-vtk-debug.outputs.cache-hit != 'true' + shell: pwsh + run: | + curl -L -O "https://github.com/Kitware/VTK/archive/refs/tags/${{env.zipfile}}" + Get-FileHash ${{env.zipfile}} + cd C:\ + 7z x ${{github.workspace}}\${{env.zipfile}} + rm ${{github.workspace}}\${{env.zipfile}} + + # it seems that 'patch' is more forgiving of line endings than 'git apply' + - name: Patch vtk + if: steps.cache-vtk-debug.outputs.cache-hit != 'true' + shell: bash + run: | + cp ./misc/0001-update-for-memory-leaks.patch /c/VTK-${{env.VTK_VERSION}}/Utilities/KWSys/vtksys/. + cd /c/VTK-${{env.VTK_VERSION}}/Utilities/KWSys/vtksys/. + md5sum SystemTools.cxx 0001-update-for-memory-leaks.patch + file SystemTools.cxx 0001-update-for-memory-leaks.patch + patch < 0001-update-for-memory-leaks.patch + md5sum SystemTools.cxx + file SystemTools.cxx + + - name: Build vtk + if: steps.cache-vtk-debug.outputs.cache-hit != 'true' + shell: pwsh + run: | + cp misc\CMakePresets-vtk-9.1.0.json ${{env.srcdir}}\CMakePresets.json + cd ${{env.srcdir}} + cmake --preset ${{env.PRESET}} + cmake --build --preset ${{env.PRESET}} --config ${{env.type}} + cmake --install ${{env.builddir}} --prefix ${{env.instdir}} --config ${{env.type}} + + - name: Check debug cache + shell: pwsh + run: | + dir ${{env.instdir}}\bin + + cache-vtk-release: + # uncomment the next line if you want to compile vtk + if: github.repository == 'MODFLOW-USGS/modelviewer-mf6' + + runs-on: windows-2019 + + steps: + + - uses: actions/checkout@v2 + + - name: Export env + env: + type: release + zipfile: v${{env.VTK_VERSION}}.zip + instdir: C:/VTK-${{env.VTK_VERSION}}-leaks-${{env.VS_VERSION}}-x64 + builddir: C:/VTK-${{env.VTK_VERSION}}-leaks-${{env.VS_VERSION}}-x64-build + srcdir: C:/VTK-${{env.VTK_VERSION}} + shell: pwsh + run: | + echo "type=$env:type" >> $env:GITHUB_ENV + echo "zipfile=$env:zipfile" >> $env:GITHUB_ENV + echo "instdir=$env:instdir" >> $env:GITHUB_ENV + echo "builddir=$env:builddir" >> $env:GITHUB_ENV + echo "srcdir=$env:srcdir" >> $env:GITHUB_ENV + + - name: Cache vtk + id: cache-vtk-release + uses: actions/cache@v2 + with: + path: ${{env.instdir}} + key: windows-2019-vtk-leaks-${{env.type}}-${{hashFiles('misc\CMakePresets-vtk-9.1.0.json')}} + + - name: Download vtk + if: steps.cache-vtk-release.outputs.cache-hit != 'true' + shell: pwsh + run: | + curl -L -O "https://github.com/Kitware/VTK/archive/refs/tags/${{env.zipfile}}" + Get-FileHash ${{env.zipfile}} + cd C:\ + 7z x ${{github.workspace}}\${{env.zipfile}} + rm ${{github.workspace}}\${{env.zipfile}} + + # it seems that 'patch' is more forgiving of line endings than 'git apply' + - name: Patch vtk + if: steps.cache-vtk-release.outputs.cache-hit != 'true' + shell: bash + run: | + cp ./misc/0001-update-for-memory-leaks.patch /c/VTK-${{env.VTK_VERSION}}/Utilities/KWSys/vtksys/. + cd /c/VTK-${{env.VTK_VERSION}}/Utilities/KWSys/vtksys/. + md5sum SystemTools.cxx 0001-update-for-memory-leaks.patch + file SystemTools.cxx 0001-update-for-memory-leaks.patch + patch < 0001-update-for-memory-leaks.patch + md5sum SystemTools.cxx + file SystemTools.cxx + + - name: Build vtk + if: steps.cache-vtk-release.outputs.cache-hit != 'true' + shell: pwsh + run: | + cp misc\CMakePresets-vtk-9.1.0.json ${{env.srcdir}}\CMakePresets.json + cd ${{env.srcdir}} + cmake --preset ${{env.PRESET}} + cmake --build --preset ${{env.PRESET}} --config ${{env.type}} + cmake --install ${{env.builddir}} --prefix ${{env.instdir}} --config ${{env.type}} + + - name: Check release cache + shell: pwsh + run: | + dir ${{env.instdir}}\bin + + cache-vtk: + # uncomment the next line if you want to compile vtk + if: github.repository == 'MODFLOW-USGS/modelviewer-mf6' + + runs-on: windows-2019 + needs: [cache-vtk-debug, cache-vtk-release] + + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: Export env + env: + zipfile: v${{env.VTK_VERSION}}.zip + instdir: C:/VTK-${{env.VTK_VERSION}}-leaks-${{env.VS_VERSION}}-x64 + builddir: C:/VTK-${{env.VTK_VERSION}}-leaks-${{env.VS_VERSION}}-x64-build + srcdir: C:/VTK-${{env.VTK_VERSION}} + tag: vtk-${{env.VTK_VERSION}}-leaks-${{env.VS_VERSION}}-x64 + shell: pwsh + run: | + echo "zipfile=$env:zipfile" >> $env:GITHUB_ENV + echo "instdir=$env:instdir" >> $env:GITHUB_ENV + echo "builddir=$env:builddir" >> $env:GITHUB_ENV + echo "srcdir=$env:srcdir" >> $env:GITHUB_ENV + echo "tag=$env:tag" >> $env:GITHUB_ENV + + - name: Cache vtk + id: cache-vtk + uses: actions/cache@v2 + with: + path: ${{env.instdir}} + key: windows-2019-vtk-leaks-${{hashFiles('misc\CMakePresets-vtk-9.1.0.json')}} + + - name: Cache vtk debug + if: steps.cache-vtk.outputs.cache-hit != 'true' + id: cache-vtk-debug + uses: actions/cache@v2 + with: + path: ${{env.instdir}} + key: windows-2019-vtk-leaks-debug-${{hashFiles('misc\CMakePresets-vtk-9.1.0.json')}} + + - name: Cache vtk release + if: steps.cache-vtk.outputs.cache-hit != 'true' + uses: actions/cache@v2 + with: + path: ${{env.instdir}} + key: windows-2019-vtk-leaks-release-${{hashFiles('misc\CMakePresets-vtk-9.1.0.json')}} + + - name: Check merged cache + shell: pwsh + run: | + dir ${{env.instdir}}\bin + + - name: Compress cache + shell: pwsh + run: | + 7z a ${{env.tag}}.7z ${{env.instdir}} + + - name: Delete release + env: + releases_url: ${{github.api_url}}/repos/${{github.repository}}/releases + run: | + # create headers dictionary + $h = @{"Authorization" = "token ${{secrets.GITHUB_TOKEN}}"} + + try { + # Get a release by tag name + # https://docs.github.com/rest/reference/repos#get-a-release-by-tag-name + # get /repos/{owner}/{repo}/releases/tags/{tag} + $response = Invoke-WebRequest -Uri ${{env.releases_url}}/tags/${{env.tag}} -Headers $h -Method Get + $hashtable = $response.Content | ConvertFrom-Json -AsHashtable + + # Delete a release + # https://docs.github.com/en/rest/reference/releases#delete-a-release + # delete /repos/{owner}/{repo}/releases/{release_id} + $id = $hashtable.id.ToString() + $response = Invoke-WebRequest -Uri ${{env.releases_url}}/$id -Headers $h -Method Delete + } + catch { + Write-Output "An error occured:" + Write-Output $_ + } + + - name: Delete tag + shell: pwsh + run: | + git push --delete origin refs/tags/${{env.tag}} + + - name: Create release + env: + releases_url: ${{github.api_url}}/repos/${{github.repository}}/releases + run: | + # setup json variables + $tag_name = "${{env.tag}}" + $filename = "${{env.tag}}.7z" + $hash = (Get-FileHash $filename).Hash.ToLower() + # format using markdown + $body = "```````nsha256`n$hash $filename`n``````" + + # store commit + $target_commitish = "${{github.sha}}" + + # create headers dictionary + $h = @{"Authorization" = "token ${{secrets.GITHUB_TOKEN}}"} + $releases_url = "${{env.releases_url}}" + # create release + # POST /repos/{owner}/{repo}/releases + # see https://docs.github.com/en/rest/reference/repos#create-a-release + # + $create = @{ + "body" = $body + "tag_name" = $tag_name + "target_commitish" = $target_commitish + "name" = $tag_name + "draft" = $true + } + $create_json = $create | ConvertTo-Json + $release = Invoke-WebRequest -Uri $releases_url -Headers $h -Method Post -Body $create_json + # upload artifact (asset) + # POST /repos/{owner}/{repo}/releases/{release_id}/assets + # see https://docs.github.com/en/rest/reference/repos#upload-a-release-asset + # + $upload_uri = ($release.Content | ConvertFrom-Json).upload_url + if (! ($upload_uri -match "(.*)\{\?name,label\}") ) { + # expecting URI{?name,label} + # ie https://uploads.github.com/repos/scharlton2/iricdev-2019/releases/24058628/assets{?name,label} + throw "Bad upload_url" + } + $upload_uri = $Matches[1] + "?name=$filename" + $h["Content-type"] = "application/x-7z-compressed" + $bytes = [System.IO.File]::ReadAllBytes($filename) + $upload = Invoke-WebRequest -Uri $upload_uri -Headers $h -Method Post -Body $bytes + # update release + # PATCH /repos/{owner}/{repo}/releases/{release_id} + # see https://docs.github.com/en/rest/reference/repos#update-a-release + # + $release_id = ($release.Content | ConvertFrom-Json).id + $h.Remove("Content-type") + $update = @{ "draft" = $false } + $update_json = $update | ConvertTo-Json + $release = Invoke-WebRequest -Uri "$releases_url/$release_id" -Headers $h -Method Patch -Body $update_json + + # display download url + Write-Output "::group::Results" + Write-Output "$((($release.Content | ConvertFrom-Json).assets).browser_download_url)" + Write-Output "${{github.sha}}" + Write-Output "sha256" + Write-Output "$hash $filename" + Write-Output "::endgroup::" diff --git a/misc/0001-update-for-memory-leaks.patch b/misc/0001-update-for-memory-leaks.patch new file mode 100644 index 0000000..a9fb854 --- /dev/null +++ b/misc/0001-update-for-memory-leaks.patch @@ -0,0 +1,26 @@ +From e3f82dc08568552525527f74632ff09b4561056f Mon Sep 17 00:00:00 2001 +From: "Charlton, Scott R" +Date: Wed, 11 May 2022 20:59:42 -0600 +Subject: [PATCH] update for memory leaks + +--- + SystemTools.cxx | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/SystemTools.cxx b/SystemTools.cxx +index bd900fe..57ef960 100644 +--- a/SystemTools.cxx ++++ b/SystemTools.cxx +@@ -4732,6 +4732,9 @@ SystemToolsManager::~SystemToolsManager() + { + if (--SystemToolsManagerCount == 0) { + SystemTools::ClassFinalize(); ++#if defined(_MSC_VER) ++ _CrtDumpMemoryLeaks(); ++#endif + } + } + +-- +2.27.0.windows.1 +