diff --git a/.travis.yml b/.travis.yml index 4ac22cae..ac3a3808 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,26 @@ git: language: c -os: - - osx - - linux +matrix: + include: + - os: linux + dist: trusty + sudo: required + env: RID=linux-x64 + - os: linux + dist: trusty + sudo: required + env: RID=rhel-x64 + - os: linux + dist: trusty + sudo: required + env: RID=fedora-x64 + - os: linux + dist: trusty + sudo: required + env: RID=debian.9-x64 + - os: osx + env: RID=osx branches: only: @@ -20,6 +37,8 @@ before_install: install: true -script: ./build.libgit2.sh +script: + - if [[ $RID == "osx" ]] || [[ $RID == "linux-x64" ]]; then ./build.libgit2.sh ; fi + - if [[ $RID != "osx" ]] && [[ $RID != "linux-x64" ]]; then ./dockerbuild.sh ; fi after_success: ./uploadbinaries.sh diff --git a/Dockerfile.debian.9-x64 b/Dockerfile.debian.9-x64 new file mode 100644 index 00000000..1d45f939 --- /dev/null +++ b/Dockerfile.debian.9-x64 @@ -0,0 +1,7 @@ +FROM debian:9 +WORKDIR /nativebinaries +COPY . /nativebinaries/ + +RUN apt update && apt -y install cmake gcc libcurl4-openssl-dev libssl-dev pkg-config zlib1g-dev + +CMD ["/bin/bash", "-c", "./build.libgit2.sh"] diff --git a/Dockerfile.fedora-x64 b/Dockerfile.fedora-x64 new file mode 100644 index 00000000..e23af04c --- /dev/null +++ b/Dockerfile.fedora-x64 @@ -0,0 +1,7 @@ +FROM fedora:26 +WORKDIR /nativebinaries +COPY . /nativebinaries/ + +RUN yum -y install cmake gcc libcurl-devel make openssl-devel + +CMD ["/bin/bash", "-c", "./build.libgit2.sh"] diff --git a/Dockerfile.rhel-x64 b/Dockerfile.rhel-x64 new file mode 100644 index 00000000..332752d2 --- /dev/null +++ b/Dockerfile.rhel-x64 @@ -0,0 +1,7 @@ +FROM centos:7 +WORKDIR /nativebinaries +COPY . /nativebinaries/ + +RUN yum -y install cmake gcc libcurl-devel make openssl-devel + +CMD ["/bin/bash", "-c", "./build.libgit2.sh"] diff --git a/UpdateLibgit2ToSha.ps1 b/UpdateLibgit2ToSha.ps1 index 72802528..5a014b05 100644 --- a/UpdateLibgit2ToSha.ps1 +++ b/UpdateLibgit2ToSha.ps1 @@ -98,6 +98,15 @@ Push-Location $libgit2Directory $sha $binaryFilename + + + + + + + + + "@ @@ -105,39 +114,10 @@ Push-Location $libgit2Directory $net461BuildProperties = @" - - `$(MSBuildAllProjects);`$(MSBuildThisFileFullPath) - `$(MSBuildThisFileFullPath) - $sha - $binaryFilename - + - - lib\win32\x64\$binaryFilename.dll - PreserveNewest - - - lib\win32\x64\$binaryFilename.pdb - PreserveNewest - - - lib\win32\x86\$binaryFilename.dll - PreserveNewest - - - lib\win32\x86\$binaryFilename.pdb - PreserveNewest - - - lib\osx\lib$binaryFilename.dylib - PreserveNewest - - - lib\linux\x86_64\lib$binaryFilename.so - PreserveNewest - - - LibGit2Sharp.dll.config + + runtimes\%(RecursiveDir)\%(Filename)%(Extension) PreserveNewest @@ -146,15 +126,6 @@ Push-Location $libgit2Directory Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\build\net461\LibGit2Sharp.NativeBinaries.props") $net461BuildProperties - $dllConfig = @" - - - - -"@ - - Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\libgit2\LibGit2Sharp.dll.config") $dllConfig - Write-Output "Done!" } exit diff --git a/build.libgit2.ps1 b/build.libgit2.ps1 index 6e683e40..badec8e0 100644 --- a/build.libgit2.ps1 +++ b/build.libgit2.ps1 @@ -20,8 +20,8 @@ Set-StrictMode -Version Latest $projectDirectory = Split-Path $MyInvocation.MyCommand.Path $libgit2Directory = Join-Path $projectDirectory "libgit2" -$x86Directory = Join-Path $projectDirectory "nuget.package\runtimes\win7-x86\native" -$x64Directory = Join-Path $projectDirectory "nuget.package\runtimes\win7-x64\native" +$x86Directory = Join-Path $projectDirectory "nuget.package\runtimes\win-x86\native" +$x64Directory = Join-Path $projectDirectory "nuget.package\runtimes\win-x64\native" $hashFile = Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt" $sha = Get-Content $hashFile diff --git a/build.libgit2.sh b/build.libgit2.sh index 61a6b269..80c6950e 100755 --- a/build.libgit2.sh +++ b/build.libgit2.sh @@ -22,27 +22,27 @@ popd OS=`uname` ARCH=`uname -m` - -PACKAGEPATH="nuget.package/libgit2" -LIBEXT="so" -if [ $OS == "Linux" ]; then - if [ "$ARCH" == "x86_64" ]; then - ARCH="x64" +PACKAGEPATH="nuget.package/runtimes" + +if [[ $RID == "" ]]; then + if [[ $ARCH == "x86_64" ]]; then + RID="unix-x64" + else + RID="unix-x86" fi + echo "$(tput setaf 3)RID not defined. Falling back to '$RID'.$(tput sgr0)" +fi - OSPATH="/linux" - ARCHPATH="-$ARCH" -elif [ $OS == "Darwin" ]; then - OSPATH="/osx" +if [[ $OS == "Darwin" ]]; then LIBEXT="dylib" else - OSPATH="/unix" + LIBEXT="so" fi -rm -rf $PACKAGEPATH$OSPATH -mkdir -p $PACKAGEPATH$OSPATH$ARCHPATH/native +rm -rf $PACKAGEPATH/$RID +mkdir -p $PACKAGEPATH/$RID/native -cp libgit2/build/libgit2-$SHORTSHA.$LIBEXT $PACKAGEPATH$OSPATH$ARCHPATH/native +cp libgit2/build/libgit2-$SHORTSHA.$LIBEXT $PACKAGEPATH/$RID/native exit $? diff --git a/buildpackage.ps1 b/buildpackage.ps1 index f5ae3434..12fee1ce 100644 --- a/buildpackage.ps1 +++ b/buildpackage.ps1 @@ -8,30 +8,4 @@ $buildDate = (Get-Date).ToUniversalTime().ToString("yyyyMMddHHmmss") $versionSuffix = "" if ($pre.IsPresent) { $versionSuffix = "-pre$BuildDate" } -$projectDirectory = Split-Path $MyInvocation.MyCommand.Path -$x86Directory = Join-Path $projectDirectory "nuget.package\runtimes\win7-x86\native" -$x64Directory = Join-Path $projectDirectory "nuget.package\runtimes\win7-x64\native" -$osxDirectory = Join-Path $projectDirectory "nuget.package\runtimes\osx\native" -$linuxDirectory = Join-Path $projectDirectory "nuget.package\runtimes\linux-x64\native" - -if ( -Not (Test-Path $x86Directory\*.dll) ) -{ - mkdir -fo $x86Directory > $null -} - -if ( -Not (Test-Path $x64Directory\*.dll) ) -{ - mkdir -fo $x64Directory > $null -} - -if ( -Not (Test-Path $osxDirectory\*.dylib) ) -{ - mkdir -fo $osxDirectory > $null -} - -if ( -Not (Test-Path $linuxDirectory\*.so) ) -{ - mkdir -fo $linuxDirectory > $null -} - .\nuget.exe Pack nuget.package\NativeBinaries.nuspec -Version $version$versionSuffix -NoPackageAnalysis diff --git a/dockerbuild.sh b/dockerbuild.sh new file mode 100755 index 00000000..d3195565 --- /dev/null +++ b/dockerbuild.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +docker build -t $RID -f Dockerfile.$RID . + +docker run -it -e RID=$RID --name=$RID $RID + +docker cp $RID:/nativebinaries/nuget.package/runtimes nuget.package + +docker rm $RID diff --git a/download.build.artifacts.and.package.ps1 b/download.build.artifacts.and.package.ps1 index 4406d7dc..d9c9b358 100644 --- a/download.build.artifacts.and.package.ps1 +++ b/download.build.artifacts.and.package.ps1 @@ -1,5 +1,5 @@ Param( - [string]$ref = "master", + [string]$ref = "master", [switch]$verbose = $False ) @@ -9,95 +9,98 @@ $ErrorActionPreference = "Stop" function Invoke-RestMethod-Ex($url, $downloadLocation) { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 - $irmParams = @{ - } + $irmParams = @{ + } - Write-Host -ForegroundColor "White" "-> Get $url" + Write-Host -ForegroundColor "White" "-> Get $url" - $proxy = [System.Net.WebRequest]::GetSystemWebProxy() - if ($proxy) { - $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials - $proxyUri = $proxy.GetProxy("$url") + $proxy = [System.Net.WebRequest]::GetSystemWebProxy() + if ($proxy) { + $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials + $proxyUri = $proxy.GetProxy("$url") - if ("$proxyUri" -ne "$url") { - $irmParams.Proxy = "$proxyUri" - $irmParams.ProxyUseDefaultCredentials = $true + if ("$proxyUri" -ne "$url") { + $irmParams.Proxy = "$proxyUri" + $irmParams.ProxyUseDefaultCredentials = $true + } } - } - if ($downloadLocation) { - $irmParams.OutFile = "$downloadLocation" - } + if ($downloadLocation) { + $irmParams.OutFile = "$downloadLocation" + } - $output = Invoke-RestMethod @irmParams -ContentType "application/json" -Method "Get" -Uri "$url" + $output = Invoke-RestMethod @irmParams -ContentType "application/json" -Method "Get" -Uri "$url" - if ($verbose) { - Write-Host -ForegroundColor "Gray" "output = $(ConvertTo-Json $output)" - } + if ($verbose) { + Write-Host -ForegroundColor "Gray" "output = $(ConvertTo-Json $output)" + } - return $output + return $output } function Extract-BuildIdentifier($statuses, $forContext) { - $status = $statuses | where { $_.context -eq $forContext } | select -First 1 + $status = $statuses | where { $_.context -eq $forContext } | select -First 1 - if (($status -eq $null) -or ("success".CompareTo($status.state) -ne 0)) { - throw "No successful status has been found for context `"$forContext`"." - } + if (($status -eq $null) -or ("success".CompareTo($status.state) -ne 0)) { + throw "No successful status has been found for context `"$forContext`"." + } - $buildNumber = $status.target_url.Split("/")[-1] + $buildNumber = $status.target_url.Split("/")[-1] - return $buildNumber + return $buildNumber } function Download-AppVeyor-Artifacts($statuses, $downloadLocation) { - $prOrBranch = "branch" + $prOrBranch = "branch" - if ($ref.StartsWith("pull/")) { - $prOrBranch = "pr" - } + if ($ref.StartsWith("pull/")) { + $prOrBranch = "pr" + } - $buildIdentifier = Extract-BuildIdentifier $statuses "continuous-integration/appveyor/$prOrBranch" + $buildIdentifier = Extract-BuildIdentifier $statuses "continuous-integration/appveyor/$prOrBranch" - Write-Host -ForegroundColor "Yellow" "Retrieving AppVeyor build `"$buildIdentifier`"" - $build = Invoke-RestMethod-Ex "https://ci.appveyor.com/api/projects/libgit2/libgit2sharp-nativebinaries/build/$buildIdentifier" + Write-Host -ForegroundColor "Yellow" "Retrieving AppVeyor build `"$buildIdentifier`"" + $build = Invoke-RestMethod-Ex "https://ci.appveyor.com/api/projects/libgit2/libgit2sharp-nativebinaries/build/$buildIdentifier" - $jobId = $build.build.jobs[0].jobId + $jobId = $build.build.jobs[0].jobId - Write-Host -ForegroundColor "Yellow" "Retrieving AppVeyor job `"$jobId`" artifacts" - $artifacts = Invoke-RestMethod-Ex "https://ci.appveyor.com/api/buildjobs/$jobId/artifacts" + Write-Host -ForegroundColor "Yellow" "Retrieving AppVeyor job `"$jobId`" artifacts" + $artifacts = Invoke-RestMethod-Ex "https://ci.appveyor.com/api/buildjobs/$jobId/artifacts" - ForEach ($artifact in $artifacts) { - $artifactFileName = $artifacts[0].fileName - $localArtifactPath = "$downloadLocation\$artifactFileName" + ForEach ($artifact in $artifacts) { + $artifactFileName = $artifacts[0].fileName + $localArtifactPath = "$downloadLocation\$artifactFileName" - Write-Host -ForegroundColor "Yellow" "Downloading `"$artifactFileName`"" - Invoke-RestMethod-Ex "https://ci.appveyor.com/api/buildjobs/$jobId/artifacts/$artifactFileName" $localArtifactPath - } + Write-Host -ForegroundColor "Yellow" "Downloading `"$artifactFileName`"" + Invoke-RestMethod-Ex "https://ci.appveyor.com/api/buildjobs/$jobId/artifacts/$artifactFileName" $localArtifactPath + } } function Download-Travis-Artifacts($statuses, $downloadLocation) { - $prOrBranch = "push" + $prOrBranch = "push" - if ($ref.StartsWith("pull/")) { - $prOrBranch = "pr" - } + if ($ref.StartsWith("pull/")) { + $prOrBranch = "pr" + } + + $buildIdentifier = Extract-BuildIdentifier $statuses "continuous-integration/travis-ci/$prOrBranch" - $buildIdentifier = Extract-BuildIdentifier $statuses "continuous-integration/travis-ci/$prOrBranch" + Write-Host -ForegroundColor "Yellow" "Retrieving Travis build `"$buildIdentifier`"" + $build = Invoke-RestMethod-Ex "https://api.travis-ci.org/builds/$buildIdentifier" - Write-Host -ForegroundColor "Yellow" "Retrieving Travis build `"$buildIdentifier`"" - $build = Invoke-RestMethod-Ex "https://api.travis-ci.org/builds/$buildIdentifier" + $buildNumber = $build.number - $buildNumber = $build.number + Write-Host -ForegroundColor "Yellow" "Retrieving Bintray version `"$buildNumber`" artifact list" + $files = Invoke-RestMethod-Ex "https://api.bintray.com/packages/libgit2/compiled-binaries/libgit2/versions/$buildNumber/files" - ForEach ($platform in @("linux", "osx")) { - $artifactFileName = "binaries-$platform-$buildNumber.zip" - $localArtifactPath = "$downloadLocation\$artifactFileName" + ForEach ($file in $files) { + $artifactFileName = $file.name + $localArtifactPath = "$downloadLocation\$artifactFileName" - Write-Host -ForegroundColor "Yellow" "Downloading `"$artifactFileName`"" - Invoke-RestMethod-Ex "https://dl.bintray.com/libgit2/compiled-binaries/$artifactFileName" $localArtifactPath - } + Write-Host -ForegroundColor "Yellow" "Downloading `"$artifactFileName`"" + Invoke-RestMethod-Ex "https://dl.bintray.com/libgit2/compiled-binaries/$artifactFileName" $localArtifactPath + } } ###################################################### @@ -109,13 +112,14 @@ Write-Host -ForegroundColor "Yellow" "Creating temporary folder at `"$path`"" New-Item "$path" -type Directory > $null if ($ref.StartsWith("pull/")) { - $pr = $ref.Replace("pull/", "") - Write-Host -ForegroundColor "Yellow" "Retrieving pull request information for pull request $pr" + $pr = $ref.Replace("pull/", "") + Write-Host -ForegroundColor "Yellow" "Retrieving pull request information for pull request $pr" - $prData = Invoke-RestMethod-Ex "https://api.github.com/repos/libgit2/libgit2sharp.nativebinaries/pulls/$pr" - $statusesUrl = $prData.statuses_url -} else { - $statusesUrl = "https://api.github.com/repos/libgit2/libgit2sharp.nativebinaries/commits/$ref/statuses" + $prData = Invoke-RestMethod-Ex "https://api.github.com/repos/libgit2/libgit2sharp.nativebinaries/pulls/$pr" + $statusesUrl = $prData.statuses_url +} +else { + $statusesUrl = "https://api.github.com/repos/libgit2/libgit2sharp.nativebinaries/commits/$ref/statuses" } Write-Host -ForegroundColor "Yellow" "Retrieving LibGit2Sharp.NativeBinaries latest CI statuses of `"$ref`"" @@ -127,18 +131,15 @@ Download-Travis-Artifacts $statuses $path Write-Host -ForegroundColor "Yellow" "Build artifacts have been downloaded at `"$path`"" $package = Get-ChildItem -Path $path -Filter "*.nupkg" -$linuxBins = Get-ChildItem -Path $path -Filter "binaries-linux-*.zip" -$osxBins = Get-ChildItem -Path $path -Filter "binaries-osx-*.zip" +$binaries = Get-ChildItem -Path $path -Filter "*.zip" Write-Host -ForegroundColor "Yellow" "Extracting build artifacts" -Add-Type -assembly "System.Io.Compression.Filesystem" -[Io.Compression.ZipFile]::ExtractToDirectory("$($package.FullName)", "$($package.FullName).ext") -[Io.Compression.ZipFile]::ExtractToDirectory("$($linuxBins.FullName)", "$($linuxBins.FullName).ext") -[Io.Compression.ZipFile]::ExtractToDirectory("$($osxBins.FullName)", "$($osxBins.FullName).ext") - -Write-Host -ForegroundColor "Yellow" "Including non Windows build artifacts" -Move-Item "$($linuxBins.FullName).ext\libgit2\linux-x64\native\*.so" "$($package.FullName).ext\runtimes\linux-x64\native" -Move-Item "$($osxBins.FullName).ext\libgit2\osx\native\*.dylib" "$($package.FullName).ext\runtimes\osx\native" +Add-Type -assembly "System.IO.Compression.Filesystem" +[IO.Compression.ZipFile]::ExtractToDirectory("$($package.FullName)", "$($package.FullName).ext") + +ForEach ($binary in $binaries) { + [IO.Compression.ZipFile]::ExtractToDirectory("$($binary.FullName)", "$($package.FullName).ext") +} Write-Host -ForegroundColor "Yellow" "Building final NuGet package" Push-location "$($package.FullName).ext" diff --git a/nuget.package/build/LibGit2Sharp.NativeBinaries.props b/nuget.package/build/LibGit2Sharp.NativeBinaries.props index ee6b4ce3..ae56cc42 100644 --- a/nuget.package/build/LibGit2Sharp.NativeBinaries.props +++ b/nuget.package/build/LibGit2Sharp.NativeBinaries.props @@ -1,8 +1,17 @@ - + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) $(MSBuildThisFileFullPath) 6311e886d8b5377c6037cd9937ccf66a71f3361d git2-6311e88 + + + + + + + + + diff --git a/nuget.package/build/net461/LibGit2Sharp.NativeBinaries.props b/nuget.package/build/net461/LibGit2Sharp.NativeBinaries.props index d1bbe3ea..06276016 100644 --- a/nuget.package/build/net461/LibGit2Sharp.NativeBinaries.props +++ b/nuget.package/build/net461/LibGit2Sharp.NativeBinaries.props @@ -1,37 +1,8 @@ - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - $(MSBuildThisFileFullPath) - 6311e886d8b5377c6037cd9937ccf66a71f3361d - git2-6311e88 - + + - - lib\win32\x64\git2-6311e88.dll - PreserveNewest - - - lib\win32\x64\git2-6311e88.pdb - PreserveNewest - - - lib\win32\x86\git2-6311e88.dll - PreserveNewest - - - lib\win32\x86\git2-6311e88.pdb - PreserveNewest - - - lib\osx\libgit2-6311e88.dylib - PreserveNewest - - - lib\linux\x86_64\libgit2-6311e88.so - PreserveNewest - - - LibGit2Sharp.dll.config + + runtimes\%(RecursiveDir)\%(Filename)%(Extension) PreserveNewest diff --git a/nuget.package/libgit2/LibGit2Sharp.dll.config b/nuget.package/libgit2/LibGit2Sharp.dll.config deleted file mode 100644 index ac208153..00000000 --- a/nuget.package/libgit2/LibGit2Sharp.dll.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/uploadbinaries.sh b/uploadbinaries.sh index 95723a7f..e6eb33aa 100755 --- a/uploadbinaries.sh +++ b/uploadbinaries.sh @@ -4,13 +4,13 @@ if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then pushd nuget.package -zip -r binaries.zip libgit2 +zip -r binaries.zip runtimes BINTRAY_API_USER="nulltoken" -curl -T binaries.zip -u$BINTRAY_API_USER:$BINTRAY_API_KEY https://api.bintray.com/content/libgit2/compiled-binaries/$TRAVIS_OS_NAME/$TRAVIS_BUILD_NUMBER/binaries-$TRAVIS_OS_NAME-$TRAVIS_BUILD_NUMBER.zip?publish=1 +curl -T binaries.zip -u$BINTRAY_API_USER:$BINTRAY_API_KEY https://api.bintray.com/content/libgit2/compiled-binaries/libgit2/$TRAVIS_BUILD_NUMBER/binaries-$RID-$TRAVIS_BUILD_NUMBER.zip?publish=1 -printf "\n\n-> https://dl.bintray.com/libgit2/compiled-binaries/binaries-%s-%s.zip\n\n" "$TRAVIS_OS_NAME" "$TRAVIS_BUILD_NUMBER" +printf "\n\n-> https://dl.bintray.com/libgit2/compiled-binaries/binaries-%s-%s.zip\n\n" "$RID" "$TRAVIS_BUILD_NUMBER" popd