]> git.tdb.fi Git - builder.git/blob - source/tarballcomponent.cpp
c94103cafc6828c4478659ecd966712d4f5ae853
[builder.git] / source / tarballcomponent.cpp
1 #include <algorithm>
2 #include "builder.h"
3 #include "file.h"
4 #include "sourcepackage.h"
5 #include "tarballcomponent.h"
6 #include "tool.h"
7
8 using namespace std;
9
10 TarballComponent::TarballComponent(SourcePackage &p, const string &n):
11         Component(p, n)
12 { }
13
14 void TarballComponent::create_targets() const
15 {
16         Builder &builder = package.get_builder();
17
18         list<Target *> files;
19         SourceList source_filenames = collect_source_files();
20         for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
21         {
22                 FileTarget *file = builder.get_vfs().get_target(*i);
23                 if(!file)
24                         file = new File(builder, package, *i);
25                 files.push_back(file);
26         }
27
28         BuildGraph &build_graph = builder.get_build_graph();
29
30         string tarname = name;
31         if(name=="@src")
32         {
33                 tarname = package.get_name()+"-"+package.get_version();
34                 files.insert(files.begin(), &package.get_build_file());
35
36                 const BuildGraph::TargetMap &targets = build_graph.get_targets();
37                 for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
38                         if(i->second->get_package()==&package && !i->second->is_buildable())
39                                 if(find(files.begin(), files.end(), i->second)==files.end())
40                                         files.push_back(i->second);
41         }
42
43         const Toolchain &toolchain = builder.get_toolchain();
44         Target *result = toolchain.get_tool("TAR").create_target(files, tarname);
45         build_graph.get_target("tarballs")->add_dependency(*result);
46 }