Skip to content

Commit e43969d

Browse files
committed
Initial features.
1 parent 7153617 commit e43969d

18 files changed

Lines changed: 204 additions & 66 deletions

File tree

src/sw/builder/command.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,9 @@ path Command::writeCommand(const path &p) const
752752
}
753753
else
754754
{
755-
static const String bat_next_line = "^\n ";
755+
static const String next_line_space = " ";
756+
static const String next_line = "\n" + next_line_space;
757+
static const String bat_next_line = "^" + next_line;
756758

757759
auto print_args = [&bat, &t](const auto &args)
758760
{
@@ -769,16 +771,14 @@ path Command::writeCommand(const path &p) const
769771
}
770772
t += "\"" + a2 + "\" ";
771773
if (bat)
772-
t += bat_next_line;
774+
t += "^";
773775
else
774-
t += "\\\n\t";
776+
t += "\\";
777+
t += next_line;
775778
}
776779
if (!args.empty())
777780
{
778-
if (bat)
779-
t.resize(t.size() - bat_next_line.size());
780-
else
781-
t.resize(t.size() - 3);
781+
t.resize(t.size() - 1 - next_line.size());
782782
}
783783
};
784784

src/sw/core/program/detect.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,9 @@ void detectNonWindowsCompilers(DETECT_ARGS)
10141014

10151015
resolve_and_add("ar", "org.gnu.binutils.ar");
10161016
resolve_and_add("as", "org.gnu.gcc.as");
1017-
resolve_and_add("ld", "org.gnu.gcc.ld");
1017+
//resolve_and_add("ld", "org.gnu.gcc.ld");
1018+
//resolve_and_add("gcc", "org.gnu.gcc.ld"); // link using gcc
1019+
resolve_and_add("g++", "org.gnu.gcc.ld"); // link using g++
10181020

10191021
resolve_and_add("gcc", "org.gnu.gcc");
10201022
resolve_and_add("g++", "org.gnu.gpp");

src/sw/core/settings.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,29 @@ void TargetSetting::reset()
257257
value.swap(v);
258258
}
259259

260+
void TargetSetting::use()
261+
{
262+
if (use_count > 0)
263+
use_count--;
264+
if (use_count == 0)
265+
reset();
266+
}
267+
268+
void TargetSetting::setUseCount(int c)
269+
{
270+
use_count = c;
271+
}
272+
273+
void TargetSetting::setRequired(bool b)
274+
{
275+
required = b;
276+
}
277+
278+
bool TargetSetting::isRequired() const
279+
{
280+
return required;
281+
}
282+
260283
TargetSetting::operator bool() const
261284
{
262285
return value.index() != 0;
@@ -362,8 +385,30 @@ int TargetSettings::compareEqualKeys(const TargetSettings &lhs, const TargetSett
362385
const auto &other = lhs.settings.size() >= rhs.settings.size() ? lhs : rhs;
363386
bool r = std::all_of(main.settings.begin(), main.settings.end(), [&other](const auto &p)
364387
{
365-
if (other[p.first] && p.second)
388+
if (
389+
// compare if both is present
390+
(other[p.first] && p.second)
391+
392+
// or one is present and required
393+
|| (other[p.first] && other[p.first].isRequired())
394+
|| (p.second && p.second.isRequired())
395+
)
396+
{
366397
return TargetSetting::compareEqualKeys(other[p.first], p.second) == 0;
398+
}
399+
return true;
400+
});
401+
// check required settings in other
402+
r &= std::all_of(other.settings.begin(), other.settings.end(), [&main](const auto &p)
403+
{
404+
if (
405+
// compare if any is required
406+
(p.second && p.second.isRequired()) ||
407+
(main[p.first] && main[p.first].isRequired())
408+
)
409+
{
410+
return TargetSetting::compareEqualKeys(main[p.first], p.second) == 0;
411+
}
367412
return true;
368413
});
369414
if (r)

src/sw/core/settings.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ struct SW_CORE_API TargetSetting
128128
void push_back(const TargetSettingValue &);
129129
void reset();
130130

131+
void use();
132+
void setUseCount(int);
133+
134+
void setRequired(bool = true);
135+
bool isRequired() const;
136+
131137
void merge(const TargetSetting &);
132138
void mergeFromJson(const nlohmann::json &);
133139

@@ -136,6 +142,8 @@ struct SW_CORE_API TargetSetting
136142
bool isObject() const;
137143

138144
private:
145+
int use_count = 1;
146+
bool required = false;
139147
TargetSettingKey key;
140148
std::variant<std::monostate, TargetSettingValue, std::vector<TargetSettingValue>, TargetSettings> value;
141149

src/sw/core/target.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,19 @@ struct SW_CORE_API ITarget : ICastable
5656
///
5757
virtual Commands getCommands() const = 0;
5858

59-
// get output config?
60-
// get input config?
59+
/// final (output) configuration
60+
/// available before prepare or after?
61+
/// round trips
62+
//virtual const TargetSettings &getConfiguration() const = 0;
6163

64+
/// input settings
65+
/// does not round trip
6266
virtual const TargetSettings &getSettings() const = 0;
67+
68+
/// settings for consumers (targets)
6369
virtual const TargetSettings &getInterfaceSettings() const = 0;
6470

71+
// get binary settings, get doc settings?
6572
// String get package settings(); // json coded or whatever via interface?
6673
// String getDescription()
6774
};

src/sw/driver/build_self.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
// License, v. 2.0. If a copy of the MPL was not distributed with this
55
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
66

7-
#define SW_PACKAGE_API
8-
#include "sw.h"
9-
107
#include "entry_point.h"
118

129
#include <sw/core/sw_context.h>
@@ -15,14 +12,16 @@
1512
#include <primitives/log.h>
1613
DECLARE_STATIC_LOGGER(logger, "build.self");
1714

15+
#define SW_PACKAGE_API
16+
#include "sw.h"
17+
1818
#ifdef _MSC_VER
1919
#pragma warning(push)
2020
#pragma warning(disable : 4005) // warning C4005: 'XXX': macro redefinition
2121
#endif
2222

2323
using TargetEntryPointMap = std::unordered_map<sw::PackageId, std::shared_ptr<sw::NativeBuiltinTargetEntryPoint>>;
2424

25-
#define getSettings getBuildSettings
2625
#define SW_CPP_DRIVER_API_VERSION 1
2726
#include <build_self.generated.h>
2827

src/sw/driver/checks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ Build Check::setupSolution(SwBuild &b, const path &f) const
704704

705705
TargetSettings Check::getSettings() const
706706
{
707-
auto ss = check_set->t->getTargetSettings();
707+
auto ss = check_set->t->getSettings();
708708

709709
// some checks may fail in msvc release (functions become intrinsics (mem*) etc.)
710710
if (check_set->t->getCompilerType() == CompilerType::MSVC ||

src/sw/driver/compiler/compiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,8 @@ void GNULinker::prepareCommand1(const Target &t)
763763
origin_dirs.push_back(d);
764764

765765
// remove later?
766-
cmd->arguments.push_back("-rpath");
767-
cmd->arguments.push_back("./");
766+
//cmd->arguments.push_back("-rpath");
767+
//cmd->arguments.push_back("./");
768768
}
769769

770770
//cmd->out.capture = true;

src/sw/driver/dependency.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct SW_DRIVER_CPP_API DependencyData : IDependency
3838
operator bool() const { return target; }
3939
bool isResolved() const override { return operator bool(); }
4040

41+
TargetSettings &getSettings() { return settings; }
4142
const TargetSettings &getSettings() const override { return settings; }
4243

4344
PackageId getResolvedPackage() const;

src/sw/driver/entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ decltype(auto) PrepareConfigEntryPoint::commonActions(Build &b, const Files &fil
358358
for (auto &fn : files)
359359
{
360360
lib += fn;
361-
lib[fn].args.push_back("-DgetSettings=getBuildSettings");
361+
//lib[fn].args.push_back("-DgetSettings=getBuildSettings");
362362
}
363363

364364
//

0 commit comments

Comments
 (0)