1 #include <msp/fs/dir.h>
2 #include <msp/fs/utils.h>
3 #include <msp/strings/format.h>
4 #include <msp/strings/regex.h>
8 #include "datatransform.h"
10 #include "sourcepackage.h"
15 DataTransform::DataTransform(Builder &b, const Component &c, const FS::Path &p):
16 FileTarget(b, c.get_package(), p)
21 void DataTransform::find_dependencies()
24 Cache &cache = component->get_package().get_cache();
25 // XXX Should check directory mtime as well
26 if(mtime<cache.get_mtime() && cache.has_key(this, "files"))
27 files = cache.get_values(this, "files");
30 builder.get_logger().log("files", format("Reading imports from %s", path.str()));
32 list<string> dir_files = list_files(FS::dirname(path));
33 IO::File in(path.str());
34 DataFile::Parser parser(in, path.str());
37 DataFile::Statement st = parser.parse();
38 if(st.keyword=="for_each")
40 for(DataFile::Statement::Arguments::const_iterator i=st.args.begin(); i!=st.args.end(); ++i)
42 Regex re(i->get<string>());
43 for(list<string>::const_iterator j=dir_files.begin(); j!=dir_files.end(); ++j)
48 else if(st.keyword=="file" && st.args.size()==1)
49 files.push_back(st.args.front().get<string>());
52 cache.set_values(this, "files", files);
55 for(list<string>::iterator i=files.begin(); i!=files.end(); ++i)
57 FS::Path file_path = FS::dirname(path)/ *i;
58 if(Target *tgt = builder.get_vfs().get_target(file_path))
61 add_dependency(*new File(builder, *package, file_path));