aboutsummaryrefslogtreecommitdiffstats
path: root/common/project.cc
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2018-08-08 20:14:18 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2018-08-08 20:14:18 +0200
commit61bce47f3cb7b4adf1d5292b3c431ca4048ad038 (patch)
tree18ff4129f05a457f0afaf8edcef90fe73252ad24 /common/project.cc
parentb326b03a5261a824f428fe0811a5376c8758b929 (diff)
downloadnextpnr-61bce47f3cb7b4adf1d5292b3c431ca4048ad038.tar.gz
nextpnr-61bce47f3cb7b4adf1d5292b3c431ca4048ad038.tar.bz2
nextpnr-61bce47f3cb7b4adf1d5292b3c431ca4048ad038.zip
Use settings for json and pcf
Diffstat (limited to 'common/project.cc')
-rw-r--r--common/project.cc62
1 files changed, 48 insertions, 14 deletions
diff --git a/common/project.cc b/common/project.cc
index 244ca761..949f6878 100644
--- a/common/project.cc
+++ b/common/project.cc
@@ -26,19 +26,53 @@
NEXTPNR_NAMESPACE_BEGIN
+boost::filesystem::path make_relative(boost::filesystem::path child, boost::filesystem::path parent)
+{
+ boost::filesystem::path::const_iterator parentIter = parent.begin();
+ boost::filesystem::path::const_iterator childIter = child.begin();
+
+ while (parentIter != parent.end() && childIter != child.end() && (*childIter) == (*parentIter)) {
+ ++childIter;
+ ++parentIter;
+ }
+
+ boost::filesystem::path finalPath;
+ while (parentIter != parent.end()) {
+ finalPath /= "..";
+ ++parentIter;
+ }
+
+ while (childIter != child.end()) {
+ finalPath /= *childIter;
+ ++childIter;
+ }
+
+ return finalPath;
+}
+
void ProjectHandler::save(Context *ctx, std::string filename)
{
- std::ofstream f(filename);
- pt::ptree root;
- root.put("project.version", 1);
- root.put("project.name", boost::filesystem::basename(filename));
- root.put("project.arch.name", ctx->archId().c_str(ctx));
- root.put("project.arch.type", ctx->archArgsToId(ctx->archArgs()).c_str(ctx));
- /* root.put("project.input.json", );*/
- root.put("project.params.freq", int(ctx->target_freq / 1e6));
- root.put("project.params.seed", ctx->rngstate);
- saveArch(ctx, root);
- pt::write_json(f, root);
+ try {
+ boost::filesystem::path proj(filename);
+ std::ofstream f(filename);
+ pt::ptree root;
+
+ log_info("Saving project %s...\n", filename.c_str());
+ log_break();
+
+ root.put("project.version", 1);
+ root.put("project.name", boost::filesystem::basename(filename));
+ root.put("project.arch.name", ctx->archId().c_str(ctx));
+ root.put("project.arch.type", ctx->archArgsToId(ctx->archArgs()).c_str(ctx));
+ std::string fn = ctx->settings[ctx->id("project/input/json")];
+ root.put("project.input.json", make_relative(fn, proj.parent_path()).string());
+ root.put("project.params.freq", int(ctx->target_freq / 1e6));
+ root.put("project.params.seed", ctx->rngstate);
+ saveArch(ctx, root, proj.parent_path().string());
+ pt::write_json(f, root);
+ } catch (...) {
+ log_error("Error saving project file.\n");
+ }
}
std::unique_ptr<Context> ProjectHandler::load(std::string filename)
@@ -63,10 +97,10 @@ std::unique_ptr<Context> ProjectHandler::load(std::string filename)
auto project = root.get_child("project");
auto input = project.get_child("input");
- std::string filename = input.get<std::string>("json");
- boost::filesystem::path json = proj.parent_path() / filename;
+ std::string fn = input.get<std::string>("json");
+ boost::filesystem::path json = proj.parent_path() / fn;
std::ifstream f(json.string());
- if (!parse_json_file(f, filename, ctx.get()))
+ if (!parse_json_file(f, fn, ctx.get()))
log_error("Loading design failed.\n");
if (project.count("params")) {