fix build

master
Daniel Kolesa 2017-03-10 20:38:57 +01:00
parent fd5b4e6749
commit 3a40bad121
2 changed files with 29 additions and 20 deletions

View File

@ -10,8 +10,8 @@ OB_CXXFLAGS += -std=c++1z -I. -I$(CUBESCRIPT_PATH)/include -I$(OCTASTD_PATH) -pt
all: obuild all: obuild
obuild: $(FILES) obuild: $(FILES)
$(CXX) $(CXXFLAGS) $(OB_CXXFLAGS) $(LDFLAGS) -o obuild $(FILES) \ $(CXX) $(CXXFLAGS) $(OB_CXXFLAGS) -o obuild $(FILES) \
$(CUBESCRIPT_PATH)/libcubescript.a $(CUBESCRIPT_PATH)/libcubescript.a $(OCTASTD_PATH)/libostd.a $(LDFLAGS)
.cc.o: .cc.o:
$(CXX) $(CXXFLAGS) $(OB_CXXFLAGS) -c -o $@ $< $(CXX) $(CXXFLAGS) $(OB_CXXFLAGS) -c -o $@ $<

45
main.cc
View File

@ -28,6 +28,8 @@ using cscript::cs_stacked_value;
using cscript::cs_bcode_ref; using cscript::cs_bcode_ref;
using cscript::cs_bcode; using cscript::cs_bcode;
namespace fs = ostd::filesystem;
/* glob matching code */ /* glob matching code */
static void ob_get_path_parts( static void ob_get_path_parts(
@ -93,13 +95,15 @@ static bool ob_expand_dir(
std::string &ret, string_range dir, std::string &ret, string_range dir,
std::vector<string_range> const &parts, string_range slash std::vector<string_range> const &parts, string_range slash
) { ) {
ostd::directory_stream d{dir}; fs::directory_iterator d;
bool appended = false; try {
if (!d.is_open()) { d = fs::directory_iterator{std::string{dir}};
} catch (fs::filesystem_error const &) {
return false; return false;
} }
for (auto fi: d.iter()) { bool appended = false;
string_range fn = fi.filename(); for (auto &fi: d) {
std::string fn = fs::path{fi}.filename().string();
/* check if filename matches */ /* check if filename matches */
if (!ob_path_matches(fn, parts)) { if (!ob_path_matches(fn, parts)) {
continue; continue;
@ -190,19 +194,19 @@ static bool ob_check_ts(
string_range tname, std::vector<std::string> const &deps string_range tname, std::vector<std::string> const &deps
) { ) {
auto get_ts = [](string_range fname) { auto get_ts = [](string_range fname) {
ostd::file_info fi{fname}; fs::path p{std::string{fname}};
if (fi.type() != ostd::file_type::REGULAR) { if (!fs::is_regular_file(p)) {
return time_t(0); return fs::file_time_type{};
} }
return fi.mtime(); return fs::last_write_time(p);
}; };
time_t tts = get_ts(tname); auto tts = get_ts(tname);
if (!tts) { if (tts == fs::file_time_type{}) {
return true; return true;
} }
for (auto &dep: deps) { for (auto &dep: deps) {
time_t sts = get_ts(dep); auto sts = get_ts(dep);
if (sts && (tts < sts)) { if ((sts != fs::file_time_type{}) && (tts < sts)) {
return true; return true;
} }
} }
@ -341,8 +345,8 @@ struct ObState: cs_state {
template<typename ...A> template<typename ...A>
int error(int retcode, string_range fmt, A &&...args) { int error(int retcode, string_range fmt, A &&...args) {
ostd::err.write(progname, ": "); ostd::cerr.write(progname, ": ");
ostd::err.writefln(fmt, std::forward<A>(args)...); ostd::cerr.writefln(fmt, std::forward<A>(args)...);
return retcode; return retcode;
} }
@ -573,7 +577,7 @@ struct ObState: cs_state {
} }
int print_help(bool is_error, string_range deffile) { int print_help(bool is_error, string_range deffile) {
ostd::stream &os = is_error ? ostd::err : ostd::out; ostd::stream &os = is_error ? ostd::cerr : ostd::cout;
os.writeln( os.writeln(
"Usage: ", progname, " [options] [action]\n", "Usage: ", progname, " [options] [action]\n",
"Options:\n" "Options:\n"
@ -615,8 +619,13 @@ int main(int argc, char **argv) {
string_range val = (argv[i][2] == '\0') ? argv[++i] : &argv[i][2]; string_range val = (argv[i][2] == '\0') ? argv[++i] : &argv[i][2];
switch (argn) { switch (argn) {
case 'C': case 'C':
if (!ostd::directory_change(val)) { try {
return os.error(1, "failed changing directory: %s", val); fs::current_path(std::string{val});
} catch (fs::filesystem_error const &e) {
return os.error(
1, "failed changing directory: %s (%s)",
val, e.what()
);
} }
break; break;
case 'f': case 'f':