src/Pure/Build/export.ML
author wenzelm
Fri, 07 Jun 2024 11:44:15 +0200
changeset 80287 a3a1ec0c47ab
parent 79502 c7a98469c0e7
permissions -rw-r--r--
clarified signature: separate formal context from exported theory_name;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
79502
c7a98469c0e7 clarified directories;
wenzelm
parents: 75604
diff changeset
     1
(*  Title:      Pure/Build/export.ML
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     3
79502
c7a98469c0e7 clarified directories;
wenzelm
parents: 75604
diff changeset
     4
Manage per-session theory exports: compressed blobs.
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     5
*)
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     6
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     7
signature EXPORT =
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     8
sig
80287
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
     9
  val report: Context.generic -> string -> Path.binding -> unit
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    10
  type params =
80287
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    11
    {theory_name: string, binding: Path.binding, executable: bool, compress: bool, strict: bool}
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    12
  val export_params: Context.generic -> params -> XML.body -> unit
70991
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70907
diff changeset
    13
  val export: theory -> Path.binding -> XML.body -> unit
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70907
diff changeset
    14
  val export_executable: theory -> Path.binding -> XML.body -> unit
70015
c8e08d8ffb93 clarified signature: more explicit type Path.binding;
wenzelm
parents: 70013
diff changeset
    15
  val export_file: theory -> Path.binding -> Path.T -> unit
c8e08d8ffb93 clarified signature: more explicit type Path.binding;
wenzelm
parents: 70013
diff changeset
    16
  val export_executable_file: theory -> Path.binding -> Path.T -> unit
70009
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    17
  val markup: theory -> Path.T -> Markup.T
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    18
  val message: theory -> Path.T -> string
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    19
end;
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    20
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    21
structure Export: EXPORT =
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    22
struct
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    23
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    24
(* export *)
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    25
80287
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    26
fun report context theory_name binding =
70051
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    27
  let
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    28
    val (path, pos) = Path.dest_binding binding;
72511
460d743010bc clarified signature: overloaded "+" for Path.append;
wenzelm
parents: 72103
diff changeset
    29
    val markup = Markup.export_path (Path.implode (Path.basic theory_name + path));
80287
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    30
  in Context_Position.report_generic context pos markup end;
70051
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    31
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    32
type params =
80287
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    33
  {theory_name: string, binding: Path.binding, executable: bool, compress: bool, strict: bool};
68105
577072a0ceed more checks;
wenzelm
parents: 68102
diff changeset
    34
80287
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    35
fun export_params context ({theory_name, binding, executable, compress, strict}: params) body =
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    36
 (report context theory_name binding;
70051
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    37
  (Output.try_protocol_message o Markup.export)
74166
ff3dbb2be924 tuned signature;
wenzelm
parents: 73559
diff changeset
    38
   {id = Position.id_of (Position.thread_data ()),
70051
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    39
    serial = serial (),
80287
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    40
    theory_name = theory_name,
70055
36fb663145e5 type Path.binding may be empty: check later via proper_binding;
wenzelm
parents: 70051
diff changeset
    41
    name = Path.implode_binding (tap Path.proper_binding binding),
70051
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    42
    executable = executable,
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    43
    compress = compress,
73559
22b5ecb53dd9 more uniform use of Byte_Message;
wenzelm
parents: 72511
diff changeset
    44
    strict = strict} [body]);
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    45
70991
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70907
diff changeset
    46
fun export thy binding body =
80287
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    47
  export_params (Context.Theory thy)
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    48
    {theory_name = Context.theory_long_name thy, binding = binding,
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    49
      executable = false, compress = true, strict = true} body;
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    50
70991
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70907
diff changeset
    51
fun export_executable thy binding body =
80287
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    52
  export_params (Context.Theory thy)
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    53
    {theory_name = Context.theory_long_name thy, binding = binding,
a3a1ec0c47ab clarified signature: separate formal context from exported theory_name;
wenzelm
parents: 79502
diff changeset
    54
      executable = true, compress = true, strict = true} body;
70013
6de8b7a5cd44 tuned signature -- more operations;
wenzelm
parents: 70011
diff changeset
    55
70991
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70907
diff changeset
    56
fun export_file thy binding file =
75604
39df30349778 more scalable generated files and code export, using Bytes.T;
wenzelm
parents: 74166
diff changeset
    57
  export thy binding (Bytes.contents_blob (Bytes.read file));
70991
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70907
diff changeset
    58
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70907
diff changeset
    59
fun export_executable_file thy binding file =
75604
39df30349778 more scalable generated files and code export, using Bytes.T;
wenzelm
parents: 74166
diff changeset
    60
  export_executable thy binding (Bytes.contents_blob (Bytes.read file));
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    61
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    62
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    63
(* information message *)
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    64
70009
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    65
fun markup thy path =
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    66
  let
72511
460d743010bc clarified signature: overloaded "+" for Path.append;
wenzelm
parents: 72103
diff changeset
    67
    val thy_path = Path.basic (Context.theory_long_name thy) + path;
70009
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    68
    val name = (Markup.nameN, Path.implode thy_path);
69650
c95edf19133b clarified message;
wenzelm
parents: 69648
diff changeset
    69
  in Active.make_markup Markup.theory_exportsN {implicit = false, properties = [name]} end;
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    70
70009
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    71
fun message thy path =
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    72
  "See " ^ Markup.markup (markup thy path) "theory exports";
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    73
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    74
end;