From 5bd91523463d08b26e185d494707a61b9ede838c Mon Sep 17 00:00:00 2001 From: Jani Honkonen Date: Tue, 22 May 2012 10:25:17 +0300 Subject: Move scripts to tools folder --- tools/Jobs.pm | 33 +++++ tools/Tiny.pm | 280 +++++++++++++++++++++++++++++++++++++++ tools/build.pl | 97 ++++++++++++++ tools/build_win_mingw.bat | 8 ++ tools/build_win_vs2005.bat | 10 ++ tools/build_win_vs2008.bat | 8 ++ tools/build_win_vs2010.bat | 8 ++ tools/build_win_vs2010_64bit.bat | 8 ++ tools/jobs.ini | 119 +++++++++++++++++ tools/run_tests.pl | 90 +++++++++++++ 10 files changed, 661 insertions(+) create mode 100644 tools/Jobs.pm create mode 100644 tools/Tiny.pm create mode 100644 tools/build.pl create mode 100644 tools/build_win_mingw.bat create mode 100644 tools/build_win_vs2005.bat create mode 100644 tools/build_win_vs2008.bat create mode 100644 tools/build_win_vs2010.bat create mode 100644 tools/build_win_vs2010_64bit.bat create mode 100644 tools/jobs.ini create mode 100644 tools/run_tests.pl (limited to 'tools') diff --git a/tools/Jobs.pm b/tools/Jobs.pm new file mode 100644 index 00000000..e2021daf --- /dev/null +++ b/tools/Jobs.pm @@ -0,0 +1,33 @@ +package Jobs; +use File::Basename; +use Tiny; + +sub get { + my $inifile = shift; + my $jobname = shift; + + # Strip the prefix from job name when using ${bamboo.buildPlanName} + my $prefix = "Digia Qt Commercial - Chart component - "; + $jobname =~ s/$prefix//; + + # read ini file + my $cfg = Config::Tiny->read( $inifile ); + + # get section from ini by jobname + my %job = %{$cfg->{$jobname}}; + if (!%job) { + die ("Unknown jobname! Check $inifile and bamboo job name."); + } + + # print out the ini settings + print "\n\nini file: $inifile\n"; + print "[$jobname]\n"; + foreach (keys %job) { + print $_ . "=" . $job{$_} . "\n"; + } + print "\n"; + + return %job; +} + +1; \ No newline at end of file diff --git a/tools/Tiny.pm b/tools/Tiny.pm new file mode 100644 index 00000000..24961295 --- /dev/null +++ b/tools/Tiny.pm @@ -0,0 +1,280 @@ +package Config::Tiny; + +# If you thought Config::Simple was small... + +use strict; +BEGIN { + require 5.004; + $Config::Tiny::VERSION = '2.14'; + $Config::Tiny::errstr = ''; +} + +# Create an empty object +sub new { bless {}, shift } + +# Create an object from a file +sub read { + my $class = ref $_[0] ? ref shift : shift; + + # Check the file + my $file = shift or return $class->_error( 'You did not specify a file name' ); + return $class->_error( "File '$file' does not exist" ) unless -e $file; + return $class->_error( "'$file' is a directory, not a file" ) unless -f _; + return $class->_error( "Insufficient permissions to read '$file'" ) unless -r _; + + # Slurp in the file + local $/ = undef; + open( CFG, $file ) or return $class->_error( "Failed to open file '$file': $!" ); + my $contents = ; + close( CFG ); + + $class->read_string( $contents ); +} + +# Create an object from a string +sub read_string { + my $class = ref $_[0] ? ref shift : shift; + my $self = bless {}, $class; + return undef unless defined $_[0]; + + # Parse the file + my $ns = '_'; + my $counter = 0; + foreach ( split /(?:\015{1,2}\012|\015|\012)/, shift ) { + $counter++; + + # Skip comments and empty lines + next if /^\s*(?:\#|\;|$)/; + + # Remove inline comments + s/\s\;\s.+$//g; + + # Handle section headers + if ( /^\s*\[\s*(.+?)\s*\]\s*$/ ) { + # Create the sub-hash if it doesn't exist. + # Without this sections without keys will not + # appear at all in the completed struct. + $self->{$ns = $1} ||= {}; + next; + } + + # Handle properties + if ( /^\s*([^=]+?)\s*=\s*(.*?)\s*$/ ) { + $self->{$ns}->{$1} = $2; + next; + } + + return $self->_error( "Syntax error at line $counter: '$_'" ); + } + + $self; +} + +# Save an object to a file +sub write { + my $self = shift; + my $file = shift or return $self->_error( + 'No file name provided' + ); + + # Write it to the file + my $string = $self->write_string; + return undef unless defined $string; + open( CFG, '>' . $file ) or return $self->_error( + "Failed to open file '$file' for writing: $!" + ); + print CFG $string; + close CFG; +} + +# Save an object to a string +sub write_string { + my $self = shift; + + my $contents = ''; + foreach my $section ( sort { (($b eq '_') <=> ($a eq '_')) || ($a cmp $b) } keys %$self ) { + # Check for several known-bad situations with the section + # 1. Leading whitespace + # 2. Trailing whitespace + # 3. Newlines in section name + return $self->_error( + "Illegal whitespace in section name '$section'" + ) if $section =~ /(?:^\s|\n|\s$)/s; + my $block = $self->{$section}; + $contents .= "\n" if length $contents; + $contents .= "[$section]\n" unless $section eq '_'; + foreach my $property ( sort keys %$block ) { + return $self->_error( + "Illegal newlines in property '$section.$property'" + ) if $block->{$property} =~ /(?:\012|\015)/s; + $contents .= "$property=$block->{$property}\n"; + } + } + + $contents; +} + +# Error handling +sub errstr { $Config::Tiny::errstr } +sub _error { $Config::Tiny::errstr = $_[1]; undef } + +1; + +__END__ + +=pod + +=head1 NAME + +Config::Tiny - Read/Write .ini style files with as little code as possible + +=head1 SYNOPSIS + + # In your configuration file + rootproperty=blah + + [section] + one=twp + three= four + Foo =Bar + empty= + + # In your program + use Config::Tiny; + + # Create a config + my $Config = Config::Tiny->new; + + # Open the config + $Config = Config::Tiny->read( 'file.conf' ); + + # Reading properties + my $rootproperty = $Config->{_}->{rootproperty}; + my $one = $Config->{section}->{one}; + my $Foo = $Config->{section}->{Foo}; + + # Changing data + $Config->{newsection} = { this => 'that' }; # Add a section + $Config->{section}->{Foo} = 'Not Bar!'; # Change a value + delete $Config->{_}; # Delete a value or section + + # Save a config + $Config->write( 'file.conf' ); + +=head1 DESCRIPTION + +C is a perl class to read and write .ini style configuration +files with as little code as possible, reducing load time and memory +overhead. Most of the time it is accepted that Perl applications use a lot +of memory and modules. The C<::Tiny> family of modules is specifically +intended to provide an ultralight alternative to the standard modules. + +This module is primarily for reading human written files, and anything we +write shouldn't need to have documentation/comments. If you need something +with more power move up to L, L or one of +the many other C modules. To rephrase, L does B +preserve your comments, whitespace, or the order of your config file. + +=head1 CONFIGURATION FILE SYNTAX + +Files are the same format as for windows .ini files. For example: + + [section] + var1=value1 + var2=value2 + +If a property is outside of a section at the beginning of a file, it will +be assigned to the C<"root section">, available at C<$Config-E{_}>. + +Lines starting with C<'#'> or C<';'> are considered comments and ignored, +as are blank lines. + +When writing back to the config file, all comments, custom whitespace, +and the ordering of your config file elements is discarded. If you need +to keep the human elements of a config when writing back, upgrade to +something better, this module is not for you. + +=head1 METHODS + +=head2 new + +The constructor C creates and returns an empty C object. + +=head2 read $filename + +The C constructor reads a config file, and returns a new +C object containing the properties in the file. + +Returns the object on success, or C on error. + +When C fails, C sets an error message internally +you can recover via Cerrstr>. Although in B +cases a failed C will also set the operating system error +variable C<$!>, not all errors do and you should not rely on using +the C<$!> variable. + +=head2 read_string $string; + +The C method takes as argument the contents of a config file +as a string and returns the C object for it. + +=head2 write $filename + +The C method generates the file content for the properties, and +writes it to disk to the filename specified. + +Returns true on success or C on error. + +=head2 write_string + +Generates the file content for the object and returns it as a string. + +=head2 errstr + +When an error occurs, you can retrieve the error message either from the +C<$Config::Tiny::errstr> variable, or using the C method. + +=head1 CAVEATS + +=head2 Unsupported Section Headers + +Some edge cases in section headers are not support, and additionally may not +be detected when writing the config file. + +Specifically, section headers with leading whitespace, trailing whitespace, +or newlines anywhere in the section header, will not be written correctly +to the file and may cause file corruption. + +=head1 SUPPORT + +Bugs should be reported via the CPAN bug tracker at + +L + +For other issues, or commercial enhancement or support, contact the author. + +=head1 AUTHOR + +Adam Kennedy Eadamk@cpan.orgE + +=head1 ACKNOWLEGEMENTS + +Thanks to Sherzod Ruzmetov Esherzodr@cpan.orgE for +L, which inspired this module by being not quite +"simple" enough for me :) + +=head1 SEE ALSO + +L, L, L + +=head1 COPYRIGHT + +Copyright 2002 - 2011 Adam Kennedy. + +This program is free software; you can redistribute +it and/or modify it under the same terms as Perl itself. + +The full text of the license can be found in the +LICENSE file included with this module. + +=cut diff --git a/tools/build.pl b/tools/build.pl new file mode 100644 index 00000000..3379db74 --- /dev/null +++ b/tools/build.pl @@ -0,0 +1,97 @@ +use File::Basename; +use feature "switch"; +use lib 'tools'; +use Jobs; + +# read command line params +my $jobname = shift; + +# get script directory +my $scriptdir = File::Basename::dirname($0); + +# read ini file +my $inifile = $scriptdir . "/jobs.ini"; +my %job = Jobs::get($inifile, $jobname); + +# examine the platform +given ($job{'Platform'}) { + + when ("Win7") { + + $scriptdir =~ s/\//\\/g; # replace / -> \ + + # construct a build command + if ($job{'ToolChain'} eq "mingw") { + run($scriptdir . "\\build_win_mingw.bat", $job{'QtDir'}, $job{'Config'}, $job{'MinGWDir'}); + } + elsif ($job{'ToolChain'} eq "vs2005") { + run($scriptdir . "\\build_win_vs2005.bat", $job{'QtDir'}, $job{'Config'}); + } + elsif ($job{'ToolChain'} eq "vs2008") { + run($scriptdir . "\\build_win_vs2008.bat", $job{'QtDir'}, $job{'Config'}); + } + elsif ($job{'ToolChain'} eq "vs2010") { + run($scriptdir . "\\build_win_vs2010.bat", $job{'QtDir'}, $job{'Config'}); + } + elsif ($job{'ToolChain'} eq "vs2010-64bit") { + run($scriptdir . "\\build_win_vs2010_64bit.bat", $job{'QtDir'}, $job{'Config'}); + } + else { + die "Unknown toolchain!"; + } + } + + when ("Mac") { + + # setup build environment + $ENV{'QTDIR'} = $job{'QtDir'}; + $ENV{'PATH'} = $job{'QtDir'} . "/bin:" . $ENV{'PATH'}; + + # run qmake + my $cmd; + if ($job{'ToolChain'} eq "clang") { + run("qmake -r -spec unsupported/macx-clang CONFIG+=" . $job{'Config'}); + } + elsif ($job{'ToolChain'} eq "gcc") { + run("qmake -r CONFIG+=" . $job{'Config'}); + } + else { + die "Unknown toolchain!"; + } + + # run make + run("make"); + } + + when ("Linux") { + + # setup build environment + $ENV{'QTDIR'} = $job{'QtDir'}; + $ENV{'PATH'} = $job{'QtDir'} . "/bin:" . $ENV{'PATH'}; + + # run qmake + my $cmd; + if ($job{'ToolChain'} eq "gcc") { + run("qmake -r CONFIG+=" . $job{'Config'}); + } + else { + die "Unknown toolchain!"; + } + + # run make + run("make -j 4"); + } + + default { + die "Unknown platform " . $job{'Platform'}; + } +} + +sub run { + my $cmd; + foreach (@_) { + $cmd .= "$_ "; + } + print "running : $cmd\n"; + system(@_) == 0 or die "system \"$cmd\" failed: $?"; +} \ No newline at end of file diff --git a/tools/build_win_mingw.bat b/tools/build_win_mingw.bat new file mode 100644 index 00000000..54212cd1 --- /dev/null +++ b/tools/build_win_mingw.bat @@ -0,0 +1,8 @@ +set QTDIR=%1 +set PATH=%1\bin; +set PATH=%PATH%;%3\bin +set PATH=%PATH%;%SystemRoot%\System32 +set QMAKESPEC=win32-g++ +qmake -r charts.pro CONFIG+=%2 +@echo on +mingw32-make \ No newline at end of file diff --git a/tools/build_win_vs2005.bat b/tools/build_win_vs2005.bat new file mode 100644 index 00000000..9642ba25 --- /dev/null +++ b/tools/build_win_vs2005.bat @@ -0,0 +1,10 @@ +set QTDIR=%1 +set PATH=%1\bin;%PATH%; +set QMAKESPEC=win32-msvc2005 +call "C:\Program Files (x86)\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86 +@echo on +set INCLUDE=%INCLUDE%;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include +set LIB=%LIB%;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib +qmake -r charts.pro CONFIG+=%2 +@echo on +nmake diff --git a/tools/build_win_vs2008.bat b/tools/build_win_vs2008.bat new file mode 100644 index 00000000..4edcefc2 --- /dev/null +++ b/tools/build_win_vs2008.bat @@ -0,0 +1,8 @@ +set QTDIR=%1 +set PATH=%1\bin;%PATH%; +set QMAKESPEC=win32-msvc2008 +call "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 +@echo on +qmake -r charts.pro CONFIG+=%2 +@echo on +nmake diff --git a/tools/build_win_vs2010.bat b/tools/build_win_vs2010.bat new file mode 100644 index 00000000..690dabf6 --- /dev/null +++ b/tools/build_win_vs2010.bat @@ -0,0 +1,8 @@ +set QTDIR=%1 +set PATH=%1\bin;%PATH%; +set QMAKESPEC=win32-msvc2010 +call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 +@echo on +qmake -r charts.pro CONFIG+=%2 +@echo on +nmake diff --git a/tools/build_win_vs2010_64bit.bat b/tools/build_win_vs2010_64bit.bat new file mode 100644 index 00000000..e89af2c8 --- /dev/null +++ b/tools/build_win_vs2010_64bit.bat @@ -0,0 +1,8 @@ +set QTDIR=%1 +set PATH=%1\bin;%PATH%; +set QMAKESPEC=win32-msvc2010 +call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" amd64 +@echo on +qmake -r charts.pro CONFIG+=%2 +@echo on +nmake diff --git a/tools/jobs.ini b/tools/jobs.ini new file mode 100644 index 00000000..cbcaeeba --- /dev/null +++ b/tools/jobs.ini @@ -0,0 +1,119 @@ + +; How to use +; ---------- +; - Section name must match to "Job Name" in Bamboo. +; * See ${bamboo.buildPlanName} in bamboo. +; * Case sensitive. +; - The parameters given can be anything you need for that particular build. +; * Implement your special parameter handling in the perl scripts. + + +[Win7 MinGW debug QtC v4.8.0 (Jani's machine)] +Platform=Win7 +QtDir=D:\Qt\4.8.0-MinGW-Commercial +ToolChain=mingw +Config=debug +MinGWDir=D:\Qt\mingw + +[Win7 MinGW release QtC v4.8.0 (Jani's machine)] +Platform=Win7 +QtDir=D:\Qt\4.8.0-MinGW-Commercial +ToolChain=mingw +Config=release +MinGWDir=D:\Qt\mingw + +[Win7 vs2005 debug QtC v4.7.5 (Jani's machine)] +Platform=Win7 +QtDir=D:\Qt\qt-win-commercial-4.7.5-vs2005 +ToolChain=vs2005 +Config=debug + +[Win7 vs2005 release QtC v4.7.5 (Jani's machine)] +Platform=Win7 +QtDir=D:\Qt\qt-win-commercial-4.7.5-vs2005 +ToolChain=vs2005 +Config=release + +[Win7 vs2008 debug QtC v4.8.2 (Jani's machine)] +Platform=Win7 +QtDir=D:\Qt\qt-win-commercial-4.8.2-vs2008-15-Apr-2012 +ToolChain=vs2008 +Config=debug + +[Win7 vs2008 release QtC v4.8.2 (Jani's machine)] +Platform=Win7 +QtDir=D:\Qt\qt-win-commercial-4.8.2-vs2008-15-Apr-2012 +ToolChain=vs2008 +Config=release + +[Win7 vs2010 debug QtC v4.8.0 (Jani's machine)] +Platform=Win7 +QtDir=D:\Qt\qt-win-commercial-4.8.0-vs2010 +ToolChain=vs2010 +Config=debug + +[Win7 vs2010 release QtC v4.8.0 (Jani's machine)] +Platform=Win7 +QtDir=D:\Qt\qt-win-commercial-4.8.0-vs2010 +ToolChain=vs2010 +Config=release + +[Win7 vs2010-64bit debug QtC v4.8.1] +Platform=Win7 +QtDir=C:\Qt\4.8.1 +ToolChain=vs2010-64bit +Config=debug + +[Win7 vs2010-64bit release QtC v4.8.1] +Platform=Win7 +QtDir=C:\Qt\4.8.1 +ToolChain=vs2010-64bit +Config=release + +[Mac 10.7 Cocoa clang debug QtC v4.8.0 (Tero's iMac)] +Platform=Mac +QtDir=/Users/teahola/QtCommercialSdk/Desktop/480/cocoa_gcc +ToolChain=clang +Config=debug + +[Mac 10.7 Cocoa clang release QtC v4.8.0 (Tero's iMac)] +Platform=Mac +QtDir=/Users/teahola/QtCommercialSdk/Desktop/480/cocoa_gcc +ToolChain=clang +Config=release + +[Mac 10.7 Cocoa gcc debug QtC v4.8.0 (Tero's iMac)] +Platform=Mac +QtDir=/Users/teahola/QtCommercialSdk/Desktop/480/cocoa_gcc +ToolChain=gcc +Config=debug + +[Mac 10.7 Cocoa gcc release QtC v4.8.0 (Tero's iMac)] +Platform=Mac +QtDir=/Users/teahola/QtCommercialSdk/Desktop/480/cocoa_gcc +ToolChain=gcc +Config=release + +[Ubuntu 10.10 x86 debug QtC v4.8.1] +Platform=Linux +QtDir=/usr/local/Trolltech/Qt-4.8.1 +ToolChain=gcc +Config=debug + +[Ubuntu 10.10 x86 release QtC v4.8.1] +Platform=Linux +QtDir=/usr/local/Trolltech/Qt-4.8.1 +ToolChain=gcc +Config=release + +[Ubuntu 10.10 x86_64 debug QtC v4.8.1] +Platform=Linux +QtDir=/usr/local/Trolltech/Qt-4.8.1 +ToolChain=gcc +Config=debug + +[Ubuntu 10.10 x86_64 release QtC v4.8.1] +Platform=Linux +QtDir=/usr/local/Trolltech/Qt-4.8.1 +ToolChain=gcc +Config=release diff --git a/tools/run_tests.pl b/tools/run_tests.pl new file mode 100644 index 00000000..c0a34cd1 --- /dev/null +++ b/tools/run_tests.pl @@ -0,0 +1,90 @@ +use Cwd; +use Cwd 'abs_path'; +use File::Basename; +use File::Copy; +use feature "switch"; +use lib 'tools'; +use Jobs; + +# read command line params +my $jobname = shift; + +# read ini file +my $inifile = File::Basename::dirname($0) . "/jobs.ini"; +my %job = Jobs::get($inifile, $jobname); + +# set/get paths +my $root_path = abs_path(); +my $bin_path = "$root_path/bin/"; +my $reports_path = "test-reports"; + +# create reports path +mkdir $reports_path; + +# setup environment for running tests +given ($job{'Platform'}) { + + when ("Win7") { + # Add qtdir to path + $ENV{'PATH'} .= ";" . $job{'QtDir'} . "\\bin"; + + # replace / -> \ + $ENV{'PATH'} =~ s/\//\\/g; + } + + when ("Linux") { + # Add qtdir to path + $ENV{'PATH'} = $job{'QtDir'} . "/bin:" . $ENV{'PATH'}; + + # If this is not set we get "cannot connect to X server" errors + $ENV{'DISPLAY'} = ":0.0"; + } +} + +# Go through all the files in the test folder +# autotest is an executable beginning with "tst_" +my $script_exit_status = 0; +opendir (TESTAPPDIR, "$bin_path") or die "Couldn't open test app dir"; +@files = ; +while ($testapp = readdir TESTAPPDIR) { + if (index($testapp, "tst_") == 0) { + if (-x "$bin_path$testapp") { + my $status = executeTestApp($testapp); + if ($status != 0) { + $script_exit_status = $status; + } + } else { + #print "file $testapp not executable\n"; + } + } +} +closedir TESTAPPDIR; + +print "\n*** script exit status : $script_exit_status ***\n\n"; +exit($script_exit_status); + + +sub executeTestApp($) { + my $testapp = $_[0]; + + # On OSX the actual test binary is in a sub folder + my $cmd_postfix = ""; + if ($^O eq "darwin") { + $cmd_postfix = "/Contents/MacOS/$testapp"; + $cmd_postfix = substr($cmd_postfix, 0, rindex($cmd_postfix, ".app")); + } + + my $cmd = "$bin_path$testapp$cmd_postfix -xunitxml -o $reports_path/$testapp.xml"; + print "executing: $cmd\n"; + system($cmd); + + # From http://perldoc.perl.org/perlvar.html about $?: + # The upper eight bits reflect specific error conditions encountered by the + # program (the program's exit() value). The lower eight bits reflect + # mode of failure, like signal death and core dump information. + # See wait(2) for details. + my $exit_status = $? >> 8; + print "\texit status: $exit_status\n"; + + return $exit_status; +} -- cgit v1.2.3