1 #include <msp/fs/utils.h>
2 #include "androidpackagefile.h"
3 #include "androidresourcebundle.h"
4 #include "apkbuilder.h"
6 #include "chainedtask.h"
8 #include "externaltask.h"
9 #include "filetarget.h"
10 #include "sourcepackage.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 list<Target *> &sources, const string &)
26 AndroidResourceBundle *resource_bundle = 0;
27 list<FileTarget *> other_files;
28 for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
30 if(AndroidResourceBundle *r = dynamic_cast<AndroidResourceBundle *>(*i))
32 else if(FileTarget *f = dynamic_cast<FileTarget *>(*i))
33 other_files.push_back(f);
35 AndroidPackageFile *apk = new AndroidPackageFile(builder, *resource_bundle->get_component(), *resource_bundle, other_files);
40 void ApkBuilder::do_prepare()
42 jarsigner = &builder.get_toolchain().get_tool("JSGN");
46 Task *ApkBuilder::run(const Target &tgt) const
48 const AndroidPackageFile &apk = dynamic_cast<const AndroidPackageFile &>(tgt);
50 ExternalTask::Arguments argv;
51 argv.push_back(executable->get_path().str());
54 const Target::Dependencies &depends = apk.get_dependencies();
57 for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
59 FileTarget *file = dynamic_cast<FileTarget *>(*i);
60 Target *real = (*i)->get_real_target();
62 if(dynamic_cast<AndroidResourceBundle *>(real))
63 input_path = file->get_path();
64 else if(real->get_package()==apk.get_package())
65 files.push_back(file->get_path());
68 FS::Path work_dir = FS::dirname(input_path);
70 for(list<FS::Path>::const_iterator i=files.begin(); i!=files.end(); ++i)
71 argv.push_back(FS::relative(*i, work_dir).str());
73 ExternalTask *task = new ExternalTask(argv, work_dir);
74 task->set_stdin(FS::basename(input_path));
75 task->set_stdout(FS::relative(apk.get_path(), work_dir));
76 ChainedTask *chain = new ChainedTask(task);
77 chain->add_task(jarsigner->run(tgt));