Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 163 lines (144 sloc) 4.73 kb
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
1 /**
2 * Appcelerator Kroll - licensed under the Apache Public License 2
3 * see LICENSE in the root folder for details on the license.
4 * Copyright (c) 2008-2009 Appcelerator, Inc. All Rights Reserved.
5 */
6 #include "boot.h"
7
8 namespace KrollBoot
9 {
10 string applicationHome;
11 string updateFile;
12 SharedApplication app = NULL;
13 int argc;
14 const char** argv;
15
16 void FindUpdate()
17 {
18 // Search for an update file in the application data directory.
19 // It will be placed there by the update service. If it exists
20 // and the version in the update file is greater than the
21 // current app version, we want to force an update.
62a4ab0 Changes for the filesystem to submit apps to the Apple App Store.
Alan DuBoff authored
22 string file = FileUtils::GetApplicationDataDirectory(GetApplicationName());
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
23 file = FileUtils::Join(file.c_str(), UPDATE_FILENAME, NULL);
9030999 @jhaynie update fixes
jhaynie authored
24
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
25 if (FileUtils::IsFile(file))
26 {
27 // If we find an update file, we want to resolve the modules that
28 // it requires and ignore our current manifest.
29 // On error: We should just continue on. A corrupt or old update manifest
30 // doesn't imply that the original application is corrupt.
31 SharedApplication update = Application::NewApplication(file, app->path);
9030999 @jhaynie update fixes
jhaynie authored
32 if (!update.isNull())
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
33 {
a39abf9 Fixes for application updates
Martin Robinson authored
34 update->SetArguments(argc, argv);
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
35 app = update;
36 updateFile = file;
37 }
38 }
39 }
40
5237840 If an app depends on SDKs, only install those.
Martin Robinson authored
41 vector<SharedDependency> FilterForSDKInstall(
42 vector<SharedDependency> dependencies)
43 {
44 // If this list of dependencies incluces the SDKs, just install
45 // those -- we assume that they also supply our other dependencies.
46 vector<SharedDependency>::iterator i = dependencies.begin();
47 vector<SharedDependency> justSDKs;
48
49 while (i != dependencies.end())
50 {
51 SharedDependency d = *i++;
52 if (d->type == KrollUtils::SDK || d->type == KrollUtils::MOBILESDK)
53 {
54 justSDKs.push_back(d);
55 }
56 }
57
628039d Small cleanup.
Martin Robinson authored
58 if (!justSDKs.empty())
5237840 If an app depends on SDKs, only install those.
Martin Robinson authored
59 {
60 return justSDKs;
61 }
62 else
63 {
64 return dependencies;
65 }
66 }
67
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
68 int Bootstrap()
69 {
70 applicationHome = GetApplicationHomePath();
71 string manifestPath = FileUtils::Join(applicationHome.c_str(), MANIFEST_FILENAME, NULL);
72 if (!FileUtils::IsFile(manifestPath))
73 {
0cff649 Improved error output for the boot.
Martin Robinson authored
74 string error("Application packaging error: no manifest was found at: ");
75 error.append(manifestPath);
76 ShowError(error);
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
77 return __LINE__;
78 }
b53d09e Support for invoking the installer from the API
Martin Robinson authored
79
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
80 app = Application::NewApplication(applicationHome);
81 if (app.isNull())
82 {
0cff649 Improved error output for the boot.
Martin Robinson authored
83 string error("Application packaging error: could not read manifest at: ");
84 error.append(manifestPath);
85 ShowError(error);
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
86 return __LINE__;
87 }
88 app->SetArguments(argc, argv);
89
90 // Look for a .update file in the app data directory
91 FindUpdate();
92
93 vector<SharedDependency> missing = app->ResolveDependencies();
c4064eb More debug info. Fixes for Win32 FileUtils.
Martin Robinson authored
94 if (app->HasArgument("debug"))
7066949 Small cleanups
Martin Robinson authored
95 {
c4064eb More debug info. Fixes for Win32 FileUtils.
Martin Robinson authored
96 vector<SharedComponent> resolved = app->GetResolvedComponents();
14331b3 Build fixes for Linux and OS X.
Martin Robinson authored
97 for (size_t i = 0; i < resolved.size(); i++)
c4064eb More debug info. Fixes for Win32 FileUtils.
Martin Robinson authored
98 {
99 SharedComponent c = resolved[i];
100 std::cout << "Resolved: (" << c->name << " "
101 << c->version << ") " << c->path << std::endl;
102 }
103 for (size_t i = 0; i < missing.size(); i++)
104 {
105 SharedDependency d = missing.at(i);
106 std::cerr << "Unresolved: " << d->name << " "
107 << d->version << std::endl;
108 }
7066949 Small cleanups
Martin Robinson authored
109 }
110
08a22c6 @marshall use force install when --force-install is passed in (right now only from...
marshall authored
111 bool forceInstall = app->HasArgument("--force-install");
628039d Small cleanup.
Martin Robinson authored
112 if (forceInstall || !missing.empty() || !app->IsInstalled() ||
113 !updateFile.empty())
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
114 {
5237840 If an app depends on SDKs, only install those.
Martin Robinson authored
115 // If this list of dependencies incluces the SDKs, just install
116 // those -- we assume that they also supply our other dependencies.
117 missing = FilterForSDKInstall(missing);
118
08a22c6 @marshall use force install when --force-install is passed in (right now only from...
marshall authored
119 if (!RunInstaller(missing, forceInstall))
b53d09e Support for invoking the installer from the API
Martin Robinson authored
120 {
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
121 return __LINE__;
b53d09e Support for invoking the installer from the API
Martin Robinson authored
122 }
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
123
124 missing = app->ResolveDependencies();
125 }
126
127 if (missing.size() > 0 || !app->IsInstalled())
128 {
129 // The user cancelled or the installer encountered an error
b53d09e Support for invoking the installer from the API
Martin Robinson authored
130 // -- which is should have already reported. We're not checking
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
131 // for updateFile.empty() here, because if the user cancelled
132 // the update, we just want to start the application as usual.
133 return __LINE__;
134 }
135
136 // Construct a list of module pathnames for setting up library paths
137 std::ostringstream moduleList;
138 vector<SharedComponent>::iterator i = app->modules.begin();
139 while (i != app->modules.end())
140 {
141 SharedComponent module = *i++;
142 moduleList << module->path << MODULE_SEPARATOR;
143 }
144
145 EnvironmentUtils::Set(BOOTSTRAP_ENV, "YES");
146 EnvironmentUtils::Set("KR_HOME", app->path);
147 EnvironmentUtils::Set("KR_RUNTIME", app->runtime->path);
148 EnvironmentUtils::Set("KR_MODULES", moduleList.str());
149
150 BootstrapPlatformSpecific(moduleList.str());
cd95c5f @marshall delete the update file after the initial bootstrap, restore win32 ABI co...
marshall authored
151 if (!updateFile.empty())
152 {
153 FileUtils::DeleteFile(updateFile);
154 }
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
155
cd95c5f @marshall delete the update file after the initial bootstrap, restore win32 ABI co...
marshall authored
156 string error = Blastoff();
fa37deb TI-277: Start of work on kroll component introspection
Martin Robinson authored
157 // If everything goes correctly, we should never get here
158 error = string("Launching application failed: ") + error;
159 ShowError(error, false);
160 return __LINE__;
161 }
162 }
Something went wrong with that request. Please try again.