Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: runtime/bin/main.cc

Issue 19284006: Return a different exit code from the vm after compilation errors (issue 5525). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_debugger_api.h" 10 #include "include/dart_debugger_api.h"
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 586
587 const char* kFormat = "%s/%s"; 587 const char* kFormat = "%s/%s";
588 intptr_t len = strlen(script_name) + strlen(func_name) + 2; 588 intptr_t len = strlen(script_name) + strlen(func_name) + 2;
589 char* buffer = new char[len]; 589 char* buffer = new char[len];
590 ASSERT(buffer != NULL); 590 ASSERT(buffer != NULL);
591 snprintf(buffer, len, kFormat, script_name, func_name); 591 snprintf(buffer, len, kFormat, script_name, func_name);
592 return buffer; 592 return buffer;
593 } 593 }
594 594
595 595
596 static const int kErrorExitCode = 255; // Indicates we encountered an error. 596 // Exit code indicating a compilation error.
597 static const int kCompilationErrorExitCode = 254;
598
599 // Exit code indicating an unhandled error that is not a compilation error.
600 static const int kErrorExitCode = 255;
597 601
598 602
599 static int ErrorExit(const char* format, ...) { 603 static int ErrorExit(int exit_code, const char* format, ...) {
600 va_list arguments; 604 va_list arguments;
601 va_start(arguments, format); 605 va_start(arguments, format);
602 Log::VPrintErr(format, arguments); 606 Log::VPrintErr(format, arguments);
603 va_end(arguments); 607 va_end(arguments);
604 fflush(stderr); 608 fflush(stderr);
605 609
606 Dart_ExitScope(); 610 Dart_ExitScope();
607 Dart_ShutdownIsolate(); 611 Dart_ShutdownIsolate();
608 612
609 return kErrorExitCode; 613 return exit_code;
614 }
615
616
617 static int DartErrorExit(Dart_Handle error) {
618 const int exit_code = Dart_IsCompilationError(error) ?
619 kCompilationErrorExitCode : kErrorExitCode;
620 return ErrorExit(exit_code, "%s\n", Dart_GetError(error));
610 } 621 }
611 622
612 623
613 static void ShutdownIsolate(void* callback_data) { 624 static void ShutdownIsolate(void* callback_data) {
614 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); 625 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data);
615 EventHandler* handler = isolate_data->event_handler; 626 EventHandler* handler = isolate_data->event_handler;
616 if (handler != NULL) handler->Shutdown(); 627 if (handler != NULL) handler->Shutdown();
617 delete isolate_data; 628 delete isolate_data;
618 } 629 }
619 630
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 DartUtils::WriteMagicNumber(snapshot_file); 771 DartUtils::WriteMagicNumber(snapshot_file);
761 772
762 // Now write the snapshot out to specified file. 773 // Now write the snapshot out to specified file.
763 bool bytes_written = snapshot_file->WriteFully(buffer, size); 774 bool bytes_written = snapshot_file->WriteFully(buffer, size);
764 ASSERT(bytes_written); 775 ASSERT(bytes_written);
765 delete snapshot_file; 776 delete snapshot_file;
766 } else { 777 } else {
767 if (has_compile_all) { 778 if (has_compile_all) {
768 result = Dart_CompileAll(); 779 result = Dart_CompileAll();
769 if (Dart_IsError(result)) { 780 if (Dart_IsError(result)) {
770 return ErrorExit("%s\n", Dart_GetError(result)); 781 return DartErrorExit(result);
771 } 782 }
772 } 783 }
773 784
774 if (has_check_function_fingerprints) { 785 if (has_check_function_fingerprints) {
775 result = Dart_CheckFunctionFingerprints(); 786 result = Dart_CheckFunctionFingerprints();
776 if (Dart_IsError(result)) { 787 if (Dart_IsError(result)) {
777 return ErrorExit("%s\n", Dart_GetError(result)); 788 return DartErrorExit(result);
778 } 789 }
779 } 790 }
780 791
781 // Create a dart options object that can be accessed from dart code. 792 // Create a dart options object that can be accessed from dart code.
782 Dart_Handle options_result = 793 Dart_Handle options_result =
783 SetupRuntimeOptions(&dart_options, executable_name, script_name); 794 SetupRuntimeOptions(&dart_options, executable_name, script_name);
784 if (Dart_IsError(options_result)) { 795 if (Dart_IsError(options_result)) {
785 return ErrorExit("%s\n", Dart_GetError(options_result)); 796 return DartErrorExit(options_result);
786 } 797 }
787 // Lookup the library of the root script. 798 // Lookup the library of the root script.
788 Dart_Handle library = Dart_RootLibrary(); 799 Dart_Handle library = Dart_RootLibrary();
789 if (Dart_IsNull(library)) { 800 if (Dart_IsNull(library)) {
790 return ErrorExit("Unable to find root library for '%s'\n", 801 return ErrorExit(kErrorExitCode,
802 "Unable to find root library for '%s'\n",
791 script_name); 803 script_name);
792 } 804 }
793 // Set debug breakpoint if specified on the command line. 805 // Set debug breakpoint if specified on the command line.
794 if (breakpoint_at != NULL) { 806 if (breakpoint_at != NULL) {
795 result = SetBreakpoint(breakpoint_at, library); 807 result = SetBreakpoint(breakpoint_at, library);
796 if (Dart_IsError(result)) { 808 if (Dart_IsError(result)) {
797 return ErrorExit("Error setting breakpoint at '%s': %s\n", 809 return ErrorExit(kErrorExitCode,
810 "Error setting breakpoint at '%s': %s\n",
798 breakpoint_at, 811 breakpoint_at,
799 Dart_GetError(result)); 812 Dart_GetError(result));
800 } 813 }
801 } 814 }
802 if (has_print_script) { 815 if (has_print_script) {
803 result = GenerateScriptSource(); 816 result = GenerateScriptSource();
804 if (Dart_IsError(result)) { 817 if (Dart_IsError(result)) {
805 return ErrorExit("%s\n", Dart_GetError(result)); 818 return DartErrorExit(result);
806 } 819 }
807 } else { 820 } else {
808 // Lookup and invoke the top level main function. 821 // Lookup and invoke the top level main function.
809 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); 822 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL);
810 if (Dart_IsError(result)) { 823 if (Dart_IsError(result)) {
811 return ErrorExit("%s\n", Dart_GetError(result)); 824 return DartErrorExit(result);
812 } 825 }
813 826
814 // Keep handling messages until the last active receive port is closed. 827 // Keep handling messages until the last active receive port is closed.
815 result = Dart_RunLoop(); 828 result = Dart_RunLoop();
816 if (Dart_IsError(result)) { 829 if (Dart_IsError(result)) {
817 return ErrorExit("%s\n", Dart_GetError(result)); 830 return DartErrorExit(result);
818 } 831 }
819 } 832 }
820 } 833 }
821 834
822 Dart_ExitScope(); 835 Dart_ExitScope();
823 // Shutdown the isolate. 836 // Shutdown the isolate.
824 Dart_ShutdownIsolate(); 837 Dart_ShutdownIsolate();
825 // Terminate process exit-code handler. 838 // Terminate process exit-code handler.
826 Process::TerminateExitCodeHandler(); 839 Process::TerminateExitCodeHandler();
827 // Free copied argument strings if converted. 840 // Free copied argument strings if converted.
828 if (argv_converted) { 841 if (argv_converted) {
829 for (int i = 0; i < argc; i++) free(argv[i]); 842 for (int i = 0; i < argc; i++) free(argv[i]);
830 } 843 }
831 844
832 return Process::GlobalExitCode(); 845 return Process::GlobalExitCode();
833 } 846 }
834 847
835 } // namespace bin 848 } // namespace bin
836 } // namespace dart 849 } // namespace dart
837 850
838 int main(int argc, char** argv) { 851 int main(int argc, char** argv) {
839 return dart::bin::main(argc, argv); 852 return dart::bin::main(argc, argv);
840 } 853 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698