1 #include <msp/builder/builder.h>
2 #include <msp/builder/chainedtask.h>
3 #include <msp/builder/component.h>
4 #include <msp/builder/externaltask.h>
5 #include <msp/builder/filetarget.h>
6 #include <msp/builder/sourcepackage.h>
7 #include <msp/fs/utils.h>
8 #include "androidpackagefile.h"
9 #include "androidresourcebundle.h"
10 #include "apkbuilder.h"
15 // TODO Separate jar into its own tool and have this one just chain the two
17 ApkBuilder::ApkBuilder(Builder &b):
24 Target *ApkBuilder::create_target(const vector<Target *> &sources, const string &)
26 AndroidResourceBundle *resource_bundle = 0;
27 vector<FileTarget *> other_files;
28 other_files.reserve(sources.size());
29 for(Target *s: sources)
31 if(AndroidResourceBundle *r = dynamic_cast<AndroidResourceBundle *>(s))
33 else if(FileTarget *f = dynamic_cast<FileTarget *>(s))
34 other_files.push_back(f);
36 AndroidPackageFile *apk = new AndroidPackageFile(builder, *resource_bundle->get_component(), *resource_bundle, other_files);
41 void ApkBuilder::do_prepare(ToolData &tool) const
43 Tool *jarsigner = &builder.get_toolchain().get_tool("JSGN");
45 tool.extra_data = jarsigner;
48 Task *ApkBuilder::_run(const Target &tgt)
50 const AndroidPackageFile &apk = dynamic_cast<const AndroidPackageFile &>(tgt);
51 const ApkBuilder &tool = dynamic_cast<const ApkBuilder &>(*apk.get_tool());
53 ExternalTask::Arguments argv;
54 argv.push_back(tool.get_executable()->get_path().str());
58 vector<FS::Path> files;
59 files.reserve(apk.get_dependencies().size());
60 for(Target *d: apk.get_dependencies())
62 FileTarget *file = dynamic_cast<FileTarget *>(d);
63 Target *real = d->get_real_target();
65 if(dynamic_cast<AndroidResourceBundle *>(real))
66 input_path = file->get_path();
67 else if(real->get_package()==apk.get_package())
68 files.push_back(file->get_path());
71 FS::Path work_dir = FS::dirname(input_path);
73 for(const FS::Path &f: files)
74 argv.push_back(FS::relative(f, work_dir).str());
76 ExternalTask *task = new ExternalTask(argv, work_dir);
77 task->set_stdin(FS::basename(input_path));
78 task->set_stdout(FS::relative(apk.get_path(), work_dir));
79 ChainedTask *chain = new ChainedTask(task);
80 chain->add_task(tool.extra_data.value<Tool *>()->run(apk));