src/HOL/Mirabelle/lib/scripts/mirabelle.pl
author boehmes
Tue, 07 Aug 2012 10:28:04 +0200
changeset 48703 d408ff0abf23
parent 47732 503efdb07566
child 49549 3b0a60eee56e
permissions -rw-r--r--
extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
     1
#
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
     2
# Author: Jasmin Blanchette and Sascha Boehme
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
     3
#
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
     4
# Testing tool for automated proof tools.
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
     5
#
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
     6
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
     7
use File::Basename;
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
     8
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
     9
# environment
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    10
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    11
my $isabelle_home = $ENV{'ISABELLE_HOME'};
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    12
my $mirabelle_home = $ENV{'MIRABELLE_HOME'};
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    13
my $mirabelle_logic = $ENV{'MIRABELLE_LOGIC'};
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    14
my $mirabelle_theory = $ENV{'MIRABELLE_THEORY'};
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    15
my $output_path = $ENV{'MIRABELLE_OUTPUT_PATH'};
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    16
my $timeout = $ENV{'MIRABELLE_TIMEOUT'};
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32498
diff changeset
    17
my $be_quiet = $ENV{'MIRABELLE_QUIET'};
48703
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    18
my $user_setup_file = $ENV{'MIRABELLE_SETUP_FILE'};
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32498
diff changeset
    19
my $actions = $ENV{'MIRABELLE_ACTIONS'};
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    20
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    21
my $mirabelle_thy = $mirabelle_home . "/Mirabelle";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    22
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    23
48703
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    24
# argument
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    25
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32498
diff changeset
    26
my $thy_file = $ARGV[0];
48703
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    27
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    28
my ($thy_name, $path, $ext) = fileparse($thy_file, ".thy");
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    29
my $rand_suffix = join('', map { ('a'..'z')[rand(26)] } 1 .. 10);
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    30
my $new_thy_name = $thy_name . "_Mirabelle_" . $rand_suffix;
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    31
my $new_thy_file = $path . "/" . $new_thy_name . $ext;
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    32
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    33
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    34
# setup
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    35
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    36
my $setup_file;
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    37
my $setup_full_name;
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    38
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    39
if (-e $user_setup_file) {
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    40
  $setup_file = undef;
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    41
  my ($name, $path, $ext) = fileparse($user_setup_file, ".thy");
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    42
  $setup_full_name = $path . "/" . $name;
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    43
}
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    44
else {
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
    45
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    46
my $start_line = "0";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    47
my $end_line = "~1";
32454
a1a5589207ad Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents: 32434
diff changeset
    48
if ($thy_file =~ /^(.*)\[([0-9]+)\:(~?[0-9]+)\]$/) {
a1a5589207ad Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents: 32434
diff changeset
    49
  $thy_file = $1;
a1a5589207ad Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents: 32434
diff changeset
    50
  $start_line = $2;
a1a5589207ad Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents: 32434
diff changeset
    51
  $end_line = $3;
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    52
}
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    53
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    54
my $setup_thy_name = $thy_name . "_Setup";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    55
my $setup_file = $output_path . "/" . $setup_thy_name . ".thy";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    56
my $log_file = $output_path . "/" . $thy_name . ".log";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    57
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    58
my @action_files;
32396
e756600502cc keep the modified (tested) theory,
boehmes
parents: 32395
diff changeset
    59
my @action_names;
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    60
foreach (split(/:/, $actions)) {
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    61
  if (m/([^[]*)/) {
47730
15f4309bb9eb reversed Tools to Actions Mirabelle renaming;
sultana
parents: 47712
diff changeset
    62
    push @action_files, "\"$mirabelle_home/Tools/mirabelle_$1.ML\"";
32396
e756600502cc keep the modified (tested) theory,
boehmes
parents: 32395
diff changeset
    63
    push @action_names, $1;
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    64
  }
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    65
}
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    66
my $tools = "";
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    67
if ($#action_files >= 0) {
38895
ec417f748064 deal with duplicates
blanchet
parents: 37378
diff changeset
    68
  # uniquify
ec417f748064 deal with duplicates
blanchet
parents: 37378
diff changeset
    69
  my $s = join ("\n", @action_files);
ec417f748064 deal with duplicates
blanchet
parents: 37378
diff changeset
    70
  my @action_files = split(/\n/, $s . "\n" . $s);
ec417f748064 deal with duplicates
blanchet
parents: 37378
diff changeset
    71
  %action_files = sort(@action_files);
ec417f748064 deal with duplicates
blanchet
parents: 37378
diff changeset
    72
  $tools = "uses " . join(" ", sort(keys(%action_files)));
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    73
}
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    74
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    75
open(SETUP_FILE, ">$setup_file") || die "Could not create file '$setup_file'";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    76
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    77
print SETUP_FILE <<END;
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    78
theory "$setup_thy_name"
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    79
imports "$mirabelle_thy" "$mirabelle_theory"
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    80
$tools
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    81
begin
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    82
46824
1257c80988cd added Mirabelle action info in its log file; tuned;
sultana
parents: 42070
diff changeset
    83
setup {*
37378
5449c9aafdca Adapted Mirabelle script (cf. f60e4dd6d76f)
krauss
parents: 32522
diff changeset
    84
  Config.put_global Mirabelle.logfile "$log_file" #>
5449c9aafdca Adapted Mirabelle script (cf. f60e4dd6d76f)
krauss
parents: 32522
diff changeset
    85
  Config.put_global Mirabelle.timeout $timeout #>
5449c9aafdca Adapted Mirabelle script (cf. f60e4dd6d76f)
krauss
parents: 32522
diff changeset
    86
  Config.put_global Mirabelle.start_line $start_line #>
5449c9aafdca Adapted Mirabelle script (cf. f60e4dd6d76f)
krauss
parents: 32522
diff changeset
    87
  Config.put_global Mirabelle.end_line $end_line
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    88
*}
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    89
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    90
END
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    91
46824
1257c80988cd added Mirabelle action info in its log file; tuned;
sultana
parents: 42070
diff changeset
    92
@action_list = split(/:/, $actions);
1257c80988cd added Mirabelle action info in its log file; tuned;
sultana
parents: 42070
diff changeset
    93
1257c80988cd added Mirabelle action info in its log file; tuned;
sultana
parents: 42070
diff changeset
    94
foreach (reverse(@action_list)) {
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    95
  if (m/([^[]*)(?:\[(.*)\])?/) {
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    96
    my ($name, $settings_str) = ($1, $2 || "");
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    97
    $name =~ s/^([a-z])/\U$1/;
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    98
    print SETUP_FILE "setup {* Mirabelle_$name.invoke [";
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
    99
    my $sep = "";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   100
    foreach (split(/,/, $settings_str)) {
41361
d1e4a20911cb better parsing of options, in case the value has '='
blanchet
parents: 38898
diff changeset
   101
      if (m/\s*([^=]*)\s*=\s*(.*)\s*/) {
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   102
        print SETUP_FILE "$sep(\"$1\", \"$2\")";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   103
        $sep = ", ";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   104
      }
32522
1b70db55c811 Mirabelle: command-line action options may either be key=value or just key
boehmes
parents: 32521
diff changeset
   105
      elsif (m/\s*(.*)\s*/) {
46824
1257c80988cd added Mirabelle action info in its log file; tuned;
sultana
parents: 42070
diff changeset
   106
        print SETUP_FILE "$sep(\"$1\", \"\")";
1257c80988cd added Mirabelle action info in its log file; tuned;
sultana
parents: 42070
diff changeset
   107
        $sep = ", ";
32522
1b70db55c811 Mirabelle: command-line action options may either be key=value or just key
boehmes
parents: 32521
diff changeset
   108
      }
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   109
    }
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   110
    print SETUP_FILE "] *}\n";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   111
  }
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   112
}
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   113
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   114
print SETUP_FILE "\nend";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   115
close SETUP_FILE;
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   116
48703
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   117
$setup_full_name = $output_path . "/" . $setup_thy_name;
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   118
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   119
open(LOG_FILE, ">$log_file");
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   120
print LOG_FILE "Run of $new_thy_file with:\n";
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   121
foreach $action  (@action_list) {
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   122
  print LOG_FILE "  $action\n";
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   123
}
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   124
close(LOG_FILE);
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   125
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   126
}
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   127
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   128
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   129
# modify target theory file
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   130
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   131
open(OLD_FILE, "<$thy_file") || die "Cannot open file '$thy_file'";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   132
my @lines = <OLD_FILE>;
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   133
close(OLD_FILE);
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   134
48703
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   135
my $setup_import = substr("\"$setup_full_name\"" . (" " x 1000), 0, 1000);
47728
6ee015f6ea4b reintroduce file offsets in Mirabelle output, but make sure they are not influenced by the length of the path
blanchet
parents: 47712
diff changeset
   136
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   137
my $thy_text = join("", @lines);
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   138
my $old_len = length($thy_text);
32395
9692b0714295 do not introduce additional newlines
boehmes
parents: 32385
diff changeset
   139
$thy_text =~ s/(theory\s+)\"?$thy_name\"?/$1"$new_thy_name"/g;
47728
6ee015f6ea4b reintroduce file offsets in Mirabelle output, but make sure they are not influenced by the length of the path
blanchet
parents: 47712
diff changeset
   140
$thy_text =~ s/(imports)(\s+)/$1 $setup_import$2/g;
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   141
die "No 'imports' found" if length($thy_text) == $old_len;
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   142
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   143
open(NEW_FILE, ">$new_thy_file") || die "Cannot create file '$new_thy_file'";
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   144
print NEW_FILE $thy_text;
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   145
close(NEW_FILE);
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   146
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   147
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   148
# run isabelle
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   149
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32498
diff changeset
   150
my $quiet = "";
42070
d3404f32328a really be quiet
boehmes
parents: 42038
diff changeset
   151
my $output_log = 1;
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32498
diff changeset
   152
if (defined $be_quiet and $be_quiet ne "") {
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32498
diff changeset
   153
  $quiet = " > /dev/null 2>&1";
42070
d3404f32328a really be quiet
boehmes
parents: 42038
diff changeset
   154
  $output_log = 0;
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32498
diff changeset
   155
}
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   156
42070
d3404f32328a really be quiet
boehmes
parents: 42038
diff changeset
   157
if ($output_log) { print "Mirabelle: $thy_file\n"; }
32498
1132c7c13f36 Mirabelle: actions are responsible for handling exceptions,
boehmes
parents: 32496
diff changeset
   158
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32498
diff changeset
   159
my $result = system "\"$ENV{'ISABELLE_PROCESS'}\" " .
47712
81c3c4e01263 run Mirabelle in quick and dirty mode
blanchet
parents: 47477
diff changeset
   160
  "-e 'Unsynchronized.setmp quick_and_dirty true use_thy \"$path/$new_thy_name\" handle _ => exit 1;\n' -q $mirabelle_logic" . $quiet;
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32498
diff changeset
   161
48703
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   162
if ($output_log) {
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   163
  my $outcome = ($result ? "failure" : "success");
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   164
  print "\nFinished:  $thy_file  [$outcome]\n";
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   165
}
32498
1132c7c13f36 Mirabelle: actions are responsible for handling exceptions,
boehmes
parents: 32496
diff changeset
   166
1132c7c13f36 Mirabelle: actions are responsible for handling exceptions,
boehmes
parents: 32496
diff changeset
   167
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   168
# cleanup
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   169
48703
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   170
if (defined $setup_file) {
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   171
  unlink $setup_file;
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47732
diff changeset
   172
}
42033
60350051ef93 mirabelle: create modified theory file in original location, to ensure that its dependencies can be found (cf. aa8dce9ab8a9)
krauss
parents: 41361
diff changeset
   173
unlink $new_thy_file;
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents:
diff changeset
   174
42034
a77df5241959 propagate mirabelle failures properly;
krauss
parents: 42033
diff changeset
   175
exit ($result ? 1 : 0);