Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated MS Windows builds #101

Merged
merged 9 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ test/config/*.tar

# JIT
**/*.bc
x64/
Debug/
Release/
.vs/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ODBC FDW for PostgreSQL 9.5+ [![Build Status](https://travis-ci.org/CartoDB/odbc_fdw.svg?branch=master)](https://travis-ci.org/CartoDB/odbc_fdw)
ODBC FDW for PostgreSQL 9.5+
============================
[![Travis Build Status](https://travis-ci.org/CartoDB/odbc_fdw.svg?branch=master)](https://travis-ci.org/CartoDB/odbc_fdw)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/mlt/odbc_fdw?branch=appveyor&svg=true)](https://ci.appveyor.com/project/PurpleI2P/odbc-fdw "Get your fresh Windows build here!")

This PostgreSQL extension implements a Foreign Data Wrapper (FDW) for
remote databases using Open Database Connectivity [ODBC](http://msdn.microsoft.com/en-us/library/ms714562(v=VS.85).aspx).
Expand Down
115 changes: 115 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
pull_requests:
do_not_increment_build_number: true
os: Visual Studio 2017
configuration: Release
platform: x64
clone_depth: 1
services:
- mysql
- mssql2017
environment:
PGUSER: postgres
PGPASSWORD: Password12!
MYSQL_PWD: Password12!
SQLCMDPASSWORD: Password12!
matrix:
- pg: 11.5-2
PlatformToolset: v140
- pg: 12.0-1
PlatformToolset: v141
- pg: master
PlatformToolset: v141
configuration: Debug
matrix:
allow_failures:
- pg: master

init: # Make %exe% available for caching
- ps: |
if ("$env:PLATFORM" -eq "x64") {
$env:pf = "$env:ProgramFiles"
$env:x64 = "-x64"
} else {
$env:pf = "${env:ProgramFiles(x86)}"
}
$env:exe = "postgresql-$env:pg-windows$env:x64.exe"
[Environment]::SetEnvironmentVariable("exe", $env:exe, "Machine")

install:
- ps: |
# http://www.databasesoup.com/2016/05/changing-postgresql-version-numbering.html
$env:pgversion = $env:pg -replace "\.\d+-\d+$", ""
# [Environment]::SetEnvironmentVariable("pgversion", $env:pgversion, "Machine")
$env:pgroot = "$env:pf\PostgreSQL\$env:pgversion"
if ("$env:pg" -notmatch "\.") {
$env:Path += ";C:\msys64\usr\bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64"
git clone -q --depth 1 --branch $env:pg https://git.postgresql.org/git/postgresql.git c:\projects\postgresql
pushd c:\projects\postgresql
perl src\tools\msvc\build.pl
perl src\tools\msvc\install.pl "$env:pgroot"
popd
} else {
if (-not (Test-Path "$env:pgroot\bin")) {
if (-not (Test-Path "$env:exe")) {
Start-FileDownload "http://get.enterprisedb.com/postgresql/$env:exe"
}
& ".\$env:exe" --unattendedmodeui none --mode unattended --superpassword "$env:PGPASSWORD" --servicepassword "$env:PGPASSWORD" | Out-Null
Stop-Service "postgresql$env:x64-$env:pgversion"
}
}

cache:
- '%exe%'
- psqlodbc_x64.msi

build_script:
- msbuild /p:PlatformToolset=%PlatformToolset% /p:configuration=%CONFIGURATION% /p:platform=%PLATFORM%
odbc_fdw.vcxproj
/verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"

after_build:
- ps: |
$dll = ($env:PLATFORM -replace "x86", ".") + "\$env:CONFIGURATION\odbc_fdw.dll"
Add-AppveyorMessage Packing -Category Information
New-Item -Name tmp\share\extension -ItemType "directory"
Copy-Item "*.sql" -Destination tmp\share\extension\
Copy-Item "*.control" -Destination tmp\share\extension\
Copy-Item LICENSE -Destination tmp\ODBC_FDW_LICENSE
New-Item -Name tmp\lib -ItemType "directory"
New-Item -Name tmp\debug_symbols -ItemType "directory"
Copy-Item $dll -Destination tmp\lib
Copy-Item ($dll -replace "\.dll", ".pdb") -Destination tmp\debug_symbols
if ($env:APPVEYOR_REPO_TAG -eq "false") {
$env:APPVEYOR_REPO_TAG_NAME=${env:APPVEYOR_REPO_COMMIT}.SubString(0,8)
}
$zip = "odbc_fdw-$env:APPVEYOR_REPO_TAG_NAME-pg$env:pgversion-windows-$env:PLATFORM.zip"
Compress-Archive -Path ".\tmp\*" -DestinationPath $zip

test_script:
- ps: |
$env:path += ";$env:pgroot\bin"
Add-AppveyorMessage "Copying the extension files to the PostgreSQL directories." -Category Information
Expand-Archive -LiteralPath $zip -DestinationPath $env:pgroot
if ("$env:pg" -notmatch "\.") {
Set-Content -path pg.pass -value "$env:pgpassword" -encoding ascii
initdb -A md5 -U "$env:PGUSER" --pwfile=pg.pass C:\pgdata
pg_ctl register -S demand -N "postgresql$env:x64-$env:pgversion" -D c:\pgdata
}
Start-Service postgresql$env:x64-$env:pgversion
& .\test\appveyor_tests.ps1

artifacts:
- path: '*.zip'

deploy:
# Deploy to GitHub Releases
- provider: GitHub
draft: false
prerelease: false
auth_token:
secure: QR7uEDoDDcUclQhaQDdbymUotMh1Gq++D+ljzKGC4a1Y9hr6BszPYRcLy9i0HJ/k
on:
appveyor_repo_tag: true # deploy on tag push only

# on_finish:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
19 changes: 14 additions & 5 deletions odbc_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
#include "access/table.h"
#endif

#if defined(_WIN32)
#define strcasecmp _stricmp
#endif

/* TupleDescAttr was backported into 9.5.9 and 9.6.5 but we support any 9.5.X */
#ifndef TupleDescAttr
#define TupleDescAttr(tupdesc, i) ((tupdesc)->attrs[(i)])
Expand Down Expand Up @@ -173,11 +177,11 @@ typedef enum { TEXT_CONVERSION, HEX_CONVERSION, BIN_CONVERSION, BOOL_CONVERSION
/*
* SQL functions
*/
extern Datum odbc_fdw_handler(PG_FUNCTION_ARGS);
extern Datum odbc_fdw_validator(PG_FUNCTION_ARGS);
extern Datum odbc_tables_list(PG_FUNCTION_ARGS);
extern Datum odbc_table_size(PG_FUNCTION_ARGS);
extern Datum odbc_query_size(PG_FUNCTION_ARGS);
PGDLLEXPORT Datum odbc_fdw_handler(PG_FUNCTION_ARGS);
PGDLLEXPORT Datum odbc_fdw_validator(PG_FUNCTION_ARGS);
PGDLLEXPORT Datum odbc_tables_list(PG_FUNCTION_ARGS);
PGDLLEXPORT Datum odbc_table_size(PG_FUNCTION_ARGS);
PGDLLEXPORT Datum odbc_query_size(PG_FUNCTION_ARGS);

PG_FUNCTION_INFO_V1(odbc_fdw_handler);
PG_FUNCTION_INFO_V1(odbc_fdw_validator);
Expand Down Expand Up @@ -2036,6 +2040,7 @@ odbcImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
* in that case we must avoid using an schema to query the table columns.
*/
schema_name = NULL;
missing_foreign_schema = false;
}

/* Since we haven't specified SQL_ALL_CATALOGS in the
Expand Down Expand Up @@ -2150,7 +2155,11 @@ odbcImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
int option_count = 0;
const char *prefix = empty_string_if_null(options.prefix);

#if PG_VERSION_NUM >= 130000
table_columns_cell = lnext(table_columns, table_columns_cell);
#else
table_columns_cell = lnext(table_columns_cell);
#endif

initStringInfo(&create_statement);
appendStringInfo(&create_statement, "CREATE FOREIGN TABLE \"%s\".\"%s%s\" (", stmt->local_schema, prefix, (char *) table_name);
Expand Down
77 changes: 77 additions & 0 deletions odbc_fdw.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{2EB5E1F5-F370-4367-9BAD-CD241B28434C}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>odbc_fdw</RootNamespace>
<PlatformToolset>v140</PlatformToolset>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CustomBuildBeforeTargets>Link</CustomBuildBeforeTargets>
<WholeProgramOptimization Condition="'$(Configuration)'=='Release'">true</WholeProgramOptimization>
<pf>$(ProgramFiles)</pf>
<pf Condition="$(Platform)=='x64'">$(ProgramW6432)</pf>
</PropertyGroup>
<PropertyGroup Label="UserMacros">
<pgversion Condition="$(pgversion) == ''">11</pgversion>
<pgroot Condition="$(pgroot)==''">$(pf)\PostgreSQL\$(pgversion)</pgroot>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<PropertyGroup>
<IncludePath>$(pgroot)\include;$(pgroot)\include\server;$(pgroot)\include\server\port\win32;$(pgroot)\include\server\port\win32_msvc;$(IncludePath)</IncludePath>
<LibraryPath>$(pgroot)\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<CompileAs>CompileAsC</CompileAs>
<ExceptionHandling>false</ExceptionHandling>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ClCompile Condition="$(Configuration)=='Release'">
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<IntrinsicFunctions>true</IntrinsicFunctions>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<StringPooling>true</StringPooling>
</ClCompile>
<ClCompile Condition="$(Configuration)=='Debug'">
<Optimization>Disabled</Optimization>
<MinimalRebuild>true</MinimalRebuild>
<BrowseInformation Condition="$(CI)==''">true</BrowseInformation>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PreprocessorDefinitions>DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>postgres.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<FullProgramDatabaseFile>true</FullProgramDatabaseFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="odbc_fdw.c" />
</ItemGroup>
</Project>
85 changes: 85 additions & 0 deletions test/appveyor_tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Taken from https://deadroot.info/scripts/2018/09/04/PowerShell-Templating
function Merge-Tokens($template, $tokens)
{
return [regex]::Replace(
$template,
'\$\{(?<tokenName>\w+)\}',
{
param($match)
$tokenName = $match.Groups['tokenName'].Value
return $tokens[$tokenName]
})
}

# https://www.appveyor.com/docs/services-databases
$Config = @{
mysql = @{
driver = 'MySQL ODBC 5.3 Unicode Driver'
host = 'localhost'
port = '3306'
dbname = 'fdw_tests'
encoding = 'utf8'
user = 'root'
password = 'Password12!'
}
postgres = @{
driver = 'PostgreSQL Unicode(x64)'
host = 'localhost'
port = '5432'
dbname = 'fdw_tests'
user = 'postgres'
password = 'Password12!'
}
sqlserver = @{
driver = 'ODBC Driver 13 for SQL Server'
host = '(local)\SQL2017'
port = '1433'
dbname = 'master'
user = 'sa'
password = 'Password12!'
}
}

foreach ($c in $Config.GetEnumerator()) {
$tpl = Get-Content "$PSScriptRoot\template\$($c.Name)_installation_test.tpl" -Raw
$generated_test = Merge-Tokens $tpl $($c.Value)
Set-Content -Path "$PSScriptRoot\sql/$($c.Name)_10_installation_test.sql" -Value $generated_test
Set-Content -Path "$PSScriptRoot\expected\$($c.Name)_10_installation_test.out" -Value $generated_test
}

$env:Path += ";C:\Program Files\MySQL\MySQL Server 5.7\bin"
& mysql -e "create database fdw_tests character set utf8mb4 collate utf8mb4_unicode_ci;" --user=root
& cmd.exe /c 'mysql fdw_tests --user=root < test\fixtures\mysql_fixtures.sql'
& createdb fdw_tests
& psql -f test\fixtures\postgres_fixtures.sql fdw_tests postgres 2>&1 |
%{ if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.Exception.Message } else { $_ } } |
Out-Default
& sqlcmd -S "(local)\SQL2017" -U "sa" -d master -i "$PSScriptRoot\fixtures\sqlserver_fixtures.sql"
Rename-Item -Path "$PSScriptRoot\sql\sqlserver_20_query_test_disabled.sql" -NewName "sqlserver_20_query_test.sql"

if (-not (Test-Path "$PSScriptRoot\..\psqlodbc_x64.msi")) {
Start-FileDownload "https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_12_00_0000-x64.zip"
Expand-Archive -LiteralPath psqlodbc_12_00_0000-x64.zip -DestinationPath .
Remove-Item psqlodbc_12_00_0000-x64.zip
}
& msiexec /i psqlodbc_x64.msi /qn /quiet

Add-AppveyorTest Regression -Framework pg_regress -FileName sql\ -Outcome Running
$env:Outcome="Passed"
$elapsed=(Measure-Command {
pg_regress "--bindir=$env:pgroot\bin" --inputdir=test --outputdir=test --load-extension=odbc_fdw --dbname=regression `
mysql_10_installation_test mysql_20_query_test `
postgres_10_installation_test postgres_20_query_test `
sqlserver_10_installation_test sqlserver_20_query_test `
2>&1 |
%{ if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.Exception.Message } else { $_ } } |
Out-Default
if ($LASTEXITCODE -ne 0) {
$env:Outcome="Failed"
}
}).TotalMilliseconds
Update-AppVeyorTest Regression -Framework pg_regress -FileName sql\ -Outcome "$env:Outcome" -Duration $elapsed
if ("$env:Outcome" -ne "Passed") {
type test\regression.diffs
$host.SetShouldExit($LastExitCode)
}