From 827385506711d497d55761b0ff8deed2f8e8321c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 06:23:58 -0800 Subject: [PATCH 01/12] Remove extra newline mostly to check for linguist updates --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 47ccaf3e..867163f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,5 @@ script: # Building with biicode - biicode/support/travis-build.sh - after_failure: - cat Testing/Temporary/LastTest.log From e392eea1605e59e157e49d9dcdfa982181866165 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 10:12:26 -0800 Subject: [PATCH 02/12] Fix CMake warning --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e135949d..bec473e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,8 @@ +if (CMAKE_MAJOR_VERSION GREATER 2 AND CMAKE_MINOR_VERSION GREATER 0) + # Only interpret `if` arguments as variables or keywords when unquoted. + cmake_policy(SET CMP0054 NEW) +endif () + cmake_minimum_required(VERSION 2.6) # Set the default CMAKE_BUILD_TYPE to Release. From 3822241d9929a7b166d672812157cfa852007d96 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 11:27:55 -0800 Subject: [PATCH 03/12] Use policy check instead of CMake version check --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bec473e8..6219383f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -if (CMAKE_MAJOR_VERSION GREATER 2 AND CMAKE_MINOR_VERSION GREATER 0) +if (POLICY CMP0054) # Only interpret `if` arguments as variables or keywords when unquoted. cmake_policy(SET CMP0054 NEW) endif () From 503e87f153ac228312971c3d38b6c174cc5ff95f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 11:41:45 -0800 Subject: [PATCH 04/12] Report CMake version for debugging --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6219383f..c1e0ea56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,5 @@ +message(STATUS "CMake version: ${CMAKE_VERSION}") + if (POLICY CMP0054) # Only interpret `if` arguments as variables or keywords when unquoted. cmake_policy(SET CMP0054 NEW) From 4f51033aa9f28e4d72ecf1b4d034f21fea332858 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 12:27:32 -0800 Subject: [PATCH 05/12] Workaround PowerShell idiocy --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 4e9ae14f..5d472999 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,8 +30,8 @@ before_build: $env:PATH = $env:PATH -replace "C:\\Program Files \(x86\)\\Git\\bin","" $generator = "-GMinGW Makefiles" } - echo "-DCMAKE_BUILD_TYPE=$env:Config" - cmake -DFMT_EXTRA_TESTS=ON "-DCMAKE_BUILD_TYPE=$env:Config" "$generator" . + - echo "-DCMAKE_BUILD_TYPE=$env:Config" + - cmake -DFMT_EXTRA_TESTS=ON "-DCMAKE_BUILD_TYPE=$env:Config" "$generator" . build_script: - ps: | From dd2e8b98deda8a5a05447160dc4d9496ae37dec8 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 12:46:28 -0800 Subject: [PATCH 06/12] Fix RST markup --- format.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/format.h b/format.h index c6bdd707..6d2ab9a1 100644 --- a/format.h +++ b/format.h @@ -1418,6 +1418,7 @@ class SystemError : public internal::RuntimeError { .. parsed-literal:: **: ** + where ** is the formatted message and ** is the system message corresponding to the error code. *error_code* is a system error code as given by ``errno``. @@ -1599,7 +1600,7 @@ class BasicWriter { Current point: (-3.140000, +3.140000) - The output can be accessed using :meth:`data`, :meth:`c_str` or :meth:`str` + The output can be accessed using :func:`data()`, :func:`c_str` or :func:`str` methods. See also :ref:`syntax`. @@ -2118,6 +2119,7 @@ class WindowsError : public SystemError { .. parsed-literal:: **: ** + where ** is the formatted message and ** is the system message corresponding to the error code. *error_code* is a Windows error code as given by ``GetLastError``. From 2ced92529dc86db3706fa2d164de722ed3d33cec Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 15:34:38 -0800 Subject: [PATCH 07/12] Move logic from travis.yml to a Python script --- appveyor.yml | 37 +++++++++++++++---------------------- support/build.py | 13 +++++++++++++ 2 files changed, 28 insertions(+), 22 deletions(-) create mode 100755 support/build.py diff --git a/appveyor.yml b/appveyor.yml index 5d472999..7a6c2a57 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,49 +1,42 @@ environment: CTEST_OUTPUT_ON_FAILURE: 1 matrix: - - Build: msvc - Config: Debug - - Build: msvc - Config: Release - - Build: mingw - Config: Debug - - Build: mingw - Config: Release + - BUILD: msvc + CONFIG: Debug + - BUILD: msvc + CONFIG: Release + - BUILD: mingw + CONFIG: Debug + - BUILD: mingw + CONFIG: Release install: - ps: | - if ($env:Build -eq "mingw") { + if ($env:BUILD -eq "mingw") { # Install MinGW. $url = "http://sourceforge.net/projects/mingw-w64/files/" - $url += "Toolchains%20targetting%20Win64/Personal%20Builds/" + $url += "Toolchains%20targetting%20Win64/Personal%20BUILDs/" $url += "mingw-builds/4.9.0/threads-win32/seh/" $url += "x86_64-4.9.0-release-win32-seh-rt_v3-rev2.7z/download" Invoke-WebRequest -UserAgent wget -Uri $url -OutFile mingw.7z &7z x -oC:\ mingw.7z > $null } - - set PATH=C:\Program Files (x86)\MSBuild\12.0\bin\;%PATH%;C:\mingw64\bin + - set PATH=C:\Program Files (x86)\MSBUILD\12.0\bin\;%PATH%;C:\mingw64\bin before_build: - - ps: | - if ($env:Build -eq "mingw") { - # Remove path to Git bin directory from PATH because it breaks MinGW config. - $env:PATH = $env:PATH -replace "C:\\Program Files \(x86\)\\Git\\bin","" - $generator = "-GMinGW Makefiles" - } - - echo "-DCMAKE_BUILD_TYPE=$env:Config" - - cmake -DFMT_EXTRA_TESTS=ON "-DCMAKE_BUILD_TYPE=$env:Config" "$generator" . + - python support/build.py build_script: - ps: | - if ($env:Build -eq "mingw") { + if ($env:BUILD -eq "mingw") { mingw32-make -j4 } else { - msbuild /m:4 /p:Config=$env:Config FORMAT.sln + msbuild /m:4 /p:Config=$env:CONFIG FORMAT.sln } test_script: - ps: | - if ($env:Build -eq "mingw") { + if ($env:BUILD -eq "mingw") { mingw32-make test } else { msbuild RUN_TESTS.vcxproj diff --git a/support/build.py b/support/build.py new file mode 100755 index 00000000..826e1527 --- /dev/null +++ b/support/build.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# Build the project on AppVeyor. + +from subprocess import check_call +import os + +env = os.environ +build = env['BUILD'] +if build == 'mingw': + # Remove path to Git bin directory from $PATH because it breaks MinGW config. + env['PATH'] = env['PATH'].replace(r'C:\Program Files (x86)\Git\bin', '') + generator = ['-GMinGW Makefiles'] +check_call(['cmake', '-DFMT_EXTRA_TESTS=ON', '-DCMAKE_BUILD_TYPE=' + env['CONFIG']] + generator, env=env) From 2f05eaa07dbb3e430e360f8defe309496e63d32b Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 15:39:06 -0800 Subject: [PATCH 08/12] Correct filename in Biicode config --- biicode.conf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/biicode.conf b/biicode.conf index f4fd4bce..e541444f 100644 --- a/biicode.conf +++ b/biicode.conf @@ -9,8 +9,11 @@ CMakeLists.txt + cmake/FindSetEnv.cmake format.h = format.cc format.cc - test/* posix.cc - biicode/samples/basic.cpp - test/* + biicode/samples/basic.cc - test/* [mains] # Manual adjust of files that define an executable !test/test-main.cc + +[parent] + vitaut/cppformat: 0 \ No newline at end of file From 609f33c94ae362568a36a97894c95b5fc9fead8b Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 15:41:30 -0800 Subject: [PATCH 09/12] Fix appveyor script --- support/build.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/support/build.py b/support/build.py index 826e1527..c2eed699 100755 --- a/support/build.py +++ b/support/build.py @@ -6,8 +6,9 @@ import os env = os.environ build = env['BUILD'] +cmake_command = ['cmake', '-DFMT_EXTRA_TESTS=ON', '-DCMAKE_BUILD_TYPE=' + env['CONFIG']] if build == 'mingw': # Remove path to Git bin directory from $PATH because it breaks MinGW config. env['PATH'] = env['PATH'].replace(r'C:\Program Files (x86)\Git\bin', '') - generator = ['-GMinGW Makefiles'] -check_call(['cmake', '-DFMT_EXTRA_TESTS=ON', '-DCMAKE_BUILD_TYPE=' + env['CONFIG']] + generator, env=env) + cmake_command.append('-GMinGW Makefiles') +check_call(cmake_command, env=env) From c643fdae53d90c5f115c449b6788dad51bb75ef3 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 15:55:21 -0800 Subject: [PATCH 10/12] Fix CMake warning --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1e0ea56..f9d40a29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,7 +109,7 @@ if (NOT FMT_VARIADIC_TEMPLATES) endif () # GTest doesn't detect with clang. -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1) endif () From 86fee707fb1e3289fa3f3c98f23de669c8aed776 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 16:48:17 -0800 Subject: [PATCH 11/12] Update MinGW URL --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 7a6c2a57..dea5d19f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,8 +16,8 @@ install: # Install MinGW. $url = "http://sourceforge.net/projects/mingw-w64/files/" $url += "Toolchains%20targetting%20Win64/Personal%20BUILDs/" - $url += "mingw-builds/4.9.0/threads-win32/seh/" - $url += "x86_64-4.9.0-release-win32-seh-rt_v3-rev2.7z/download" + $url += "mingw-builds/4.9.2/threads-win32/seh/" + $url += "x86_64-4.9.2-release-win32-seh-rt_v3-rev1.7z/download" Invoke-WebRequest -UserAgent wget -Uri $url -OutFile mingw.7z &7z x -oC:\ mingw.7z > $null } From c110f7b8d352ee63a2e971c21c429321a66f60bf Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Feb 2015 17:53:39 -0800 Subject: [PATCH 12/12] Move the code from appveyor config to a Python script No more PowerShell rubbish, yay! --- appveyor.yml | 31 +----------------------------- support/build.py | 28 +++++++++++++++++++++------ support/download.py | 46 +++++++++++++++++++++++++++++++++++++++++++++ support/timer.py | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 36 deletions(-) create mode 100644 support/download.py create mode 100644 support/timer.py diff --git a/appveyor.yml b/appveyor.yml index dea5d19f..63285a65 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,37 +10,8 @@ environment: - BUILD: mingw CONFIG: Release -install: - - ps: | - if ($env:BUILD -eq "mingw") { - # Install MinGW. - $url = "http://sourceforge.net/projects/mingw-w64/files/" - $url += "Toolchains%20targetting%20Win64/Personal%20BUILDs/" - $url += "mingw-builds/4.9.2/threads-win32/seh/" - $url += "x86_64-4.9.2-release-win32-seh-rt_v3-rev1.7z/download" - Invoke-WebRequest -UserAgent wget -Uri $url -OutFile mingw.7z - &7z x -oC:\ mingw.7z > $null - } - - set PATH=C:\Program Files (x86)\MSBUILD\12.0\bin\;%PATH%;C:\mingw64\bin - -before_build: - - python support/build.py - build_script: - - ps: | - if ($env:BUILD -eq "mingw") { - mingw32-make -j4 - } else { - msbuild /m:4 /p:Config=$env:CONFIG FORMAT.sln - } - -test_script: - - ps: | - if ($env:BUILD -eq "mingw") { - mingw32-make test - } else { - msbuild RUN_TESTS.vcxproj - } + - python support/build.py on_failure: - appveyor PushArtifact Testing/Temporary/LastTest.log diff --git a/support/build.py b/support/build.py index c2eed699..a58aea91 100755 --- a/support/build.py +++ b/support/build.py @@ -1,14 +1,30 @@ #!/usr/bin/env python # Build the project on AppVeyor. -from subprocess import check_call import os +from download import Downloader +from subprocess import check_call -env = os.environ -build = env['BUILD'] -cmake_command = ['cmake', '-DFMT_EXTRA_TESTS=ON', '-DCMAKE_BUILD_TYPE=' + env['CONFIG']] +build = os.environ['BUILD'] +cmake_command = ['cmake', '-DFMT_EXTRA_TESTS=ON', '-DCMAKE_BUILD_TYPE=' + os.environ['CONFIG']] +build_command = ['msbuild', '/m:4', '/p:Config=' + os.environ['CONFIG'], 'FORMAT.sln'] +test_command = ['msbuild', 'RUN_TESTS.vcxproj'] if build == 'mingw': + # Install MinGW. + mingw_url = 'http://sourceforge.net/projects/mingw-w64/files/' + \ + 'Toolchains%20targetting%20Win64/Personal%20Builds/' + \ + 'mingw-builds/4.9.2/threads-win32/seh/' + \ + 'x86_64-4.9.2-release-win32-seh-rt_v3-rev1.7z/download' + with Downloader().download(mingw_url) as f: + check_call(['7z', 'x', '-oC:\\', f]) + # Remove path to Git bin directory from $PATH because it breaks MinGW config. - env['PATH'] = env['PATH'].replace(r'C:\Program Files (x86)\Git\bin', '') + path = os.environ['PATH'].replace(r'C:\Program Files (x86)\Git\bin', '') + + os.environ['PATH'] = r'C:\Program Files (x86)\MSBUILD\12.0\bin\;' + path + r';C:\mingw64\bin' cmake_command.append('-GMinGW Makefiles') -check_call(cmake_command, env=env) + build_command = ['mingw32-make', '-j4'] + test_command = ['mingw32-make', 'test'] + +check_call(cmake_command) +check_call(build_command) diff --git a/support/download.py b/support/download.py new file mode 100644 index 00000000..dda7aa4e --- /dev/null +++ b/support/download.py @@ -0,0 +1,46 @@ +# A file downloader. + +import contextlib, os, tempfile, timer, urllib2, urlparse + +class Downloader: + def __init__(self, dir=None): + self.dir = dir + + # Downloads a file and removes it when exiting a block. + # Usage: + # d = Downloader() + # with d.download(url) as f: + # use_file(f) + def download(self, url, cookie=None): + suffix = os.path.splitext(urlparse.urlsplit(url)[2])[1] + fd, filename = tempfile.mkstemp(suffix=suffix, dir=self.dir) + os.close(fd) + with timer.print_time('Downloading', url, 'to', filename): + opener = urllib2.build_opener() + if cookie: + opener.addheaders.append(('Cookie', cookie)) + num_tries = 2 + for i in range(num_tries): + try: + f = opener.open(url) + except urllib2.URLError, e: + print('Failed to open url', url) + continue + length = f.headers.get('content-length') + if not length: + print('Failed to get content-length') + continue + length = int(length) + with open(filename, 'wb') as out: + count = 0 + while count < length: + data = f.read(1024 * 1024) + count += len(data) + out.write(data) + @contextlib.contextmanager + def remove(filename): + try: + yield filename + finally: + pass #os.remove(filename) + return remove(filename) diff --git a/support/timer.py b/support/timer.py new file mode 100644 index 00000000..8e33cee3 --- /dev/null +++ b/support/timer.py @@ -0,0 +1,35 @@ +# A with statement based timer. + +from __future__ import print_function +from contextlib import contextmanager +import timeit + +class Timer: + """ + A with statement based timer. + Usage: + t = Timer() + with t: + do_something() + time = t.time + """ + + def __enter__(self): + self.start = timeit.default_timer() + + def __exit__(self, type, value, traceback): + finish = timeit.default_timer() + self.time = finish - self.start + +@contextmanager +def print_time(*args): + """ + Measures and prints the time taken to execute nested code. + args: Additional arguments to print. + """ + t = Timer() + print(*args) + with t: + yield + print(*args, end=' ') + print('finished in {0:.2f} second(s)'.format(t.time))