47
47
import waflib .Build
48
48
import waflib .Utils
49
49
import waflib .Options
50
- from waflib .TaskGen import before_method , feature
50
+ from waflib .TaskGen import before_method , after_method , feature
51
51
52
52
MAFVERSION = 'x'
53
53
MAFREVISION = 'x'
@@ -734,6 +734,8 @@ def __init__(self, **kw):
734
734
for key in ['source' , 'target' , 'features' ]:
735
735
_let_element_to_be_list (self .__dict__ , key )
736
736
737
+ self .__dict__ ['directory_target' ] = map (lambda x : x [:- 1 ], self .__dict__ ['target' ])
738
+
737
739
for key in ['for_each' , 'aggregate_by' ]:
738
740
if hasattr (self , key ):
739
741
_let_element_to_be_list (self .__dict__ , key )
@@ -745,6 +747,12 @@ def __init__(self, **kw):
745
747
else :
746
748
self .parameters = [Parameter (p ) for p in self .parameters ]
747
749
750
+ # preprocess to handle directory outputs
751
+ directory_target = list (filter (lambda x : x [- 1 ] == '/' , self .__dict__ ['target' ]))
752
+ if directory_target :
753
+ self .__dict__ ['features' ].append ('create_target_directory' )
754
+ self .__dict__ ['directory_target' ] = list (map (lambda x : x [:- 1 ], directory_target ))
755
+
748
756
# Some tests do not support the argument 'wscript'
749
757
if 'wscript' in kw :
750
758
relpath = self .wscript .parent .relpath ()
@@ -1102,6 +1110,23 @@ class OldExperimentContext(ExperimentContext):
1102
1110
fun = 'experiment'
1103
1111
variant = 'experiment'
1104
1112
1113
+ @feature ('create_target_directory' )
1114
+ @after_method ('process_rule' )
1115
+ def create_target_directory (self ):
1116
+ """Create directory of target node if the output is directory.
1117
+
1118
+ The flag feature of this method (create_target_directory)
1119
+ is set at constructor of CallObject.
1120
+
1121
+ """
1122
+
1123
+ def meta_sig (target_node ):
1124
+ name = target_node .name
1125
+ return name [name .find ('-' )+ 1 :]
1126
+
1127
+ for target_node in self .target :
1128
+ if meta_sig (target_node ) in self .directory_target :
1129
+ target_node .mkdir ()
1105
1130
1106
1131
@feature ('experiment' )
1107
1132
@before_method ('process_rule' )
0 commit comments