|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75872 - in trunk/tools/build/v2: engine test
From: steven_at_[hidden]
Date: 2011-12-08 22:56:03
Author: steven_watanabe
Date: 2011-12-08 22:56:02 EST (Thu, 08 Dec 2011)
New Revision: 75872
URL: http://svn.boost.org/trac/boost/changeset/75872
Log:
Handle STDOUT and STDERR in @ files.
Added:
trunk/tools/build/v2/test/core_at_file.py (contents, props changed)
Text files modified:
trunk/tools/build/v2/engine/function.c | 44 +++++++++++++++++++++++++++++++++++++--
trunk/tools/build/v2/engine/pathsys.h | 1
trunk/tools/build/v2/test/test_all.py | 1
3 files changed, 43 insertions(+), 3 deletions(-)
Modified: trunk/tools/build/v2/engine/function.c
==============================================================================
--- trunk/tools/build/v2/engine/function.c (original)
+++ trunk/tools/build/v2/engine/function.c 2011-12-08 22:56:02 EST (Thu, 08 Dec 2011)
@@ -16,6 +16,8 @@
#include "compile.h"
#include "search.h"
#include "class.h"
+#include "pathsys.h"
+#include "filesys.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -3241,13 +3243,47 @@
{
string buf[1];
const char * out;
- LIST * filename;
+ OBJECT * tmp_filename = 0;
int out_debug = DEBUG_EXEC ? 1 : 0;
FILE * out_file = 0;
string_new( buf );
combine_strings( s, code->arg, buf );
- filename = stack_top( s );
- out = object_str( filename->value );
+ out = object_str( stack_top( s )->value );
+
+ /* For stdout/stderr we will create a temp file and generate
+ * a command that outputs the content as needed.
+ */
+ if ( ( strcmp( "STDOUT", out ) == 0 ) ||
+ ( strcmp( "STDERR", out ) == 0 ) )
+ {
+ int err_redir = strcmp( "STDERR", out ) == 0;
+ string result[1];
+ tmp_filename = path_tmpfile();
+ string_new( result );
+
+ #ifdef OS_NT
+ string_append( result, "type \"" );
+ #else
+ string_append( result, "cat \"" );
+ #endif
+ string_append( result, object_str( tmp_filename ) );
+ string_push_back( result, '\"' );
+ if ( err_redir )
+ string_append( result, " 1>&2" );
+
+ /* Replace STDXXX with the temporary file. */
+ list_free( stack_pop( s ) );
+ stack_push( s, list_new( L0, object_new( result->value ) ) );
+ out = object_str( tmp_filename );
+
+ string_free( result );
+
+ /* We also make sure that the temp files created by this
+ * get nuked eventually.
+ */
+ file_remove_atexit( tmp_filename );
+ }
+
if ( !globs.noexec )
{
string out_name[1];
@@ -3279,6 +3315,8 @@
fflush( out_file );
fclose( out_file );
string_free( buf );
+ if ( tmp_filename )
+ object_free( tmp_filename );
if ( out_debug ) fputc( '\n', stdout );
Modified: trunk/tools/build/v2/engine/pathsys.h
==============================================================================
--- trunk/tools/build/v2/engine/pathsys.h (original)
+++ trunk/tools/build/v2/engine/pathsys.h 2011-12-08 22:56:02 EST (Thu, 08 Dec 2011)
@@ -20,6 +20,7 @@
#ifndef PATHSYS_VP_20020211_H
# define PATHSYS_VP_20020211_H
+#include "jam.h"
#include "strings.h"
#include "object.h"
Added: trunk/tools/build/v2/test/core_at_file.py
==============================================================================
--- (empty file)
+++ trunk/tools/build/v2/test/core_at_file.py 2011-12-08 22:56:02 EST (Thu, 08 Dec 2011)
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+
+# Copyright 2011 Steven Watanabe
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+
+
+import BoostBuild
+import os
+
+t = BoostBuild.Tester(pass_toolset=0)
+
+t.write("file.jam", """
+name = n1 n2 ;
+contents = M1 M2 ;
+EXIT file: "@(o$(name) .txt:E= test -D$(contents))" : 0 ;
+""")
+
+t.run_build_system("-ffile.jam")
+t.expect_output_line("file: on1 on2 .txt");
+t.expect_addition("on1 on2 .txt")
+t.expect_content("on1 on2 .txt", " test -DM1 -DM2", True)
+
+t.rm(".")
+
+t.write("file.jam", """
+name = n1 n2 ;
+contents = M1 M2 ;
+actions run {
+echo file: "@(o$(name) .txt:E= test -D$(contents))"
+}
+
+run all ;
+
+""")
+
+t.run_build_system("-ffile.jam -d2")
+t.expect_output_line('echo file: "on1 on2 .txt"');
+t.expect_addition("on1 on2 .txt")
+t.expect_content("on1 on2 .txt", " test -DM1 -DM2", True)
+
+t.rm(".")
+
+t.write("file.jam", """
+name = n1 n2 ;
+contents = M1 M2 ;
+file = "@($(STDOUT):E= test -D$(contents)\n)" ;
+
+actions run {
+$(file)
+}
+
+run all ;
+""")
+
+t.run_build_system("-ffile.jam -d1")
+t.expect_output_line(" test -DM1 -DM2")
+
+t.rm(".")
+
+t.write("file.jam", """
+name = n1 n2 ;
+contents = M1 M2 ;
+actions run {
+@($(STDOUT):E= test -D$(contents)\n)
+}
+
+run all ;
+
+""")
+
+t.run_build_system("-ffile.jam -d1")
+t.expect_output_line(" test -DM1 -DM2")
+
+t.cleanup()
Modified: trunk/tools/build/v2/test/test_all.py
==============================================================================
--- trunk/tools/build/v2/test/test_all.py (original)
+++ trunk/tools/build/v2/test/test_all.py 2011-12-08 22:56:02 EST (Thu, 08 Dec 2011)
@@ -142,6 +142,7 @@
"copy_time",
"core_action_status",
"core_actions_quietly",
+ "core_at_file",
"core_bindrule",
"core_nt_line_length",
"core_option_d2",
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk