Skip to content

Commit a478a64

Browse files
authored
fix: Block .doo files as input in legacy CLI (#3967)
Also use the new CLI when executing Dafny files for the library and Simple Dafny backends.
1 parent 5134059 commit a478a64

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

Source/DafnyCore/Compilers/Dafny/DafnyBackend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override bool RunTargetProgram(string dafnyProgramName, string targetProg
4545
string targetFilename, ReadOnlyCollection<string> otherFileNames, object compilationResult, TextWriter outputWriter) {
4646
Contract.Requires(targetFilename != null || otherFileNames.Count == 0);
4747

48-
return RunTargetDafnyProgram(targetFilename, outputWriter);
48+
return RunTargetDafnyProgram(targetFilename, outputWriter, false);
4949
}
5050

5151
public DafnyBackend(DafnyOptions options) : base(options) {

Source/DafnyCore/Compilers/ExecutableBackend.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected static void WriteFromFile(string inputFilename, TextWriter outputWrite
116116
SinglePassCompiler.WriteFromStream(rd, outputWriter);
117117
}
118118

119-
protected bool RunTargetDafnyProgram(string targetFilename, TextWriter outputWriter) {
119+
protected bool RunTargetDafnyProgram(string targetFilename, TextWriter outputWriter, bool verify) {
120120

121121
/*
122122
* In order to work for the continuous integration, we need to call the Dafny compiler using dotnet
@@ -128,15 +128,17 @@ protected bool RunTargetDafnyProgram(string targetFilename, TextWriter outputWri
128128
var dafny = where + "/Dafny.dll";
129129

130130
var opt = Options;
131-
var psi = PrepareProcessStartInfo("dotnet", opt.MainArgs
132-
.Prepend("/compileTarget:cs")
133-
.Prepend("/compile:4")
134-
.Prepend("/compileVerbose:0")
135-
.Prepend("/printVerifiedProceduresCount:0")
136-
.Prepend("/noVerify")
137-
.Prepend(targetFilename)
138-
.Prepend(dafny));
139-
131+
var args = opt.MainArgs
132+
.Prepend(targetFilename);
133+
if (!verify) {
134+
args = args.Prepend("--no-verify");
135+
}
136+
args = args
137+
.Prepend("--target:cs")
138+
.Prepend("run")
139+
.Prepend(dafny);
140+
var psi = PrepareProcessStartInfo("dotnet", args);
141+
Console.Out.WriteLine(string.Join(", ", psi.ArgumentList));
140142
/*
141143
* When this code was written, the Dafny compiler cannot be made completely silent.
142144
* This is a problem for this specific compiler and the integration tests because the second

Source/DafnyCore/Compilers/Library/LibraryBackend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ public override bool RunTargetProgram(string dafnyProgramName, string targetProg
8383
ReadOnlyCollection<string> otherFileNames, object compilationResult, TextWriter outputWriter) {
8484

8585
var dooPath = DooFilePath(dafnyProgramName);
86-
return RunTargetDafnyProgram(dooPath, outputWriter);
86+
return RunTargetDafnyProgram(dooPath, outputWriter, true);
8787
}
8888
}

Source/DafnyCore/DooFile.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ private DooFile() {
113113
}
114114

115115
public bool Validate(string filePath, DafnyOptions options, Command currentCommand) {
116+
if (currentCommand == null) {
117+
options.Printer.ErrorWriteLine(Console.Out, $"Cannot load {filePath}: .doo files cannot be used with the legacy CLI");
118+
return false;
119+
}
120+
116121
if (options.VersionNumber != Manifest.DafnyVersion) {
117122
options.Printer.ErrorWriteLine(Console.Out, $"Cannot load {filePath}: it was built with Dafny {Manifest.DafnyVersion}, which cannot be used by Dafny {options.VersionNumber}");
118123
return false;

0 commit comments

Comments
 (0)