+++ /dev/null
-#include <msp/fs/utils.h>
-#include "androidpackagefile.h"
-#include "androidresourcebundle.h"
-#include "apkbuilder.h"
-#include "builder.h"
-#include "chainedtask.h"
-#include "component.h"
-#include "externaltask.h"
-#include "filetarget.h"
-#include "sourcepackage.h"
-
-using namespace std;
-using namespace Msp;
-
-// TODO Separate jar into its own tool and have this one just chain the two
-
-ApkBuilder::ApkBuilder(Builder &b):
- Tool(b, "APK"),
- jarsigner(0)
-{
- set_command("jar");
-}
-
-Target *ApkBuilder::create_target(const list<Target *> &sources, const string &)
-{
- AndroidResourceBundle *resource_bundle = 0;
- list<FileTarget *> other_files;
- for(Target *s: sources)
- {
- if(AndroidResourceBundle *r = dynamic_cast<AndroidResourceBundle *>(s))
- resource_bundle = r;
- else if(FileTarget *f = dynamic_cast<FileTarget *>(s))
- other_files.push_back(f);
- }
- AndroidPackageFile *apk = new AndroidPackageFile(builder, *resource_bundle->get_component(), *resource_bundle, other_files);
- apk->set_tool(*this);
- return apk;
-}
-
-void ApkBuilder::do_prepare()
-{
- jarsigner = &builder.get_toolchain().get_tool("JSGN");
- jarsigner->prepare();
-}
-
-Task *ApkBuilder::run(const Target &tgt) const
-{
- const AndroidPackageFile &apk = dynamic_cast<const AndroidPackageFile &>(tgt);
-
- ExternalTask::Arguments argv;
- argv.push_back(executable->get_path().str());
- argv.push_back("u");
-
- FS::Path input_path;
- list<FS::Path> files;
- for(Target *d: apk.get_dependencies())
- {
- FileTarget *file = dynamic_cast<FileTarget *>(d);
- Target *real = d->get_real_target();
-
- if(dynamic_cast<AndroidResourceBundle *>(real))
- input_path = file->get_path();
- else if(real->get_package()==apk.get_package())
- files.push_back(file->get_path());
- }
-
- FS::Path work_dir = FS::dirname(input_path);
-
- for(const FS::Path &f: files)
- argv.push_back(FS::relative(f, work_dir).str());
-
- ExternalTask *task = new ExternalTask(argv, work_dir);
- task->set_stdin(FS::basename(input_path));
- task->set_stdout(FS::relative(apk.get_path(), work_dir));
- ChainedTask *chain = new ChainedTask(task);
- chain->add_task(jarsigner->run(tgt));
- return chain;
-}