726 | | sep = Path.directorySeparatorChar.toString |
727 | | oldPaths = for path in paths get path.replace('\\', sep).replace('/', sep) |
728 | | paths.clear |
729 | | for path in oldPaths |
730 | | if File.exists(path) |
731 | | paths.add(path) |
732 | | else if Directory.exists(path) |
733 | | .error('Cannot process directories in general ("[path]").') |
734 | | else |
735 | | .error('Cannot find file "[path]".') |
736 | | if paths.count == 0 and not .options.buildStandardLibrary |
737 | | .error('No files to process.') |
| 734 | |
| 735 | if _options.isSpecified('embed-version'), .embedVersion( _options['embed-version'] to String) |
| 736 | |
| 737 | _fixupPaths(paths) |
750 | | if _options.containsKey('editor') |
751 | | spec = _options['editor'] to String? |
752 | | else |
753 | | spec = Environment.getEnvironmentVariable('COBRA_EDITOR') |
754 | | if spec and spec <> '' |
755 | | if spec.indexOf('FILE')==-1 |
756 | | .error('Missing FILE from editor spec.') |
757 | | if spec.indexOf('LINE')==-1 |
758 | | .error('Missing LINE from editor spec.') |
759 | | i = spec.indexOf('_') |
760 | | if i == -1 |
761 | | i = spec.indexOf(' ') |
762 | | if i == -1 |
763 | | .error('Missing underscore or space from editor spec.') |
764 | | exeName = spec.substring(0, i) |
765 | | args = spec.substring(i+1) |
766 | | for error in c.errors |
767 | | if error.isError and error.hasSourceSite |
768 | | if error.fileName.trim <> '' |
769 | | # trace error.fileName, error.lineNum |
770 | | args = args.replace('FILE', error.fileName) |
771 | | args = args.replace('LINE', error.lineNum.toString) |
772 | | p = System.Diagnostics.Process() |
773 | | p.startInfo.fileName = exeName |
774 | | p.startInfo.arguments = args |
775 | | p.startInfo.useShellExecute = false |
776 | | if _verbosity >= 3 |
777 | | print 'Running: [p.startInfo.fileName] [p.startInfo.arguments]' |
778 | | try |
779 | | p.start |
780 | | p.waitForExit # TODO: is this really needed? |
781 | | catch exc as Exception |
782 | | print 'Cannot invoke editor:' |
783 | | print ' Command: [p.startInfo.fileName] [p.startInfo.arguments]' |
784 | | print ' Exception: [exc]' |
785 | | break |
| 750 | _invokeEditor(c.errors) |
| 754 | def _fixupPaths(paths as List<of String>) |
| 755 | sep = Path.directorySeparatorChar.toString |
| 756 | oldPaths = for path in paths get path.replace('\\', sep).replace('/', sep) |
| 757 | paths.clear |
| 758 | for path in oldPaths |
| 759 | if File.exists(path) |
| 760 | paths.add(path) |
| 761 | else if Directory.exists(path) |
| 762 | .error('Cannot process directories in general ("[path]").') |
| 763 | else |
| 764 | .error('Cannot find file "[path]".') |
| 765 | if paths.count == 0 and not .options.buildStandardLibrary |
| 766 | .error('No files to process.') |
| 767 | |
| 768 | def _invokeEditor(compilerErrors as List<of SourceException>) |
| 769 | spec = if(_options.containsKey('editor'), _options['editor'] to String?, Environment.getEnvironmentVariable('COBRA_EDITOR')) |
| 770 | if spec and spec <> '' |
| 771 | if spec.indexOf('FILE')==-1, .error('Missing FILE from editor spec.') |
| 772 | if spec.indexOf('LINE')==-1, .error('Missing LINE from editor spec.') |
| 773 | i = spec.indexOf('_') |
| 774 | if i == -1 |
| 775 | i = spec.indexOf(' ') |
| 776 | if i == -1, .error('Missing underscore or space from editor spec.') |
| 777 | exeName = spec.substring(0, i) |
| 778 | args = spec.substring(i+1) |
| 779 | for error in compilerErrors #c.errors |
| 780 | if error.isError and error.hasSourceSite |
| 781 | if error.fileName.trim <> '' |
| 782 | # trace error.fileName, error.lineNum |
| 783 | args = args.replace('FILE', error.fileName) |
| 784 | args = args.replace('LINE', error.lineNum.toString) |
| 785 | p = System.Diagnostics.Process() |
| 786 | p.startInfo.fileName = exeName |
| 787 | p.startInfo.arguments = args |
| 788 | p.startInfo.useShellExecute = false |
| 789 | if _verbosity >= 3 |
| 790 | print 'Running: [p.startInfo.fileName] [p.startInfo.arguments]' |
| 791 | try |
| 792 | p.start |
| 793 | p.waitForExit # TODO: is this really needed? |
| 794 | catch exc as Exception |
| 795 | print 'Cannot invoke editor:' |
| 796 | print ' Command: [p.startInfo.fileName] [p.startInfo.arguments]' |
| 797 | print ' Exception: [exc]' |
| 798 | break |
| 799 | |
1066 | | |
1067 | | # embed the version |
| 1077 | if not _options.isSpecified('embed-version') |
| 1078 | _options['embed-version'] = 'compiler-version' |
| 1079 | _options.didSpecify('embed-version') |
| 1080 | .doCompile(List<of String>(), true, false, nil) |
| 1081 | |
| 1082 | def embedVersion(version as String) |
| 1083 | if version == 'compiler-version' or version == 'on', version = _embeddedCompilerVersion |
| 1084 | #TODO: push into backend - platform specific |
| 1085 | _options.addExtraUse('use System.Reflection') |
| 1086 | _options.addExtraSource("assembly\n\thas AssemblyVersion('[version]')\n") |
| 1087 | if _verbosity >= 1, print 'embed version "[version]"' |
| 1088 | |
| 1089 | def _embeddedCompilerVersion as String |