Permalink
Browse files

Better tool discovery and checking in the wrapper

Make the perl wrapper script search for more tools
in well-known paths, and make sure it tests all the
build tools, not just the language interpreters.

Also resolves an issue with stdout from the build
with some configurations.
  • Loading branch information...
1 parent 2df2451 commit 809385c0d0c4066fdffb06c60b6afeaac95032de @ringerc ringerc committed Jan 23, 2013
Showing with 202 additions and 55 deletions.
  1. +0 −3 Makefile
  2. +114 −26 PgBuildWin/Config.pm
  3. +9 −1 PgBuildWin/DetectSDK.pm
  4. +33 −0 PgBuildWin/SilentInstallTools.pm
  5. +23 −11 README.md
  6. +5 −4 configpl.mak
  7. +10 −2 postgresql.mak
  8. +8 −8 zlib.mak
View
@@ -60,9 +60,6 @@ TCLDIR=$(TCL_X64)
default: postgresql
-$(WGET) $(BISON) $(FLEX) $(TOUCH):
- $(MINGW)\bin\mingw-get install msys msys-wget msys-bison msys-flex
-
phony:
!INCLUDE zlib.mak
View
@@ -6,6 +6,7 @@ use Exporter;
use File::Spec::Functions qw/catfile catdir devnull/;
use IPC::Open3 qw( open3 );
use FindBin qw($Bin);
+use File::Basename qw/dirname/;
our $VERSION = 1.00;
our @ISA = qw(Exporter);
@@ -24,6 +25,14 @@ sub set_ind($$$) {
}
};
+sub set_ind_path($$$) {
+ # Same as set_ind, but only sets default if the path actually exists
+ my ($h, $k, $v) = @_;
+ if (-e $k) {
+ set_ind($h,$k,$v);
+ }
+}
+
sub test_cmd($) {
my $cmd = $_[0];
open(local *NUL, '>', devnull()) or die;
@@ -78,7 +87,32 @@ sub find_git() {
) {
return $git if test_cmd('"' . $git . '" --version');
}
- return;
+ return undef;
+}
+
+sub find_7zip($) {
+ my $ma = $_[0];
+ my $sevenz;
+ foreach $sevenz (
+ '7z',
+ '7za',
+ catfile($ENV{'ProgramFiles'}, '7-Zip','7z.exe'),
+ catfile($ENV{'ProgramFiles(x86)'}, '7-Zip','7z.exe')
+ ) {
+ if (test_cmd('"' . $sevenz . '"')) {
+ $ma->{'7ZIP'} = $sevenz;
+ return 1;
+ }
+ }
+}
+
+sub add_util_to_path($) {
+ my $cmd = $_[0];
+ my $cmddir = dirname($cmd);
+ if ( ($cmddir ne '.') && (index($ENV{'PATH'}, $cmddir) == -1) ) {
+ $ENV{PATH} .= ';' . $cmddir;
+ print("Added " . $cmddir . " to PATH\n");
+ }
}
# Pass a reference to the config hash to merge_defaults
@@ -90,15 +124,18 @@ sub merge_defaults($$) {
unless defined($cfg->{'makeargs'});
my $ma = $cfg->{'makeargs'};
- set_ind($ma, 'TARGET_CPU', $ENV{'TARGET_CPU'});
+ set_ind($ma, 'TARGET_CPU', defined($ENV{'TARGET_CPU'}) ? $ENV{'TARGET_CPU'} : '');
my $cpu = lc($ma->{'TARGET_CPU'});
- if (!defined($cpu)) {
- die("TARGET_CPU isn't defined in settings.pl or the environment. Did you run vcvars or setenv.cmd?");
+ if (!defined($cpu) || $cpu eq '') {
+ die("TARGET_CPU isn't defined in settings.pl or the environment. See README.");
+ }
+
+ set_ind($ma, 'CONFIGURATION', defined($ENV{'CONFIGURATION'}) ? $ENV{'CONFIGURATION'} : '');
+ if ($ma->{'CONFIGURATION'} eq '') {
+ die("CONFIGURATION isn't defined in settings.pl or the environment. See README.");
}
die("Don't set USE_GIT in settings.pl; use buildgit.pl instead.") if exists($ma->{'USE_GIT'});
-
- set_ind($ma, 'CONFIGURATION', $ENV{'CONFIGURATION'});
set_ind($ma, 'LIBDIR', '\pg\libs');
set_ind($ma, 'PKGDIR', catdir($ma->{'LIBDIR'}, 'pkgs'));
@@ -114,7 +151,7 @@ sub merge_defaults($$) {
}
} else {
# Unset git-related params if USE_GIT is not set
- delete $ma->{'GIT'};
+ # but keep the GIT path; we'll use it later
delete $ma->{'GIT_PULL'};
delete $ma->{'PG_GIT_URL'};
delete $ma->{'PGDIR'};
@@ -138,11 +175,6 @@ sub merge_defaults($$) {
} else {
die("Unknown TARGET_CPU $cpu");
}
-
- set_ind($ma, 'MINGW', catdir($ma->{'TOOLPREFIX'}, 'MinGW'));
- set_ind($ma, 'MSYS', catdir($ma->{'MINGW'}, 'msys', '1.0'));
- # you can also use 7za, the standalone 7zip, here.
- set_ind($ma, '7ZIP', catfile($ENV{'ProgramFiles'}, '7-Zip','7z.exe'));
# Tools the scripts can download and install
# for you.
@@ -152,15 +184,75 @@ sub merge_defaults($$) {
# Override this to specify a particular perl executable
set_ind($ma, 'PERL_CMD', 'perl');
- # Where to find wget for downloading sources
- # TODO: Do downloads with Perl instead
- set_ind($ma, 'WGET', catfile($ma->{'MSYS'}, 'bin', 'wget.exe'));
-
- # FIXME: currently we don't respect $(FLEX) and $(BISON)
- # We assume they're in the msys directory.
- set_ind($ma, 'FLEX', catfile($ma->{'MSYS'}, 'bin', 'flex.exe'));
- set_ind($ma, 'BISON', catfile($ma->{'MSYS'}, 'bin', 'bison.exe'));
- set_ind($ma, 'TOUCH', catfile($ma->{'MSYS'}, 'bin', 'touch.exe'));
+ set_ind_path($ma, 'MINGW', catdir($ma->{'TOOLPREFIX'}, 'MinGW'));
+ set_ind_path($ma, 'MSYS', catdir($ma->{'MINGW'}, 'msys', '1.0'));
+
+ # Look for flex, curl, bison and touch in msysgit, then if not found in
+ # mingw.
+ my $cmd;
+ foreach $cmd ('flex', 'bison', 'touch','curl', 'tee') {
+ if (!defined($ma->{uc($cmd)})) {
+ if (test_cmd("\"$cmd\" --version")) {
+ print("Detected $cmd on PATH\n");
+ $ma->{uc($cmd)} = $cmd;
+ next;
+ }
+ if (defined($ma->{'GIT'})) {
+ # Why shortpaths? Bison may misbehave if the path has spaces in it.
+ my $cmdpath = Win32::GetShortPathName(catfile(dirname($ma->{'GIT'}),$cmd . '.exe'));
+ if (test_cmd("\"$cmdpath\" --version")) {
+ print("Detected $cmd at $cmdpath\n");
+ $ma->{uc($cmd)} = $cmdpath;
+ next;
+ }
+ }
+ if (defined($ma->{'MINGW'})) {
+ my $cmdpath = Win32::GetShortPathName(catfile($ma->{'MINGW'}, $cmd . '.exe'));
+ if (test_cmd("\"$cmdpath\" --version")) {
+ print("Detected $cmd at $cmdpath\n");
+ $ma->{uc($cmd)} = $cmdpath;
+ next;
+ }
+ }
+ }
+ }
+
+ foreach $cmd ('flex', 'bison', 'touch','curl') {
+ if (!defined($ma->{uc($cmd)})) {
+ die('Could not find usable ' . uc($cmd) . '. Looked in MAKEARGS, git install, mingw. See README.');
+ }
+ if (!test_cmd("\"$ma->{uc($cmd)}\" --version")) {
+ die("Expected usable $cmd at $ma->{uc($cmd)}, cannot proceed with build. See README.\n");
+ }
+ }
+
+ if ($ma->{'BISON'} =~ / /) {
+ my $shortbison = Win32::GetShortPathName($ma->{'BISON'});
+ if ($shortbison =~ / /) {
+ print("---------------------------------------------\n");
+ print("WARNING: Path to bison has spaces in the name, malfunction is highly likely\n");
+ print("Press control-C to abort the build; it will continue in 2 seconds\n");
+ print("---------------------------------------------\n");
+ sleep(2);
+ } else {
+ print("WARNING: bison path has spaces in it. Converting to shortname form $shortbison\n");
+ $ma->{'BISON'} = $shortbison;
+ }
+ sleep(5);
+ }
+
+ # The PostgreSQL build expects flex and bison to be on the PATH; it can't take their locations
+ # via an env var, because pgflex.pl and pgbison.pl just assume a bare command. Extract the paths
+ # and inject them into the environment.
+ add_util_to_path($ma->{'FLEX'});
+ add_util_to_path($ma->{'BISON'});
+
+ # you can also use 7za, the standalone 7zip, here.
+ if (!defined($ma->{'7ZIP'})) {
+ find_7zip($ma) or die ("7ZIP not in MAKEARGS and not found in well known locations. See README.\n");
+ } elsif (!test_cmd('"' . $ma->{'7ZIP'} . '"')) {
+ die("7ZIP was set in MAKEARGS but could not be executed. See README.");
+ }
};
@@ -205,8 +297,4 @@ sub cfg_read($) {
return $cfg;
}
-1;
-
-
-
-
+1;
View
@@ -17,6 +17,10 @@ sub get_vc_info() {
my $sdkvers;
if ($ENV{'WindowsSDKDir'} =~ /Microsoft SDKs\\Windows\\([^\\]+)/) {
$sdkvers = $1;
+ } elsif ($ENV{'WindowsSDKDir'} =~ /Windows Kits\\([^\\]+)/) {
+ $sdkvers = $1;
+ } else {
+ die("Env var %WindowsSDKDir% doesn't match a known SDK: $ENV{'WindowsSDKDir'}\n");
}
# Try to determine the cl.exe version
@@ -46,7 +50,11 @@ sub get_vc_info() {
sub detect_sdk() {
our ($sdkvers, $clvers, $vsvers) = get_vc_info();
- our $verstring = "sdk${sdkvers}_cl${clvers}" . (defined($vsvers)?"_vs${vsvers}":"");
+ if (defined($sdkvers)) {
+ our $verstring = "sdk${sdkvers}_cl${clvers}" . (defined($vsvers)?"_vs${vsvers}":"");
+ } else {
+ die("Unable to detect Windows SDK version\n");
+ }
};
sub ver_string() {
@@ -0,0 +1,33 @@
+package PgBuildWin::Config;
+
+use strict;
+use warnings;
+use Exporter;
+use LWP::Simple qw( getstore is_success );
+use File::Spec::Functions qw/catfile catdir devnull/;
+#use IPC::Open3 qw( open3 );
+#use FindBin qw($Bin);
+
+our $VERSION = 1.00;
+our @ISA = qw(Exporter);
+# Always export:
+our @EXPORT = ();
+# Export only on request
+our @EXPORT_OK = qw();
+
+my $resources = {
+ 'GIT' => ('http://msysgit.github.com/', 'http://msysgit.googlecode.com/files/Git-1.8.0-preview20121022.exe', 'Git-1.8.0-preview20121022.exe')
+};
+
+sub install_git($) {
+ my $cfg = $_[0];
+ my ($home,$dl,$localfilename) = $resources->{'GIT'};
+ my $localfilepath = catfile($cfg->{'PKGDIR'}, $localfilename);
+ my $dl_result = getstore($dl);
+ if (is_success($dl_result)) {
+ print("Successfully downloaded git");
+ } else {
+ print("Download of git failed with HTTP $dl_result\n");
+ }
+}
+
View
@@ -83,16 +83,22 @@ them and wait, but it won't work with all installers.
You will need to adjust the file names to reflect the exact files you downloaded.
-If you're on a 32-bit platform, omit the lines for 64-bit programs and for Perl, use
-PERL_PATH=Yes PERL_EXT=Yes for the 32-bit version since you aren't installing the 64-bit
-version.
+On 64-bit platforms:
+
+ start /wait msiexec /i ActivePerl-5.16.1.1601-MSWin32-x64-296175.msi /qb /passive PERL_PATH=Yes PERL_EXT=Yes
+ start /wait msiexec /i ActivePerl-5.16.1.1601-MSWin32-x86-296175.msi /qb /passive PERL_PATH=No PERL_EXT=No
+
+On 32-bit platforms:
+
+ start /wait msiexec /i ActivePerl-5.16.1.1601-MSWin32-x86-296175.msi /qb /passive PERL_PATH=Yes PERL_EXT=Yes
+
+Then for x64 install all the below, and for x68 install only the non-64-bit versions:
+
start /wait mingw-get-inst-20120426.exe /silent
c:\MinGW\bin\mingw-get.exe install msys-flex msys-bison g++ gdb mingw32-make msys-base
start /wait msiexec /i 7z920-x64.msi /qb /passive /norestart
start /wait Git-1.8.0-preview20121022.exe /silent
- start /wait msiexec /i ActivePerl-5.16.1.1601-MSWin32-x64-296175.msi /qb /passive PERL_PATH=Yes PERL_EXT=Yes
- start /wait msiexec /i ActivePerl-5.16.1.1601-MSWin32-x86-296175.msi /qb /passive PERL_PATH=No PERL_EXT=No
start /wait msiexec /i python-2.7.3.amd64.msi /qb /passive TARGETDIR=%SystemDrive%\Python27_x64 ALLUSERS=1
start /wait msiexec /i python-2.7.3.msi /qb /passive TARGETDIR=%SystemDrive%\Python27_x86 ALLUSERS=1
start /wait msiexec /i python-3.3.0.amd64.msi /qb /passive TARGETDIR=%SystemDrive%\Python33_x64 ALLUSERS=1
@@ -224,10 +230,10 @@ including any source packages you put there.
SET UP VISUAL STUDIO ENVIRONMENT
================================
-Set up your Visual Studio or Windows SDK environment for the build target you want.
-Either use the Start menu option to launch a suitable prompt if you want the default
-settings, or preferably open a new ordinary Command Prompt and use SetEnv.cmd
-(SDK) or vcvars.bat (Studio) to set the environment up.
+Set up your Visual Studio or Windows SDK environment for the build target you
+want. Either use the Start menu option to launch a suitable prompt if you want
+the default settings, or preferably open a new ordinary Command Prompt and use
+SetEnv.cmd (SDK) or vcvars.bat (Studio) to set the environment up.
For windows SDK 7.1 32-bit release builds you'd use:
@@ -240,6 +246,12 @@ For options:
The main options are "/x86" vs "/x64" and "/Debug" vs "/Release".
You probably want to pass "/xp" for 32-bit builds and "/2008" for 64-bit builds.
+vcvarsall.bat for Visual Studio builds works a bit differently to the Windows
+SDK 7.1 SetEnv.cmd script. They do not offer any control of the debug/release
+state ("Configuration") or the target platform; the only argument they accept
+is an arcitecture. You must set the environment variables for TARGET and
+Configuration yourself.
+
BUILD
=====
@@ -398,9 +410,9 @@ Installing Visual Studio 2012 breaks Visual Studio 2010 (pre-SP1) and Windows SD
Environment setup with vcvarsall.bat or VsDevCmd.bat:
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" /?
- "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"
-Untested.
+Build not supported for PostgreSQL 9.2 and older; 9.3 or newer is required
+for Visual Studio 2012 build support.
Microsoft Platform SDK for Windows XP SP2
-----------------------------------------
View
@@ -19,9 +19,9 @@ our $$config = {
# wal_segsize => 16, # --with-wal-segsize, 16MB by default
ldap => 1, # --with-ldap
nls => undef, # --enable-nls=<path>
- tcl => '$(TCLDIR)', # --with-tls=<path>
- perl => '$(PERLDIR)', # --with-perl
- python => '$(PYTHON2DIR)', # --with-python=<path>
+ tcl => '$(TCLDIR)' || undef, # --with-tls=<path>
+ perl => '$(PERLDIR)' || undef, # --with-perl
+ python => '$(PYTHON2DIR)' || undef, # --with-python=<path>
krb5 => undef, # --with-krb5=<path>
openssl => undef, # --with-ssl=<path>
uuid => undef, # --with-ossp-uuid
@@ -38,7 +38,8 @@ $(BUILDENV_PL):
@echo Generated buildenv.pl
@echo ---------------------
@type <<$@
-$$ENV{PATH}=$$ENV{PATH} . ';$(MSYS)\bin';
+# The PATH is now set via the wrapper script
+#$$ENV{PATH}=$$ENV{PATH} . ';$(MSYS)\bin';
1;
<< KEEP
@echo ---------------------
View
@@ -25,10 +25,18 @@ $(PGBUILDDIR): phony
# us to find out if the tree is dirty, so we have to re-run the build and let it decide
# anyway.
#
-postgresql: $(FLEX) $(BISON) zlib $(PGBUILDDIR) $(CONFIG_PL) $(BUILDENV_PL)
+# The weird hack with tee works around an odd stdio issue that seems to occur
+# on some machines with some consoles and some SDK versions with some Perl versions.
+# Which ones? Never did work it out.
+#
+postgresql: zlib $(PGBUILDDIR) $(CONFIG_PL) $(BUILDENV_PL)
cd $(PGBUILDDIR)\src\tools\msvc
+!IFDEF TEE
+ "$(PERL_CMD)" build.pl 2>&1 | tee build-log.log
+!ELSE
"$(PERL_CMD)" build.pl
-
+!ENDIF
+
!IFDEF USE_GIT
postgresql-clean: phony
IF EXIST $(PGBUILDDIR)\.git\HEAD ( cd $(PGBUILDDIR) && "$(GIT)" clean -fdx )
Oops, something went wrong.

0 comments on commit 809385c

Please sign in to comment.