Skip to content

Commit ab2f708

Browse files
committed
Improve command mtime work on other platforms. Add ability to save command output. Add -static-deps option. Improve macos builds.
1 parent d5fa931 commit ab2f708

22 files changed

Lines changed: 745 additions & 51 deletions

src/sw/builder/command.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bool Command::isOutdated() const
137137
}
138138
else
139139
{
140-
*((size_t*)&mtime) = r.first->mtime;
140+
((Command*)(this))->mtime = r.first->mtime;
141141
((Command*)(this))->implicit_inputs = r.first->implicit_inputs;
142142
return isTimeChanged();
143143
}
@@ -459,7 +459,7 @@ void Command::afterCommand()
459459
auto &cs = getContext().getCommandStorage();
460460
auto &r = *cs.getStorage(command_storage == CS_LOCAL).insert(k).first;
461461
r.hash = k;
462-
r.mtime = *(size_t*)&mtime;
462+
r.mtime = mtime;
463463
r.implicit_inputs = implicit_inputs;
464464
cs.async_command_log(r, command_storage == CS_LOCAL);
465465
}
@@ -595,12 +595,14 @@ void Command::printOutputs()
595595
s += out.text + "\n";
596596
if (!err.text.empty())
597597
s += err.text + "\n";
598-
if (!s.empty())
599-
{
600-
s = log_string + "\n" + s;
601-
boost::trim(s);
598+
if (s.empty())
599+
return;
600+
s = log_string + "\n" + s;
601+
boost::trim(s);
602+
if (write_output_to_file)
603+
write_file(fs::current_path() / SW_BINARY_DIR / "rsp" / std::to_string(getHash()) += ".txt", s);
604+
else
602605
LOG_INFO(logger, s);
603-
}
604606
}
605607

606608
String Command::makeErrorString(const String &e)

src/sw/builder/command.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct SW_BUILDER_API Command : ICastable, CommandNode, detail::ResolvableComman
166166
bool do_not_save_command = false;
167167
bool silent = false; // no log record
168168
bool show_output = false; // no command output
169+
bool write_output_to_file = false;
169170
int strict_order = 0; // used to execute this before other commands
170171
ResourcePool *pool = nullptr;
171172

src/sw/builder/command_storage.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ void FileDb::write(std::vector<uint8_t> &v, const CommandRecord &f)
8484
return;
8585

8686
write_int(v, f.hash);
87+
#ifndef __APPLE__
8788
write_int(v, f.mtime);
89+
#else
90+
write_int(v, decltype(f.mtime)::clock::to_time_t(f.mtime));
91+
#endif
8892

8993
auto n = f.implicit_inputs.size();
9094
write_int(v, n);
@@ -151,9 +155,13 @@ static void load(const path &fn, Files &files, ConcurrentCommandStorage &command
151155
auto r = commands.insert(h);
152156
r.first->hash = h;
153157

154-
size_t m;
158+
time_t m;
155159
b.read(m);
156-
r.first->mtime = m;
160+
#ifndef __APPLE__
161+
*(time_t*)&r.first->mtime = m;
162+
#else
163+
r.first->mtime = decltype(r.first->mtime)::clock::from_time_t(m);
164+
#endif
157165

158166
size_t n;
159167
b.read(n);

src/sw/builder/command_storage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace sw
1818
struct CommandRecord
1919
{
2020
size_t hash = 0;
21-
size_t mtime = 0;
21+
fs::file_time_type mtime = fs::file_time_type::min();
2222
Files implicit_inputs;
2323
};
2424

src/sw/builder/execution_plan.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void ExecutionPlan::execute(Executor &e) const
5757
{
5858
static_cast<builder::Command*>(c)->silent = silent;
5959
static_cast<builder::Command*>(c)->show_output = show_output;
60+
static_cast<builder::Command*>(c)->write_output_to_file = write_output_to_file;
6061
static_cast<builder::Command*>(c)->always |= build_always;
6162
}
6263
}

src/sw/builder/execution_plan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct SW_BUILDER_API ExecutionPlan
4444
bool build_always = false;
4545
bool silent = false;
4646
bool show_output = false;
47+
bool write_output_to_file = false;
4748

4849
ExecutionPlan() = default;
4950
ExecutionPlan(const ExecutionPlan &rhs) = delete;

src/sw/builder/program_version_storage.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ ProgramVersionStorage::ProgramVersionStorage(const path &fn)
2727
break;
2828
ifile >> v;
2929
ifile >> t;
30-
auto lwt = fs::last_write_time(p).time_since_epoch().count();
31-
if (t && lwt <= t)
30+
auto lwt = fs::last_write_time(p);
31+
#ifndef __APPLE__
32+
if (t && *(time_t*)&lwt <= t)
33+
#else
34+
if (t && lwt <= decltype(lwt)::clock::from_time_t(t))
35+
#endif
3236
versions[p] = {v,lwt};
3337
}
3438
}
@@ -37,7 +41,11 @@ ProgramVersionStorage::~ProgramVersionStorage()
3741
{
3842
std::ofstream ofile(fn);
3943
for (auto &[p, v] : std::map{ versions.begin(), versions.end() })
40-
ofile << p << " " << v.v.toString() << " " << v.t << "\n";
44+
#ifndef __APPLE__
45+
ofile << p << " " << v.v.toString() << " " << *(time_t*)&v.t << "\n";
46+
#else
47+
ofile << p << " " << v.v.toString() << " " << decltype(v.t)::clock::to_time_t(v.t) << "\n";
48+
#endif
4149
}
4250

4351
}

src/sw/builder/program_version_storage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct ProgramVersionStorage
1818
struct ProgramInfo
1919
{
2020
Version v;
21-
time_t t;
21+
fs::file_time_type t;
2222

2323
operator Version&() { return v; }
2424
};
@@ -31,7 +31,7 @@ struct ProgramVersionStorage
3131

3232
void addVersion(const path &p, const Version &v)
3333
{
34-
versions[p] = {v,fs::last_write_time(p).time_since_epoch().count()};
34+
versions[p] = {v,fs::last_write_time(p)};
3535
}
3636
};
3737

src/sw/client/command/build.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ static cl::list<String> os("os", cl::desc("Set build target os"), cl::CommaSepar
5555
static cl::list<String> libc("libc", cl::desc("Set build libc"), cl::CommaSeparated);
5656
static cl::list<String> libcpp("libcpp", cl::desc("Set build libcpp"), cl::CommaSeparated);
5757

58+
static ::cl::opt<bool> static_deps("static-dependencies", ::cl::desc("Build static dependencies of inputs"));
59+
static cl::alias static_deps2("static-deps", cl::aliasopt(static_deps));
60+
5861
// -setting k1=v1,k2=v2,k3="v3,v3" -setting k4=v4,k5,k6 etc.
5962
// settings in one setting applied simultaneosly
6063
// settings in different settings are multiplied
@@ -257,6 +260,9 @@ std::vector<sw::TargetSettings> createSettings(const sw::SwBuild &b)
257260
applySettingsFromFile(initial_settings["host"].getSettings(), host_settings_file);
258261
}
259262

263+
if (static_deps)
264+
initial_settings["static-deps"] = "true";
265+
260266
std::vector<sw::TargetSettings> settings;
261267
settings.push_back(initial_settings);
262268

src/sw/core/build.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ DECLARE_STATIC_LOGGER(logger, "build");
2222

2323
//cl::opt<bool> dry_run("n", cl::desc("Dry run"));
2424

25-
cl::opt<bool> build_always("B", cl::desc("Build always"));
26-
cl::opt<int> skip_errors("k", cl::desc("Skip errors"));
25+
static cl::opt<bool> build_always("B", cl::desc("Build always"));
26+
static cl::opt<int> skip_errors("k", cl::desc("Skip errors"));
2727
static cl::opt<bool> time_trace("time-trace", cl::desc("Record chrome time trace events"));
2828

2929
//static cl::opt<bool> hide_output("hide-output");
3030
static cl::opt<bool> cl_show_output("show-output");
31+
static cl::opt<bool> cl_write_output_to_file("write-output-to-file");
3132
static cl::opt<bool> print_graph("print-graph", cl::desc("Print file with build graph"));
3233

3334
#define CHECK_STATE(from) \
@@ -339,6 +340,8 @@ void SwBuild::execute(ExecutionPlan &p) const
339340
CHECK_STATE_AND_CHANGE(BuildState::Prepared, BuildState::Executed);
340341

341342
p.build_always = build_always;
343+
p.show_output = cl_show_output | cl_write_output_to_file;
344+
p.write_output_to_file = cl_write_output_to_file;
342345
p.skip_errors = skip_errors.getValue();
343346

344347
//ScopedTime t;

0 commit comments

Comments
 (0)