summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-08-21 22:32:48 +0800
committerJohn Hodge <tpg@mutabah.net>2017-08-21 22:32:48 +0800
commit8ca7753af27a431c9b2f8bec98b5cecc83fa452d (patch)
tree44dd706522882e91540d06b9ce226b9836513075 /tools
parentaf317dcd9059ee78e4c8f36d9c67eb38fdf07709 (diff)
downloadmrust-8ca7753af27a431c9b2f8bec98b5cecc83fa452d.tar.gz
minicargo - Rough support for build scripts (override file only)
Diffstat (limited to 'tools')
-rw-r--r--tools/minicargo/Makefile2
-rw-r--r--tools/minicargo/build.cpp89
-rw-r--r--tools/minicargo/helpers.h8
-rw-r--r--tools/minicargo/manifest.cpp60
-rw-r--r--tools/minicargo/manifest.h2
-rw-r--r--tools/minicargo/path.h7
-rw-r--r--tools/minicargo/repository.cpp6
-rw-r--r--tools/overrides/nightly-2017-07-08/build_libc.txt3
8 files changed, 141 insertions, 36 deletions
diff --git a/tools/minicargo/Makefile b/tools/minicargo/Makefile
index ab3f8531..b528bac6 100644
--- a/tools/minicargo/Makefile
+++ b/tools/minicargo/Makefile
@@ -10,7 +10,7 @@ OBJDIR := .obj/
BIN := ../bin/minicargo
OBJS := main.o build.o manifest.o repository.o
-OBJS += toml.o
+OBJS += toml.o path.o
LINKFLAGS :=
CXXFLAGS := -Wall -std=c++14
diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp
index 29b75328..b4e736d2 100644
--- a/tools/minicargo/build.cpp
+++ b/tools/minicargo/build.cpp
@@ -81,14 +81,22 @@ class Builder
}
};
- //::helpers::path m_build_script_overrides;
+ ::helpers::path m_build_script_overrides;
public:
+ Builder(::helpers::path override_dir):
+ m_build_script_overrides(override_dir)
+ {
+ }
+
bool build_target(const PackageManifest& manifest, const PackageTarget& target) const;
bool build_library(const PackageManifest& manifest) const;
private:
bool spawn_process(const StringList& args, const ::helpers::path& logfile) const;
+
+
+ time_t get_timestamp(const ::helpers::path& path) const;
};
void MiniCargo_Build(const PackageManifest& manifest)
@@ -105,7 +113,8 @@ void MiniCargo_Build(const PackageManifest& manifest)
}
// Build dependencies
- Builder builder;
+ // TODO: Take this path as input. (XXX HACK)
+ Builder builder { "overrides/nightly-2017-07-08" };
for(const auto& p : list.iter())
{
if( ! builder.build_library(p) )
@@ -179,20 +188,22 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget&
// > mrustc/minicargo is newer than `outfile`
// > build script has changed
// > any input file has changed (requires depfile from mrustc)
- //auto ts_result = this->get_timestamp(outfile);
- //if( force_rebuild ) {
- //}
- //else if( ts_result == Timestamp::infinite_past() ) {
- // // Rebuild (missing)
- //}
+ bool force_rebuild = false;
+ auto ts_result = this->get_timestamp(outfile);
+ if( force_rebuild ) {
+ }
+ else if( ts_result == 0/*Timestamp::infinite_past()*/ ) {
+ // Rebuild (missing)
+ }
//else if( ts_result < this->get_timestamp("../bin/mrustc") || ts_result < this->get_timestamp("bin/minicargo") ) {
// // Rebuild (older than mrustc/minicargo)
//}
- // TODO: Check dependencies.
- //else {
- // // Don't rebuild (no need to)
- // return true;
- //}
+ else {
+ // TODO: Check dependencies. (from depfile)
+ // Don't rebuild (no need to)
+ DEBUG("Not building " << outfile << " - not out of date");
+ return true;
+ }
for(const auto& cmd : manifest.build_script_output().pre_build_commands)
@@ -227,23 +238,24 @@ bool Builder::build_library(const PackageManifest& manifest) const
if( manifest.build_script() != "" )
{
// Locate a build script override file
- //if(this->m_build_script_overrides.is_valid())
- //{
- // auto override_file = this->m_build_script_overrides / "build_" + manifest.name + ".txt";
- //
- // // > Note, override file can specify a list of commands to run.
- // manifest.load_build_script( override_file );
- //}
- //else
- //{
- // // Otherwise, compile and run build script
- // // - Load dependencies for the build script
- // // - Build the script itself
- // this->build_build_script( manifest );
- // // - Run the script and put output in the right dir
- // manifest.load_build_script( ::helpers::path("output") / "build_" + manifest.name + ".txt" );
- //}
- throw ::std::runtime_error("TODO: Build script for " + manifest.name());
+ if(this->m_build_script_overrides.is_valid())
+ {
+ auto override_file = this->m_build_script_overrides / "build_" + manifest.name().c_str() + ".txt";
+ // TODO: Should this test if it exists? or just assume and let it error?
+
+ // > Note, override file can specify a list of commands to run.
+ const_cast<PackageManifest&>(manifest).load_build_script( override_file.str() );
+ }
+ else
+ {
+ // Otherwise, compile and run build script
+ // - Load dependencies for the build script
+ // - Build the script itself
+ //this->build_build_script( manifest );
+ // - Run the script and put output in the right dir
+ //manifest.load_build_script( ::helpers::path("output") / "build_" + manifest.name().c_str() + ".txt" );
+ throw ::std::runtime_error("TODO: Build script for " + manifest.name());
+ }
}
return this->build_target(manifest, manifest.get_library());
@@ -335,3 +347,20 @@ bool Builder::spawn_process(const StringList& args, const ::helpers::path& logfi
#endif
return true;
}
+
+time_t Builder::get_timestamp(const ::helpers::path& path) const
+{
+#if _WIN32
+#else
+ struct stat s;
+ if( stat(path.str().c_str(), &s) == 0 )
+ {
+ return s.st_mtime;
+ }
+ else
+ {
+ return 0;
+ }
+#endif
+}
+
diff --git a/tools/minicargo/helpers.h b/tools/minicargo/helpers.h
index 1099778b..d913e3c2 100644
--- a/tools/minicargo/helpers.h
+++ b/tools/minicargo/helpers.h
@@ -2,6 +2,7 @@
#include <string>
#include <cstring>
+#include <iostream>
namespace helpers {
@@ -23,10 +24,17 @@ public:
return false;
return s[m_len] == '\0';
}
+ operator ::std::string() const {
+ return ::std::string { m_start, m_start + m_len };
+ }
friend ::std::string& operator+=(::std::string& x, const string_view& sv) {
x.append(sv.m_start, sv.m_start+sv.m_len);
return x;
}
+ friend ::std::ostream& operator<<(::std::ostream& os, const string_view& sv) {
+ os.write(sv.m_start, sv.m_len);
+ return os;
+ }
};
diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp
index d0eefcc6..60594303 100644
--- a/tools/minicargo/manifest.cpp
+++ b/tools/minicargo/manifest.cpp
@@ -305,6 +305,66 @@ void PackageManifest::load_dependencies(Repository& repo)
}
}
+void PackageManifest::load_build_script(const ::std::string& path)
+{
+ ::std::ifstream is( path );
+ if( !is.good() )
+ throw ::std::runtime_error("Unable to open build script file '" + path + "'");
+
+ BuildScriptOutput rv;
+
+ while( !is.eof() )
+ {
+ ::std::string line;
+ is >> line;
+ if( line.compare(0, 5+1, "cargo:") == 0 )
+ {
+ size_t start = 5+1;
+ size_t eq_pos = line.find_first_of('=');
+ ::helpers::string_view key { line.c_str() + start, eq_pos - start };
+ ::helpers::string_view value { line.c_str() + eq_pos + 1, line.size() - eq_pos - 1 };
+
+ if( key == "minicargo-pre-build" ) {
+ rv.pre_build_commands.push_back(value);
+ }
+ // cargo:rustc-link-search=foo/bar/baz
+ else if( key == "rustc-link-search" ) {
+ // TODO: Check for an = (otherwise default to dynamic)
+ throw ::std::runtime_error("TODO: rustc-link-search");
+ }
+ // cargo:rustc-link-lib=mysql
+ else if( key == "rustc-link-lib" ) {
+ // TODO: Check for an = (otherwise default to dynamic)
+ throw ::std::runtime_error("TODO: rustc-link-lib");
+ }
+ // cargo:rustc-cfg=foo
+ else if( key == "rustc-cfg" ) {
+ // TODO: Validate
+ rv.rustc_cfg.push_back( value );
+ }
+ // cargo:rustc-flags=-l foo
+ else if( key == "rustc-flags" ) {
+ // Split on space, then push each.
+ throw ::std::runtime_error("TODO: rustc-flags");
+ }
+ // cargo:rustc-env=FOO=BAR
+ else if( key == "rustc-env" ) {
+ rv.rustc_env.push_back( value );
+ }
+ // cargo:rerun-if-changed=foo.rs
+ else if( key == "rerun-if-changed" ) {
+ DEBUG("TODO: '" << key << "' = '" << value << "'");
+ }
+ // - Ignore
+ else {
+ DEBUG("TODO: '" << key << "' = '" << value << "'");
+ }
+ }
+ }
+
+ m_build_script_output = rv;
+}
+
void PackageRef::load_manifest(Repository& repo, const ::helpers::path& base_path)
{
// If the path isn't set, check for:
diff --git a/tools/minicargo/manifest.h b/tools/minicargo/manifest.h
index bf010804..7f93e2c4 100644
--- a/tools/minicargo/manifest.h
+++ b/tools/minicargo/manifest.h
@@ -125,7 +125,7 @@ struct PackageTarget
class BuildScriptOutput
{
public:
- // `minicargo:pre-build=make -C bar/`
+ // `cargo:minicargo-pre-build=make -C bar/`
// MiniCargo hack
::std::vector<::std::string> pre_build_commands;
diff --git a/tools/minicargo/path.h b/tools/minicargo/path.h
index 73a520a9..54cb8f40 100644
--- a/tools/minicargo/path.h
+++ b/tools/minicargo/path.h
@@ -1,6 +1,7 @@
#pragma once
#include <string>
+#include <stdexcept>
#include "helpers.h"
namespace helpers {
@@ -81,6 +82,10 @@ public:
}
}
+ const ::std::string& str() const
+ {
+ return m_str;
+ }
operator ::std::string() const
{
return m_str;
@@ -123,4 +128,4 @@ public:
}
};
-} \ No newline at end of file
+}
diff --git a/tools/minicargo/repository.cpp b/tools/minicargo/repository.cpp
index 0a097f66..c6fe284f 100644
--- a/tools/minicargo/repository.cpp
+++ b/tools/minicargo/repository.cpp
@@ -13,11 +13,11 @@ void Repository::load_vendored(const ::helpers::path& path)
// Extract package name and version from each manifest
}
-::std::shared_ptr<PackageManifest> Repository::from_path(::helpers::path path)
+::std::shared_ptr<PackageManifest> Repository::from_path(::helpers::path in_path)
{
- DEBUG("Repository::from_path(" << path << ")");
+ DEBUG("Repository::from_path(" << in_path << ")");
// 1. Normalise path
- path = path.normalise();
+ auto path = in_path.normalise();
DEBUG("path = " << path);
auto it = m_path_cache.find(path);
diff --git a/tools/overrides/nightly-2017-07-08/build_libc.txt b/tools/overrides/nightly-2017-07-08/build_libc.txt
new file mode 100644
index 00000000..32bbd68e
--- /dev/null
+++ b/tools/overrides/nightly-2017-07-08/build_libc.txt
@@ -0,0 +1,3 @@
+cargo:rustc-cfg=stdbuild
+cargo:rerun-if-changed=build.rs
+