diff --git a/meson.build b/meson.build index 5307f06a1..20fc56fe0 100644 --- a/meson.build +++ b/meson.build @@ -11,7 +11,7 @@ else endif version_inc = include_directories('.') version_h = custom_target('git_version.h', - command: [version_sh, meson.source_root()], + command: [version_sh, meson.current_build_dir()], build_by_default: true, build_always_stale: true, # has internal check whether target file will be refreshed output: ['git_version.h', 'git_version.xml']) diff --git a/tools/version.ps1 b/tools/version.ps1 index 03d02dbef..0d61c7176 100644 --- a/tools/version.ps1 +++ b/tools/version.ps1 @@ -1,20 +1,32 @@ #!/usr/bin/env powershell + +param ( + [Parameter(Position = 0, Mandatory = $false)] + [string]$BuildRoot = $null +) + $lastSvnRevision = 6962 $lastSvnHash = '16cd907fe7482cb54a7374cd28b8501f138116be' $defineNumberMatch = [regex] '^#define\s+(\w+)\s+(\d+)$' $defineStringMatch = [regex] "^#define\s+(\w+)\s+[`"']?(.+?)[`"']?$" $semVerMatch = [regex] 'v?(\d+)\.(\d+).(\d+)(?:-(\w+))?' - $repositoryRootPath = Join-Path $PSScriptRoot .. | Resolve-Path if (!(git -C $repositoryRootPath rev-parse --is-inside-work-tree 2>$null)) { throw "$repositoryRootPath is not a git repository" } -$gitVersionHeaderPath = Join-Path $repositoryRootPath 'src' | Join-Path -ChildPath 'include' | Join-Path -ChildPath 'aegisub' ` - | Join-Path -ChildPath 'git_version.h' -$gitVersionXmlPath = Join-Path $repositoryRootPath 'packages' | Join-Path -ChildPath 'win_installer' ` - | Join-Path -ChildPath 'git_version.xml' +if ($BuildRoot -eq $null -or $BuildRoot.Trim() -eq "") { + $BuildRoot = $repositoryRootPath +} + +# support legacy in-tree builds +if ([System.IO.Path]::GetFullPath([System.IO.Path]::Combine((pwd).Path, $BuildRoot)) -eq + [System.IO.Path]::GetFullPath([System.IO.Path]::Combine((pwd).Path, $repositoryRootPath))) { + $BuildRoot = Join-Path $repositoryRootPath 'build' + } +$gitVersionHeaderPath = Join-Path $BuildRoot 'git_version.h' +$gitVersionXmlPath = Join-Path $repositoryRootPath 'build' | Join-Path -ChildPath 'git_version.xml' $version = @{} if (Test-Path $gitVersionHeaderPath) {