diff options
author | John Hodge <tpg@mutabah.net> | 2017-08-20 22:15:35 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2017-08-20 22:15:35 +0800 |
commit | a99e49b7505d2912d8699d4c791b8b30c194024b (patch) | |
tree | cbd5940603be8811cf35f05e496445ec6c9c65dd | |
parent | 72571e39e4659cb32b82c633d45a0fcd7b8c5ffb (diff) | |
download | mrust-a99e49b7505d2912d8699d4c791b8b30c194024b.tar.gz |
minicargo - Makefile and posix_spawn
-rw-r--r-- | tools/minicargo/Makefile | 6 | ||||
-rw-r--r-- | tools/minicargo/build.cpp | 55 | ||||
-rw-r--r-- | tools/minicargo/debug.h | 4 | ||||
-rw-r--r-- | tools/minicargo/helpers.h | 3 | ||||
-rw-r--r-- | tools/minicargo/manifest.cpp | 6 | ||||
-rw-r--r-- | tools/minicargo/toml.h | 2 |
6 files changed, 64 insertions, 12 deletions
diff --git a/tools/minicargo/Makefile b/tools/minicargo/Makefile index ff7a5f4f..ab3f8531 100644 --- a/tools/minicargo/Makefile +++ b/tools/minicargo/Makefile @@ -9,10 +9,11 @@ V ?= @ OBJDIR := .obj/ BIN := ../bin/minicargo -OBJS := main.o +OBJS := main.o build.o manifest.o repository.o +OBJS += toml.o LINKFLAGS := -CXXFLAGS := -Wall +CXXFLAGS := -Wall -std=c++14 OBJS := $(OBJS:%=$(OBJDIR)%) @@ -29,6 +30,7 @@ $(BIN): $(OBJS) $V$(CXX) -o $@ $(OBJS) $(LINKFLAGS) $(OBJDIR)%.o: %.cpp + @mkdir -p $(dir $@) @echo [CXX] $< $V$(CXX) -o $@ -c $< $(CXXFLAGS) -MMD -MP -MF $@.dep diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp index 55e45c49..8127fbf0 100644 --- a/tools/minicargo/build.cpp +++ b/tools/minicargo/build.cpp @@ -7,7 +7,13 @@ #include <sstream> // stringstream #include "helpers.h" // path #ifdef _WIN32 -#include <Windows.h> +# include <Windows.h> +#else +# include <spawn.h> +# include <sys/types.h> +# include <sys/stat.h> +# include <sys/wait.h> +# include <fcntl.h> #endif struct BuildList @@ -218,7 +224,6 @@ bool Builder::spawn_process(const StringList& args, const ::helpers::path& logfi STARTUPINFO si = { 0 }; si.cb = sizeof(si); -#if 1 si.dwFlags = STARTF_USESTDHANDLES; si.hStdInput = NULL; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); @@ -231,7 +236,6 @@ bool Builder::spawn_process(const StringList& args, const ::helpers::path& logfi WriteFile(si.hStdOutput, cmdline_str.data(), cmdline_str.size(), &tmp, NULL); WriteFile(si.hStdOutput, "\n", 1, &tmp, NULL); } -#endif PROCESS_INFORMATION pi = { 0 }; char env[] = "MRUSTC_DEBUG=""\0" @@ -247,8 +251,49 @@ bool Builder::spawn_process(const StringList& args, const ::helpers::path& logfi return false; } #else - // TODO: posix_spawn - return false; + + // Create logfile output directory + mkdir(static_cast<::std::string>(logfile.parent()).c_str(), 0755); + + // Create handles such that the log file is on stdout + ::std::string logfile_str = logfile; + pid_t pid; + posix_spawn_file_actions_t fa; + { + posix_spawn_file_actions_init(&fa); + posix_spawn_file_actions_addopen(&fa, 1, logfile_str.c_str(), O_CREAT|O_WRONLY|O_TRUNC, 0644); + } + + // Generate `argv` + auto argv = args.get_vec(); + argv.insert(argv.begin(), "mrustc"); + DEBUG("Calling " << argv); + argv.push_back(nullptr); + + // Generate `envp` + ::std::vector<const char*> envp; + extern char **environ; + for(auto p = environ; *p; p++) + { + envp.push_back(*p); + } + envp.push_back(nullptr); + + if( posix_spawn(&pid, "../bin/mrustc", &fa, /*attr=*/nullptr, (char* const*)argv.data(), (char* const*)envp.data()) != 0 ) + { + perror("posix_spawn"); + DEBUG("Unable to spawn compiler"); + posix_spawn_file_actions_destroy(&fa); + return false; + } + posix_spawn_file_actions_destroy(&fa); + int status = -1; + waitpid(pid, &status, 0); + if( WEXITSTATUS(status) != 0 ) + { + DEBUG("Compiler exited with non-zero exit status " << WEXITSTATUS(status)); + return false; + } #endif return true; } diff --git a/tools/minicargo/debug.h b/tools/minicargo/debug.h index 5cc338e3..bff9ddf3 100644 --- a/tools/minicargo/debug.h +++ b/tools/minicargo/debug.h @@ -10,10 +10,10 @@ extern void Debug_Print(::std::function<void(::std::ostream& os)> cb); #define TODO(fmt) do { Debug_Print([&](auto& os){ os << "DEBUG: " << fmt; }); abort(); } while(0) namespace { - static void format_to_stream(::std::ostream& os) { + static inline void format_to_stream(::std::ostream& os) { } template<typename T, typename... A> - static void format_to_stream(::std::ostream& os, const T& v, const A&... a) { + static inline void format_to_stream(::std::ostream& os, const T& v, const A&... a) { os << v; format_to_stream(os, a...); } diff --git a/tools/minicargo/helpers.h b/tools/minicargo/helpers.h index 35e791f1..f2679ef4 100644 --- a/tools/minicargo/helpers.h +++ b/tools/minicargo/helpers.h @@ -1,6 +1,7 @@ #pragma once #include <string> +#include <cstring> namespace helpers { @@ -274,4 +275,4 @@ public: } }; -} // namespace helpers
\ No newline at end of file +} // namespace helpers diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp index d068b7bf..1bb815d8 100644 --- a/tools/minicargo/manifest.cpp +++ b/tools/minicargo/manifest.cpp @@ -190,6 +190,10 @@ PackageManifest PackageManifest::load_from_toml(const ::std::string& path) { // TODO: Build deps } + else if( section == "dev-dependencies" ) + { + // TODO: Developemnt (test/bench) deps + } else if( section == "patch" ) { //const auto& repo = key_val.path[1]; @@ -352,4 +356,4 @@ PackageVersionSpec PackageVersionSpec::from_string(const ::std::string& s) bool PackageVersionSpec::accepts(const PackageVersion& v) const { throw ""; -}
\ No newline at end of file +} diff --git a/tools/minicargo/toml.h b/tools/minicargo/toml.h index 17517ca3..6f145a2e 100644 --- a/tools/minicargo/toml.h +++ b/tools/minicargo/toml.h @@ -55,7 +55,7 @@ struct TomlValue { } - const char* what() const override { + const char* what() const noexcept override { return "toml type error"; } }; |