target out_dir in build script
This commit is contained in:
18
build.rs
18
build.rs
@@ -2,13 +2,15 @@ extern crate indexmap;
|
|||||||
|
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
|
|
||||||
use std::fs::{File, read_dir};
|
use std::env;
|
||||||
|
use std::fs::{File, copy, read_dir};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
fn main()
|
fn main()
|
||||||
{
|
{
|
||||||
let dest_path = Path::new("./src/prolog/machine/libraries.rs");
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
|
let dest_path = Path::new(&out_dir).join("libraries.rs");
|
||||||
|
|
||||||
let mut libraries = File::create(&dest_path).unwrap();
|
let mut libraries = File::create(&dest_path).unwrap();
|
||||||
let mut library_index = IndexSet::new();
|
let mut library_index = IndexSet::new();
|
||||||
@@ -18,14 +20,20 @@ fn main()
|
|||||||
for item in paths {
|
for item in paths {
|
||||||
let item = item.unwrap().path();
|
let item = item.unwrap().path();
|
||||||
|
|
||||||
if item.is_file() {
|
if let Some(file_name) = item.file_name() {
|
||||||
if let Some(ext) = item.extension() {
|
if let Some(ext) = item.extension() {
|
||||||
if ext == "pl" {
|
if ext == "pl" {
|
||||||
let file_stem = item.file_stem().unwrap();
|
let file_stem = item.file_stem().unwrap();
|
||||||
let file_str = file_stem.to_string_lossy().to_uppercase();
|
let file_str = file_stem.to_string_lossy().to_uppercase();
|
||||||
|
let dest = Path::new(&out_dir).join(file_name);
|
||||||
|
|
||||||
let include_line = format!("static {}: &str = include_str!(\"{}/{}.pl\");\n",
|
match copy(&item, dest) {
|
||||||
file_str, "../lib", file_stem.to_string_lossy());
|
Ok(_) => {},
|
||||||
|
Err(e) => panic!("die: {:?}", e)
|
||||||
|
};
|
||||||
|
|
||||||
|
let include_line = format!("static {}: &str = include_str!(\"{}.pl\");\n",
|
||||||
|
file_str, file_stem.to_string_lossy());
|
||||||
|
|
||||||
libraries.write_all(include_line.as_bytes()).unwrap();
|
libraries.write_all(include_line.as_bytes()).unwrap();
|
||||||
library_index.insert(file_stem.to_string_lossy().to_string());
|
library_index.insert(file_stem.to_string_lossy().to_string());
|
||||||
|
|||||||
@@ -790,8 +790,7 @@ impl ListingCompiler {
|
|||||||
&Declaration::Hook(hook, _, ref queue) if !hook.has_module_scope() => {
|
&Declaration::Hook(hook, _, ref queue) if !hook.has_module_scope() => {
|
||||||
worker.term_stream.incr_expansion_lens(hook, 1, queue.len())
|
worker.term_stream.incr_expansion_lens(hook, 1, queue.len())
|
||||||
}
|
}
|
||||||
&Declaration::UseModule(ModuleSource::File(_))
|
&Declaration::UseModule(_) | &Declaration::UseQualifiedModule(..) => {
|
||||||
| &Declaration::UseQualifiedModule(ModuleSource::File(_), _) => {
|
|
||||||
update_expansion_lengths = true
|
update_expansion_lengths = true
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ impl SubModuleUser for IndexStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
include!("libraries.rs");
|
include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
|
||||||
|
|
||||||
static TOPLEVEL: &str = include_str!("../toplevel.pl");
|
static TOPLEVEL: &str = include_str!("../toplevel.pl");
|
||||||
|
|
||||||
|
|||||||
25
src/tests.rs
25
src/tests.rs
@@ -1790,13 +1790,13 @@ fn test_queries_on_conditionals() {
|
|||||||
fn test_queries_on_modules() {
|
fn test_queries_on_modules() {
|
||||||
let mut wam = Machine::new(readline::input_stream());
|
let mut wam = Machine::new(readline::input_stream());
|
||||||
|
|
||||||
submit(&mut wam, ":- use_module('src/prolog/lib/lists.pl').");
|
submit(&mut wam, ":- use_module(library(lists)).");
|
||||||
|
|
||||||
submit_code(
|
submit_code(
|
||||||
&mut wam,
|
&mut wam,
|
||||||
"
|
"
|
||||||
:- module(my_lists, [local_member/2, reverse/2]).
|
:- module(my_lists, [local_member/2, reverse/2]).
|
||||||
:- use_module('src/prolog/lib/lists.pl', [member/2]).
|
:- use_module(library(lists), [member/2]).
|
||||||
|
|
||||||
local_member(X, Xs) :- member(X, Xs).
|
local_member(X, Xs) :- member(X, Xs).
|
||||||
|
|
||||||
@@ -1826,7 +1826,7 @@ reverse(Xs, Ys) :- lists:reverse(Xs, Ys).",
|
|||||||
|
|
||||||
submit(
|
submit(
|
||||||
&mut wam,
|
&mut wam,
|
||||||
":- use_module('src/prolog/lib/lists.pl', [reverse/2]).",
|
":- use_module(library(lists), [reverse/2]).",
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_prolog_success!(
|
assert_prolog_success!(
|
||||||
@@ -1836,7 +1836,7 @@ reverse(Xs, Ys) :- lists:reverse(Xs, Ys).",
|
|||||||
);
|
);
|
||||||
assert_prolog_success!(&mut wam, "reverse(_, _).");
|
assert_prolog_success!(&mut wam, "reverse(_, _).");
|
||||||
|
|
||||||
submit(&mut wam, ":- use_module('src/prolog/lib/lists.pl', []).");
|
submit(&mut wam, ":- use_module(library(lists), []).");
|
||||||
|
|
||||||
assert_prolog_success!(
|
assert_prolog_success!(
|
||||||
&mut wam,
|
&mut wam,
|
||||||
@@ -1849,7 +1849,7 @@ reverse(Xs, Ys) :- lists:reverse(Xs, Ys).",
|
|||||||
fn test_queries_on_builtins() {
|
fn test_queries_on_builtins() {
|
||||||
let mut wam = Machine::new(readline::input_stream());
|
let mut wam = Machine::new(readline::input_stream());
|
||||||
|
|
||||||
submit(&mut wam, ":- use_module('src/prolog/lib/lists.pl').");
|
submit(&mut wam, ":- use_module(library(lists)).");
|
||||||
|
|
||||||
assert_prolog_failure!(&mut wam, "atom(X).");
|
assert_prolog_failure!(&mut wam, "atom(X).");
|
||||||
assert_prolog_success!(&mut wam, "atom(a).");
|
assert_prolog_success!(&mut wam, "atom(a).");
|
||||||
@@ -2113,7 +2113,7 @@ fn test_queries_on_builtins() {
|
|||||||
assert_prolog_success!(&mut wam, "1.0 @=< 1.");
|
assert_prolog_success!(&mut wam, "1.0 @=< 1.");
|
||||||
assert_prolog_success!(&mut wam, "1 @=< 1.0.");
|
assert_prolog_success!(&mut wam, "1 @=< 1.0.");
|
||||||
|
|
||||||
submit(&mut wam, ":- use_module('src/prolog/lib/non_iso.pl').");
|
submit(&mut wam, ":- use_module(library(non_iso)).");
|
||||||
|
|
||||||
assert_prolog_success!(&mut wam, "variant(X, Y).");
|
assert_prolog_success!(&mut wam, "variant(X, Y).");
|
||||||
assert_prolog_failure!(&mut wam, "variant(f(X), f(x)).");
|
assert_prolog_failure!(&mut wam, "variant(f(X), f(x)).");
|
||||||
@@ -2696,7 +2696,7 @@ foo(X) :- call(X) -> call(X).",
|
|||||||
fn test_queries_on_setup_call_cleanup() {
|
fn test_queries_on_setup_call_cleanup() {
|
||||||
let mut wam = Machine::new(readline::input_stream());
|
let mut wam = Machine::new(readline::input_stream());
|
||||||
|
|
||||||
submit(&mut wam, ":- use_module('src/prolog/lib/non_iso.pl').");
|
submit(&mut wam, ":- use_module(library(non_iso)).");
|
||||||
|
|
||||||
// Test examples from the ISO Prolog page for setup_call_catch.
|
// Test examples from the ISO Prolog page for setup_call_catch.
|
||||||
assert_prolog_failure!(&mut wam, "setup_call_cleanup(false, _, _).");
|
assert_prolog_failure!(&mut wam, "setup_call_cleanup(false, _, _).");
|
||||||
@@ -2805,7 +2805,7 @@ fn test_queries_on_setup_call_cleanup() {
|
|||||||
fn test_queries_on_call_with_inference_limit() {
|
fn test_queries_on_call_with_inference_limit() {
|
||||||
let mut wam = Machine::new(readline::input_stream());
|
let mut wam = Machine::new(readline::input_stream());
|
||||||
|
|
||||||
submit(&mut wam, ":- use_module('src/prolog/lib/non_iso.pl').");
|
submit(&mut wam, ":- use_module(library(non_iso)).");
|
||||||
|
|
||||||
assert_prolog_success!(
|
assert_prolog_success!(
|
||||||
&mut wam,
|
&mut wam,
|
||||||
@@ -3027,7 +3027,7 @@ fn test_queries_on_call_with_inference_limit() {
|
|||||||
fn test_queries_on_dcgs() {
|
fn test_queries_on_dcgs() {
|
||||||
let mut wam = Machine::new(readline::input_stream());
|
let mut wam = Machine::new(readline::input_stream());
|
||||||
|
|
||||||
submit(&mut wam, ":- use_module('src/prolog/lib/dcgs.pl').");
|
submit(&mut wam, ":- use_module(library(dcgs)).");
|
||||||
|
|
||||||
// test case by YeGoblynQueene from hacker news.
|
// test case by YeGoblynQueene from hacker news.
|
||||||
submit_code(
|
submit_code(
|
||||||
@@ -3064,7 +3064,7 @@ fn test_queries_on_dcgs() {
|
|||||||
fn test_queries_on_string_lists() {
|
fn test_queries_on_string_lists() {
|
||||||
let mut wam = Machine::new(readline::input_stream());
|
let mut wam = Machine::new(readline::input_stream());
|
||||||
|
|
||||||
submit(&mut wam, ":- use_module('src/prolog/lib/non_iso.pl').");
|
submit(&mut wam, ":- use_module(library(non_iso)).");
|
||||||
|
|
||||||
// double_quotes is chars by default.
|
// double_quotes is chars by default.
|
||||||
assert_prolog_success!(&mut wam, "variant(\"\", []).");
|
assert_prolog_success!(&mut wam, "variant(\"\", []).");
|
||||||
@@ -3426,15 +3426,14 @@ fn test_queries_on_attributed_variables() {
|
|||||||
&mut wam,
|
&mut wam,
|
||||||
"
|
"
|
||||||
:- module(my_mod, []).
|
:- module(my_mod, []).
|
||||||
:- use_module('src/prolog/lib/atts.pl').
|
:- use_module(library(atts)).
|
||||||
|
|
||||||
:- attribute dif/1, frozen/1.",
|
:- attribute dif/1, frozen/1.",
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_prolog_success!(
|
assert_prolog_success!(
|
||||||
&mut wam,
|
&mut wam,
|
||||||
"( put_atts(V, my_mod, dif(1)) ; put_atts(V, my_mod, dif(2)) ),
|
"( put_atts(V, my_mod, dif(1)) ; put_atts(V, my_mod, dif(2)) ), get_atts(V, my_mod, L).",
|
||||||
get_atts(V, my_mod, L).",
|
|
||||||
[["L = [dif(1)]", "V = _10"], ["L = [dif(2)]", "V = _10"]]
|
[["L = [dif(1)]", "V = _10"], ["L = [dif(2)]", "V = _10"]]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user