summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-08-19 22:13:14 +0800
committerJohn Hodge <tpg@mutabah.net>2017-08-19 22:13:14 +0800
commit1f43a2f620521b7324923912228cf4bf13624bd0 (patch)
tree5565f0261afa0cb1437a9257cd1a7645d1720474 /tools
parent1b66d3257daf5dfb18128e5aaebb43568925587b (diff)
downloadmrust-1f43a2f620521b7324923912228cf4bf13624bd0.tar.gz
minicargo - Output redirection (windows)
Diffstat (limited to 'tools')
-rw-r--r--tools/minicargo/build.cpp6
-rw-r--r--tools/minicargo/main.cpp3
-rw-r--r--tools/minicargo/manifest.cpp31
-rw-r--r--tools/minicargo/manifest.h2
4 files changed, 33 insertions, 9 deletions
diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp
index a8032760..1d9b30ba 100644
--- a/tools/minicargo/build.cpp
+++ b/tools/minicargo/build.cpp
@@ -54,10 +54,12 @@ void MiniCargo_Build(const PackageManifest& manifest)
// Build dependencies
for(const auto& p : list.iter())
{
- p.build_lib();
+ if( ! p.build_lib() )
+ return ;
}
- manifest.build_lib();
+ if( ! manifest.build_lib() )
+ return ;
// TODO: If the manifest doesn't have a library, build the binary
}
diff --git a/tools/minicargo/main.cpp b/tools/minicargo/main.cpp
index b1e21c69..c2fe4c2e 100644
--- a/tools/minicargo/main.cpp
+++ b/tools/minicargo/main.cpp
@@ -45,7 +45,8 @@ int main(int argc, const char* argv[])
// 3. Build dependency tree
MiniCargo_Build(m);
- throw "";
+ ::std::cout << "Press any key to exit..." << ::std::endl;
+ ::std::cin.get();
return 0;
}
diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp
index 69660702..22b63005 100644
--- a/tools/minicargo/manifest.cpp
+++ b/tools/minicargo/manifest.cpp
@@ -227,13 +227,16 @@ namespace
}
-void PackageManifest::build_lib() const
+bool PackageManifest::build_lib() const
{
auto it = ::std::find_if(m_targets.begin(), m_targets.end(), [](const auto& x) { return x.m_type == PackageTarget::Type::Lib; });
if (it == m_targets.end())
{
throw ::std::runtime_error(::format("Package ", m_name, " doesn't have a library"));
}
+
+ auto outfile = ::helpers::path("output") / ::format("lib", it->m_name, ".hir");
+
::std::vector<::std::string> args;
args.push_back( ::helpers::path(m_manmifest_path).parent() / ::helpers::path(it->m_path) );
args.push_back("--crate-name"); args.push_back(it->m_name);
@@ -244,23 +247,41 @@ void PackageManifest::build_lib() const
cmdline << "mrustc.exe";
for(const auto& arg : args)
cmdline << " " << arg;
- DEBUG("Calling " << cmdline.str());
+ auto cmdline_str = cmdline.str();
+ DEBUG("Calling " << cmdline_str);
+
+ CreateDirectory(static_cast<::std::string>(outfile.parent()).c_str(), NULL);
STARTUPINFO si = {0};
- PROCESS_INFORMATION pi;
- CreateProcessA("x64\\Release\\mrustc.exe", (LPSTR)cmdline.str().c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
+ si.cb = sizeof(si);
+ si.dwFlags = STARTF_USESTDHANDLES;
+ si.hStdInput = NULL;
+ si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
+ {
+ SECURITY_ATTRIBUTES sa = {0};
+ sa.nLength = sizeof(sa);
+ sa.bInheritHandle = TRUE;
+ si.hStdOutput = CreateFile( (static_cast<::std::string>(outfile) + "_dbg.txt").c_str(), GENERIC_WRITE, FILE_SHARE_READ, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
+ DWORD tmp;
+ WriteFile(si.hStdOutput, cmdline_str.data(), cmdline_str.size(), &tmp, NULL);
+ WriteFile(si.hStdOutput, "\n", 1, &tmp, NULL);
+ }
+ PROCESS_INFORMATION pi = {0};
+ CreateProcessA("x64\\Release\\mrustc.exe", (LPSTR)cmdline_str.c_str(), NULL, NULL, TRUE, CREATE_NO_WINDOW, "MRUSTC_DEBUG=Parse\0", NULL, &si, &pi);
+ CloseHandle(si.hStdOutput);
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD status = 1;
GetExitCodeProcess(pi.hProcess, &status);
if(status != 0)
{
DEBUG("Compiler exited with non-zero exit status " << status);
- throw "";
+ return false;
}
#elif defined(__posix__)
//spawn();
#else
#endif
+ return true;
}
const PackageManifest& PackageRef::get_package() const
diff --git a/tools/minicargo/manifest.h b/tools/minicargo/manifest.h
index 7bbcfa9c..108a8d2b 100644
--- a/tools/minicargo/manifest.h
+++ b/tools/minicargo/manifest.h
@@ -109,7 +109,7 @@ class PackageManifest
PackageManifest();
public:
static PackageManifest load_from_toml(const ::std::string& path);
- void build_lib() const;
+ bool build_lib() const;
const ::std::vector<PackageRef>& dependencies() const {
return m_dependencies;