Skip to content
Permalink
Browse files

Add getOptions() method. Improve current project detection. Add SwBui…

…ldDescription generator.
  • Loading branch information...
egorpugin committed Oct 30, 2019
1 parent e158f2f commit a4e7dac8585a3791539e64f015f972ef4e93c7d4
@@ -57,6 +57,8 @@ String toPathString(GeneratorType t)
return "compdb";
case GeneratorType::SwExecutionPlan:
return "swexplan";
case GeneratorType::SwBuildDescription:
return "swbdesc";
default:
throw SW_LOGIC_ERROR("not implemented");
}
@@ -101,6 +103,8 @@ static String toString(GeneratorType t)
return "CompDB";
case GeneratorType::SwExecutionPlan:
return "Sw Execution Plan";
case GeneratorType::SwBuildDescription:
return "Sw Build Description";
default:
throw SW_LOGIC_ERROR("not implemented");
}
@@ -146,6 +150,8 @@ static GeneratorType fromString(const String &s)
return GeneratorType::CompilationDatabase;
else if (boost::iequals(s, "SwExPlan"))
return GeneratorType::SwExecutionPlan;
else if (boost::iequals(s, "SwBDesc"))
return GeneratorType::SwBuildDescription;
//else if (boost::iequals(s, "qtc"))
//return GeneratorType::qtc;
throw SW_RUNTIME_ERROR("Unknown generator: " + s);
@@ -207,6 +213,9 @@ std::unique_ptr<Generator> Generator::create(const String &s)
case GeneratorType::SwExecutionPlan:
g = std::make_unique<SwExecutionPlanGenerator>();
break;
case GeneratorType::SwBuildDescription:
g = std::make_unique<SwBuildDescriptionGenerator>();
break;
default:
SW_UNIMPLEMENTED;
}
@@ -896,3 +905,33 @@ void SwExecutionPlanGenerator::generate(const sw::SwBuild &b)
auto ep = b.getExecutionPlan();
ep.save(fn);
}

void SwBuildDescriptionGenerator::generate(const sw::SwBuild &b)
{
const auto d = getRootDirectory(b);
auto fn = path(d) += ".json";
fs::create_directories(d.parent_path());

nlohmann::json j;
for (auto &[pkg, tgts] : b.getTargets())
{
if (tgts.empty())
{
continue;
//throw SW_RUNTIME_ERROR("No targets in " + pkg.toString());
}
// filter out predefined targets
if (b.getContext().getPredefinedTargets().find(pkg) != b.getContext().getPredefinedTargets().end())
continue;

for (auto &t : tgts)
{
nlohmann::json j1;
// rename to settings?
j1["key"] = nlohmann::json::parse(t->getSettings().toString());
j1["value"] = nlohmann::json::parse(t->getInterfaceSettings().toString());
j[pkg.toString()].push_back(j1);
}
}
write_file(fn, j.dump(4));
}
@@ -44,6 +44,7 @@ enum class GeneratorType
VisualStudio,

SwExecutionPlan,
SwBuildDescription, // simply BDesc?
};

enum class VsGeneratorType
@@ -109,4 +110,9 @@ struct SwExecutionPlanGenerator : Generator
void generate(const sw::SwBuild &b) override;
};

struct SwBuildDescriptionGenerator : Generator
{
void generate(const sw::SwBuild &b) override;
};

String toPathString(GeneratorType Type);
@@ -38,6 +38,9 @@ struct SW_DRIVER_CPP_API DependencyData : IDependency
operator bool() const { return target; }
bool isResolved() const override { return operator bool(); }

TargetSettings &getOptions() { return getSettings()["options"].getSettings(); }
const TargetSettings &getOptions() const { return getSettings()["options"].getSettings(); }

TargetSettings &getSettings() { return settings; }
const TargetSettings &getSettings() const override { return settings; }

@@ -119,7 +119,7 @@ bool Target::hasSameProject(const ITarget &t) const
return false;
return
current_project && t2->current_project &&
current_project->getPackage() == t2->current_project->getPackage();
current_project == t2->current_project;
}

PackagePath TargetBase::constructTargetName(const PackagePath &Name) const
@@ -228,7 +228,7 @@ void TargetBase::setupTarget(TargetBaseType *t) const

t->current_project = current_project; // ok, take from here (this, parent)
if (!t->current_project)
t->current_project = t;
t->current_project = t->getPackage();
}

Build &TargetBase::getSolution()
@@ -786,7 +786,7 @@ path Target::getFile(const DependencyPtr &dep, const path &fn)

bool ProjectTarget::init()
{
current_project = this;
current_project = getPackage();
return Target::init();
}

@@ -82,7 +82,7 @@ struct SW_DRIVER_CPP_API TargetBaseData : ProjectDirectories, TargetEvents

// projects and dirs go here
std::vector<TargetBaseTypePtr> dummy_children;
const Target *current_project = nullptr;
std::optional<PackageId> current_project;
};

struct SW_DRIVER_CPP_API TargetBase : TargetBaseData
@@ -309,6 +309,8 @@ struct SW_DRIVER_CPP_API Target : ITarget, TargetBase, ProgramStorage,
const TargetSettings &getTargetSettings() const { return getSettings(); }
const BuildSettings &getBuildSettings() const;

const TargetSettings &getOptions() const { return getSettings()["options"].getSettings(); }

//
Commands getCommands() const;
UnresolvedDependenciesType gatherUnresolvedDependencies() const;

0 comments on commit a4e7dac

Please sign in to comment.
You can’t perform that action at this time.