1 #include <msp/builder/builder.h>
2 #include <msp/builder/cache.h>
3 #include <msp/builder/component.h>
4 #include <msp/builder/file.h>
5 #include <msp/builder/sourcepackage.h>
6 #include <msp/fs/dir.h>
7 #include <msp/fs/stat.h>
8 #include <msp/fs/utils.h>
9 #include <msp/strings/regex.h>
10 #include "datatransform.h"
15 DataTransform::DataTransform(Builder &b, const Component &c, const FS::Path &p):
16 FileTarget(b, c.get_package(), p)
20 if(FS::Stat st = FS::lstat(FS::dirname(path)))
21 dir_mtime = st.get_modify_time();
24 void DataTransform::find_dependencies()
27 Cache &cache = component->get_package().get_cache();
28 const Time::TimeStamp &cache_mtime = cache.get_mtime();
29 if(mtime<cache_mtime && dir_mtime<cache_mtime && cache.has_key(this, "files"))
30 files = cache.get_values(this, "files");
33 builder.get_logger().log("files", "Reading imports from %s", path.str());
34 IO::File in(path.str());
35 DataFile::Parser parser(in, path.str());
37 vector<string> dir_files;
40 DataFile::Statement st = parser.parse();
41 if(st.keyword=="for_each")
43 // There's bound to be at least one file: the transform itself
46 FS::Path dir = FS::dirname(path);
47 builder.get_logger().log("files", "Traversing %s", dir.str());
48 dir_files = list_files(dir);
51 for(const DataFile::Value &a: st.args)
53 Regex re(a.get<string>());
54 for(const string &f: dir_files)
59 else if(st.keyword=="file" && st.args.size()==1)
60 files.push_back(st.args.front().get<string>());
63 cache.set_values(this, "files", files);
66 for(const string &f: files)
68 FS::Path file_path = FS::dirname(path)/f;
69 if(Target *tgt = builder.get_vfs().get_target(file_path))
70 add_transitive_dependency(*tgt);
72 add_transitive_dependency(*new File(builder, *package, file_path));