| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Generate a snapshot file after loading all the scripts specified on the | 5 // Generate a snapshot file after loading all the scripts specified on the |
| 6 // command line. | 6 // command line. |
| 7 | 7 |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 private: | 190 private: |
| 191 Dart_Isolate snapshotted_isolate_; | 191 Dart_Isolate snapshotted_isolate_; |
| 192 | 192 |
| 193 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); | 193 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); |
| 194 }; | 194 }; |
| 195 | 195 |
| 196 Dart_Isolate UriResolverIsolateScope::isolate = NULL; | 196 Dart_Isolate UriResolverIsolateScope::isolate = NULL; |
| 197 | 197 |
| 198 | 198 |
| 199 static Dart_Handle ResolveScriptUri(const char* script_uri) { | 199 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) { |
| 200 bool failed = false; | 200 bool failed = false; |
| 201 char* result_string = NULL; | 201 char* result_string = NULL; |
| 202 | 202 |
| 203 { | 203 { |
| 204 UriResolverIsolateScope scope; | 204 UriResolverIsolateScope scope; |
| 205 | 205 |
| 206 // Run DartUtils::ResolveScriptUri in context of uri resolver isolate. | 206 // Run DartUtils::ResolveUriInWorkingDirectory in context of uri resolver |
| 207 // isolate. |
| 207 Dart_Handle builtin_lib = | 208 Dart_Handle builtin_lib = |
| 208 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 209 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 209 CHECK_RESULT(builtin_lib); | 210 CHECK_RESULT(builtin_lib); |
| 210 | 211 |
| 211 Dart_Handle result = DartUtils::ResolveScriptUri( | 212 Dart_Handle result = DartUtils::ResolveUriInWorkingDirectory( |
| 212 DartUtils::NewString(script_uri), builtin_lib); | 213 DartUtils::NewString(script_uri), builtin_lib); |
| 213 if (Dart_IsError(result)) { | 214 if (Dart_IsError(result)) { |
| 214 failed = true; | 215 failed = true; |
| 215 result_string = strdup(Dart_GetError(result)); | 216 result_string = strdup(Dart_GetError(result)); |
| 216 } else { | 217 } else { |
| 217 result_string = strdup(DartUtils::GetStringValue(result)); | 218 result_string = strdup(DartUtils::GetStringValue(result)); |
| 218 } | 219 } |
| 219 } | 220 } |
| 220 | 221 |
| 221 Dart_Handle result = failed ? Dart_NewApiError(result_string) : | 222 Dart_Handle result = failed ? Dart_NewApiError(result_string) : |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 return Dart_NewApiError("not a library"); | 304 return Dart_NewApiError("not a library"); |
| 304 } | 305 } |
| 305 Dart_Handle library_url = Dart_LibraryUrl(library); | 306 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 306 if (Dart_IsError(library_url)) { | 307 if (Dart_IsError(library_url)) { |
| 307 return Dart_NewApiError("accessing library url failed"); | 308 return Dart_NewApiError("accessing library url failed"); |
| 308 } | 309 } |
| 309 const char* library_url_string = DartUtils::GetStringValue(library_url); | 310 const char* library_url_string = DartUtils::GetStringValue(library_url); |
| 310 const char* mapped_library_url_string = DartUtils::MapLibraryUrl( | 311 const char* mapped_library_url_string = DartUtils::MapLibraryUrl( |
| 311 url_mapping, library_url_string); | 312 url_mapping, library_url_string); |
| 312 if (mapped_library_url_string != NULL) { | 313 if (mapped_library_url_string != NULL) { |
| 313 library_url = ResolveScriptUri(mapped_library_url_string); | 314 library_url = ResolveUriInWorkingDirectory(mapped_library_url_string); |
| 314 library_url_string = DartUtils::GetStringValue(library_url); | 315 library_url_string = DartUtils::GetStringValue(library_url); |
| 315 } | 316 } |
| 316 | 317 |
| 317 if (!Dart_IsString(url)) { | 318 if (!Dart_IsString(url)) { |
| 318 return Dart_NewApiError("url is not a string"); | 319 return Dart_NewApiError("url is not a string"); |
| 319 } | 320 } |
| 320 const char* url_string = DartUtils::GetStringValue(url); | 321 const char* url_string = DartUtils::GetStringValue(url); |
| 321 const char* mapped_url_string = DartUtils::MapLibraryUrl(url_mapping, | 322 const char* mapped_url_string = DartUtils::MapLibraryUrl(url_mapping, |
| 322 url_string); | 323 url_string); |
| 323 | 324 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 349 return Dart_LoadSource(library, url, | 350 return Dart_LoadSource(library, url, |
| 350 Builtin::PartSource(libraryBuiltinId, url_string), 0, 0); | 351 Builtin::PartSource(libraryBuiltinId, url_string), 0, 0); |
| 351 } | 352 } |
| 352 ASSERT(tag == Dart_kImportTag); | 353 ASSERT(tag == Dart_kImportTag); |
| 353 return DartUtils::NewError("Unable to import '%s' ", url_string); | 354 return DartUtils::NewError("Unable to import '%s' ", url_string); |
| 354 } | 355 } |
| 355 | 356 |
| 356 Dart_Handle resolved_url = url; | 357 Dart_Handle resolved_url = url; |
| 357 if (mapped_url_string != NULL) { | 358 if (mapped_url_string != NULL) { |
| 358 // Mapped urls are relative to working directory. | 359 // Mapped urls are relative to working directory. |
| 359 resolved_url = ResolveScriptUri(mapped_url_string); | 360 resolved_url = ResolveUriInWorkingDirectory(mapped_url_string); |
| 360 if (Dart_IsError(resolved_url)) { | 361 if (Dart_IsError(resolved_url)) { |
| 361 return resolved_url; | 362 return resolved_url; |
| 362 } | 363 } |
| 363 } | 364 } |
| 364 | 365 |
| 365 // Get the file path out of the url. | 366 // Get the file path out of the url. |
| 366 Dart_Handle file_path = FilePathFromUri( | 367 Dart_Handle file_path = FilePathFromUri( |
| 367 DartUtils::GetStringValue(resolved_url)); | 368 DartUtils::GetStringValue(resolved_url)); |
| 368 if (Dart_IsError(file_path)) { | 369 if (Dart_IsError(file_path)) { |
| 369 return file_path; | 370 return file_path; |
| 370 } | 371 } |
| 371 const char* raw_path = DartUtils::GetStringValue(file_path); | 372 const char* raw_path = DartUtils::GetStringValue(file_path); |
| 372 Dart_Handle source = DartUtils::ReadStringFromFile(raw_path); | 373 Dart_Handle source = DartUtils::ReadStringFromFile(raw_path); |
| 373 if (Dart_IsError(source)) { | 374 if (Dart_IsError(source)) { |
| 374 return source; | 375 return source; |
| 375 } | 376 } |
| 376 if (tag == Dart_kImportTag) { | 377 if (tag == Dart_kImportTag) { |
| 377 return Dart_LoadLibrary(url, source, 0, 0); | 378 return Dart_LoadLibrary(url, source, 0, 0); |
| 378 } else { | 379 } else { |
| 379 ASSERT(tag == Dart_kSourceTag); | 380 ASSERT(tag == Dart_kSourceTag); |
| 380 return Dart_LoadSource(library, url, source, 0, 0); | 381 return Dart_LoadSource(library, url, source, 0, 0); |
| 381 } | 382 } |
| 382 } | 383 } |
| 383 | 384 |
| 384 | 385 |
| 385 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { | 386 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { |
| 386 Dart_Handle resolved_script_uri = ResolveScriptUri(script_name); | 387 Dart_Handle resolved_script_uri = ResolveUriInWorkingDirectory(script_name); |
| 387 if (Dart_IsError(resolved_script_uri)) { | 388 if (Dart_IsError(resolved_script_uri)) { |
| 388 return resolved_script_uri; | 389 return resolved_script_uri; |
| 389 } | 390 } |
| 390 Dart_Handle script_path = FilePathFromUri( | 391 Dart_Handle script_path = FilePathFromUri( |
| 391 DartUtils::GetStringValue(resolved_script_uri)); | 392 DartUtils::GetStringValue(resolved_script_uri)); |
| 392 if (Dart_IsError(script_path)) { | 393 if (Dart_IsError(script_path)) { |
| 393 return script_path; | 394 return script_path; |
| 394 } | 395 } |
| 395 Dart_Handle source = DartUtils::ReadStringFromFile( | 396 Dart_Handle source = DartUtils::ReadStringFromFile( |
| 396 DartUtils::GetStringValue(script_path)); | 397 DartUtils::GetStringValue(script_path)); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 } | 621 } |
| 621 return 0; | 622 return 0; |
| 622 } | 623 } |
| 623 | 624 |
| 624 } // namespace bin | 625 } // namespace bin |
| 625 } // namespace dart | 626 } // namespace dart |
| 626 | 627 |
| 627 int main(int argc, char** argv) { | 628 int main(int argc, char** argv) { |
| 628 return dart::bin::main(argc, argv); | 629 return dart::bin::main(argc, argv); |
| 629 } | 630 } |
| OLD | NEW |