]> git.tdb.fi Git - builder.git/blob - source/androidmanifestgenerator.cpp
Refactor InternalTask to take a functor
[builder.git] / source / androidmanifestgenerator.cpp
1 #include <msp/io/file.h>
2 #include <msp/io/print.h>
3 #include "androidmanifestfile.h"
4 #include "androidmanifestgenerator.h"
5 #include "component.h"
6 #include "internaltask.h"
7 #include "sharedlibrary.h"
8 #include "sourcepackage.h"
9
10 using namespace std;
11 using namespace Msp;
12
13 Target *AndroidManifestGenerator::create_target(const vector<Target *> &, const string &)
14 {
15         throw logic_error("not implemented");
16 }
17
18 Task *AndroidManifestGenerator::run(const Target &target) const
19 {
20         const AndroidManifestFile &manifest = dynamic_cast<const AndroidManifestFile &>(target);
21         return new InternalTask([&manifest]{ return _run(manifest); });
22 }
23
24 bool AndroidManifestGenerator::_run(const AndroidManifestFile &manifest)
25 {
26         const Component &comp = *manifest.get_component();
27         const SourcePackage &pkg = comp.get_package();
28
29         BuildInfo binfo;
30         manifest.collect_build_info(binfo);
31
32         IO::BufferedFile out(manifest.get_path().str(), IO::M_WRITE);
33         out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
34         IO::print(out, "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"%s\">\n", comp.get_name());
35         out.write("\t<uses-sdk android:minSdkVersion=\"9\" />\n");
36         // TODO Make the icon name configurable
37         bool debuggable = binfo.debug;
38         IO::print(out, "\t<application android:icon=\"@drawable/icon\" android:label=\"%s\" android:hasCode=\"false\" android:debuggable=\"%s\">\n", pkg.get_label(), debuggable);
39         if(SharedLibrary *native_lib = manifest.get_native_library())
40         {
41                 out.write("\t\t<activity android:name=\"android.app.NativeActivity\"");
42                 const string &orientation = manifest.get_orientation();
43                 if(!orientation.empty())
44                         IO::print(out, " android:screenOrientation=\"%s\"", orientation);
45                 out.write(">\n");
46                 IO::print(out, "\t\t\t<meta-data android:name=\"android.app.lib_name\" android:value=\"%s\" />\n", native_lib->get_libname());
47                 out.write("\t\t\t<intent-filter>\n");
48                 out.write("\t\t\t\t<action android:name=\"android.intent.action.MAIN\" />\n");
49                 out.write("\t\t\t\t<category android:name=\"android.intent.category.LAUNCHER\" />\n");
50                 out.write("\t\t\t</intent-filter>\n");
51                 out.write("\t\t</activity>\n");
52         }
53         out.write("\t</application>\n");
54         for(const string &p: manifest.get_permissions())
55                 IO::print(out, "\t<uses-permission android:name=\"%s\" />\n", p);
56         out.write("</manifest>\n");
57
58         return true;
59 }