Did you know ... Search Documentation:
qsave.pl -- Save current program as a state or executable
PublicShow source

This library provides qsave_program/1 and qsave_program/2, which are also used by the commandline sequence below.

swipl -o exe -c file.pl ...
Source qsave_program(+File) is det
Source qsave_program(+File, :Options) is det
Make a saved state in file `File'.
Source finalize_state(+Status, +StateStream:stream, +File:atom, +Options) is det[private]
Fixpu the result. Normally closes StateStream used to create File and makes the file executable.
Source exe_file(+Base, -Exe, +Options) is det[private]
True when Exe is the name of the file we create. This adds .exe to the given name on Windows.
Source system_specific_join(-How, +Options) is semidet[private]
Normally we create the saved state as a header with the zip file containing the actual state on its back. This is troublesome as the result looks like a normal executable, but does not satisfy the target system binary format. On some platforms we can do better and add the state as an additional section to the executable. This may fix issues using the executable with tools to manage binaries such as strip(1) or gdb.

This predicate succeeds, indicating how to perform the join, if the current platform supports this feature. After the zip file is created, join_exe_and_state/4 is called to join the emulator to the zip file.

Source join_exe_and_state(+How, +Emulator, +ZipFile, +Executable) is det[private]
Create Executable by combining Emulator with ZipFile. Emulator must be a native binary. Typically it is swipl.

Note that we use shell/1 rather than process_create/3. This would be easier, but we do not want dependencies on foreign code that is not needed.

Source shell_quote(+Arg, -QArg) is det[private]
Quote argument against shell. Currently uses either single or double quotes and refuses names containing a single quote and a $. Should we ignore any name holding a quote or $?
Source make_header(+Out:stream, +SaveClass, +Options) is det[private]
Write the header after which we add the zip file. This is normally either swipl[.exe] or a shell script.
Source save_options(+ArchiveHandle, +SaveClass, +Options)[private]
Save the options in the '$options' resource. The home directory is saved for development states to make it keep refering to the development home.

The script files (-s script) are not saved at all. I think this is fine to avoid a save-script loading itself.

Source save_option_value(+SaveClass, +OptionName, +OptionValue, -FinalValue)[private]
Source save_init_goals(+Stream, +Options)[private]
Save initialization goals. If there is a goal(Goal) option, use that, else save the goals from '$cmd_option_val'/2.
Source mkrcname(+Module, +NameSpec, -Name)[private]
Turn a resource name term into a resource name atom.
Source save_resource(+Zipper, +Name, +FileSpec, +Options) is det[private]
Add the content represented by FileSpec to Zipper under Name.
Source create_mapping(+Options) is det[private]
Call hook to obfuscate symbols.
Source lock_files(+SaveClass) is det[private]
When saving as runtime, lock all files such that when running the program the system stops checking existence and modification time on the filesystem.
To be done
- system is a poor name. Maybe use resource?
Source save_program(+Zipper, +SaveClass, +Options) is det[private]
Save the program itself as virtual machine code to Zipper.
Source prepare_entry_points(+Options)[private]
Prepare the --goal=Goal and --toplevel=Goal options. Preparing implies autoloading the definition and declaring it public such at it doesn't get obfuscated.
Source prepare_state(+Options) is det[private]
Prepare the executable by running the prepare_state registered initialization hooks.
Source save_autoload(+Options) is det[private]
Resolve all autoload dependencies.
Errors
- existence_error(procedures, List) if undefined(true) is in Options and there are undefined predicates.
Source save_module(+Module, +SaveClass)[private]
Saves a module
Source save_imports[private]
Save import relations. An import relation is saved if a predicate is imported from a module that is not a default module for the destination module. If the predicate is dynamic, we always define the explicit import relation to make clear that an assert must assert on the imported predicate.
Source restore_import(+TargetModule, +SourceModule, +PI) is det[private]
Restore import relation. This notably deals with imports from the module user, avoiding a message that the predicate is not exported.
Source restore_prolog_flag(+Name, +Value, +Type)[private]
Deal with possibly protected flags (debug_on_error and report_error are protected flags for the runtime kernel).
Source save_operators(+Options) is det[private]
Save operators for all modules. Operators for system are not saved because these are read-only anyway.
Source save_foreign_libraries(+Archive, +ExeFile, +Options) is det[private]
Save current foreign libraries into the archive.
Source copy_foreign_libraries(+Exe, +Options) is det[private]
Copy all required foreign libraries to an installation directory. This is currently only implemented for Windows, copying all .dll files to the directory where the executable is created.
Source find_foreign_library(+Architecture, +FileSpec, -EntryName, -File, -Time) is det[private]
Find the shared object specified by FileSpec for the named Architecture. EntryName will be the name of the file within the saved state archive. If posible, the shared object is stripped to reduce its size. This is achieved by calling strip -o <tmp> <shared-object>. Note that (if stripped) the file is a Prolog tmp file and will be deleted on halt.
bug
- Should perform OS search on failure
Source strip_file(+File, -Stripped) is det[private]
Try to strip File. Unify Stripped with File if stripping fails for some reason.
Source qsave:arch_shlib(+Architecture, +FileSpec, -File) is det[multifile]
This is a user defined hook called by qsave_program/2. It is used to find a shared library for the specified Architecture, named by FileSpec. FileSpec is of the form foreign(Name), a specification usable by absolute_file_name/2. The predicate should unify File with the absolute path for the shared library that corresponds to the specified Architecture.

If this predicate fails to find a file for the specified architecture an existence_error is thrown.

Source zipper_append_file(+Zipper, +Name, +File, +Options) is det[private]
Append the content of File under Name to the open Zipper.
Source zipper_add_directory(+Zipper, +Name, +Dir, +Options) is det[private]
Add a directory entry. Dir is only used if there is no option time(Stamp).
Source zipper_append_directory(+Zipper, +Name, +Dir, +Options) is det[private]
Append the content of Dir below Name in the resource archive. Options:
include(+Patterns)
Only add entries that match an element from Patterns using wildcard_match/2.
exclude(+Patterns)
Ignore entries that match an element from Patterns using wildcard_match/2.
To be done
- Process .gitignore. There also seem to exists other standards for this.
Source ignored(+File, +Options) is semidet[private]
Ignore File if there is an include(Patterns) option that does not match File or an exclude(Patterns) that does match File.
Source qsave_toplevel
Called to handle `-c file` compilaton.
 qsave_option(+Name, +ValueStrings, -Value) is semidet[private]

Re-exported predicates

The following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.

Source qsave_program(+File) is det
Source qsave_program(+File, :Options) is det
Make a saved state in file `File'.