1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*use common::cpp_build_config::CppBuildConfigData;
use common::cpp_lib_builder::{BuildType, CppLibBuilder};
use common::errors::fancy_unwrap;
use common::target;
use common::utils::{add_env_path_item, run_command};
use config::{Config, CrateProperties};
use std::path::PathBuf;
use std::process::Command;
use std::path::{Path, PathBuf};
#[derive(Debug)]
pub enum TempTestDir {
System(::tempdir::TempDir),
Custom(PathBuf),
}
impl TempTestDir {
pub fn new(name: &str) -> TempTestDir {
if let Ok(value) = ::std::env::var("CPP_TO_RUST_TEMP_TEST_DIR") {
let path = canonicalize(PathBuf::from(value)).unwrap().join(name);
create_dir_all(&path).unwrap();
TempTestDir::Custom(path)
} else {
TempTestDir::System(::tempdir::TempDir::new(name).unwrap())
}
}
pub fn path(&self) -> &Path {
match *self {
TempTestDir::System(ref dir) => dir.path(),
TempTestDir::Custom(ref path) => path,
}
}
}
fn build_cpp_lib() -> TempTestDir {
let cpp_lib_source_dir = {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("test_assets");
path.push("ctrt1");
path.push("cpp");
path
};
assert!(cpp_lib_source_dir.exists());
let temp_dir = TempTestDir::new("test_full_run");
let build_dir = temp_dir.path().join("build");
let install_dir = temp_dir.path().join("install");
if !build_dir.exists() {
create_dir(&build_dir).unwrap();
}
if !install_dir.exists() {
create_dir(&install_dir).unwrap();
}
fancy_unwrap(
CppLibBuilder {
cmake_source_dir: cpp_lib_source_dir,
build_dir: build_dir,
build_type: BuildType::Release,
install_dir: Some(install_dir),
num_jobs: None,
cmake_vars: Vec::new(),
}
.run(),
);
temp_dir
}
#[test]
fn full_run() {
let temp_dir = build_cpp_lib();
let crate_dir = temp_dir.path().join("crate");
let cpp_install_lib_dir = temp_dir.path().join("install").join("lib");
assert!(cpp_install_lib_dir.exists());
let crate_properties = CrateProperties::new("rust_ctrt1", "0.0.0");
let mut config = Config::new(
&crate_dir,
temp_dir.path().join("cache"),
crate_properties,
);
config.add_include_directive("ctrt1/all.h");
let include_path = {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("test_assets");
path.push("ctrt1");
path.push("cpp");
path.push("include");
path
};
let crate_template_path = {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("test_assets");
path.push("ctrt1");
path.push("crate");
path
};
assert!(include_path.exists());
config.add_include_path(&include_path);
config.add_target_include_path(&include_path);
{
let mut data = CppBuildConfigData::new();
data.add_linked_lib("ctrt1");
config
.cpp_build_config_mut()
.add(target::Condition::True, data);
}
{
let mut data = CppBuildConfigData::new();
data.add_compiler_flag("-fPIC");
data.add_compiler_flag("-std=gnu++11");
config
.cpp_build_config_mut()
.add(target::Condition::Env(target::Env::Msvc).negate(), data);
}
if target::current_env() == target::Env::Msvc {
config.add_cpp_parser_argument("-std=c++14");
} else {
config.add_cpp_parser_argument("-std=gnu++11");
}
config.set_crate_template_path(&crate_template_path);
fancy_unwrap(config.exec());
assert!(crate_dir.exists());
for cargo_cmd in &["update", "build", "test", "doc"] {
let mut command = Command::new("cargo");
command.arg(cargo_cmd);
command.arg("-v");
if *cargo_cmd != "update" {
command.arg("-j1");
}
// if *cargo_cmd == "test" {
// command.arg("--");
// command.arg("--nocapture");
// }
command.current_dir(&crate_dir);
command.env("CPP_TO_RUST_INCLUDE_PATHS", &include_path);
command.env("CPP_TO_RUST_LIB_PATHS", &cpp_install_lib_dir);
command.env(
"PATH",
add_env_path_item("PATH", vec![cpp_install_lib_dir.clone()]).unwrap(),
);
command.env(
"LD_LIBRARY_PATH",
add_env_path_item("LD_LIBRARY_PATH", vec![cpp_install_lib_dir.clone()]).unwrap(),
);
run_command(&mut command).unwrap();
}
}
*/