Remake
Loading...
Searching...
No Matches
Target status

Functions

static status_t const & get_status (std::string const &target)
static void update_status (std::string const &target)
static bool still_need_rebuild (std::string const &target)

Detailed Description

Function Documentation

◆ get_status()

status_t const & get_status ( std::string const & target)
static

Compute and memoize the status of target:

  • if the file does not exist, the target is obsolete,
  • if any dependency is obsolete or younger than the file, it is obsolete,
  • otherwise it is up-to-date.
Note
For rules with multiple targets, all the targets share the same status. (If one is obsolete, they all are.) The second rule above is modified in that case: the latest target is chosen, not the oldest!

Definition at line 1987 of file remake.cpp.

1988{
1989 std::pair<status_map::iterator,bool> i =
1990 status.insert(std::make_pair(target, status_t()));
1991 status_t &ts = i.first->second;
1992 if (!i.second) return ts;
1993 DEBUG_open << "Checking status of " << target << "... ";
1994 dependency_map::const_iterator j = dependencies.find(target);
1995 if (j == dependencies.end())
1996 {
1997 struct stat s;
1998 if (stat(target.c_str(), &s) != 0)
1999 {
2000 DEBUG_close << "missing\n";
2001 ts.status = Todo;
2002 ts.last = 0;
2003 return ts;
2004 }
2005 DEBUG_close << "up-to-date\n";
2006 ts.status = Uptodate;
2007 ts.last = s.st_mtime;
2008 return ts;
2009 }
2010 if (obsolete_targets)
2011 {
2012 DEBUG_close << "forcefully obsolete\n";
2013 ts.status = Todo;
2014 ts.last = 0;
2015 return ts;
2016 }
2017 dependency_t const &dep = *j->second;
2018 status_e st = Uptodate;
2019 time_t latest = 0;
2020 for (string_list::const_iterator k = dep.targets.begin(),
2021 k_end = dep.targets.end(); k != k_end; ++k)
2022 {
2023 struct stat s;
2024 if (stat(k->c_str(), &s) != 0)
2025 {
2026 if (st == Uptodate) DEBUG_close << *k << " missing\n";
2027 s.st_mtime = 0;
2028 st = Todo;
2029 }
2030 status[*k].last = s.st_mtime;
2031 if (s.st_mtime > latest) latest = s.st_mtime;
2032 }
2033 if (st != Uptodate) goto update;
2034 for (string_set::const_iterator k = dep.deps.begin(),
2035 k_end = dep.deps.end(); k != k_end; ++k)
2036 {
2037 status_t const &ts_ = get_status(*k);
2038 if (latest < ts_.last)
2039 {
2040 DEBUG_close << "older than " << *k << std::endl;
2041 st = Todo;
2042 goto update;
2043 }
2044 if (ts_.status != Uptodate && st != Recheck)
2045 {
2046 DEBUG << "obsolete dependency " << *k << std::endl;
2047 st = Recheck;
2048 }
2049 }
2050 if (st == Uptodate) DEBUG_close << "all siblings up-to-date\n";
2051 update:
2052 for (string_list::const_iterator k = dep.targets.begin(),
2053 k_end = dep.targets.end(); k != k_end; ++k)
2054 {
2055 status[*k].status = st;
2056 }
2057 return ts;
2058}
static status_t const & get_status(std::string const &target)
Definition remake.cpp:1987
static status_map status
Definition remake.cpp:627
#define DEBUG_close
Definition remake.cpp:817
status_e
Definition remake.cpp:523
@ Todo
Target is missing or obsolete.
Definition remake.cpp:525
@ Recheck
Target has an obsolete dependency.
Definition remake.cpp:526
@ Uptodate
Target is up-to-date.
Definition remake.cpp:524
static dependency_map dependencies
Definition remake.cpp:622
static bool obsolete_targets
Definition remake.cpp:754
#define DEBUG_open
Definition remake.cpp:816
#define DEBUG
Definition remake.cpp:815
string_list targets
Definition remake.cpp:511
string_set deps
Definition remake.cpp:512
status_e status
Actual status.
Definition remake.cpp:538
time_t last
Last-modified date.
Definition remake.cpp:539

Referenced by get_status(), handle_clients(), and server_mode().

◆ still_need_rebuild()

bool still_need_rebuild ( std::string const & target)
static

Check whether all the prerequisites of target ended being up-to-date.

Definition at line 2097 of file remake.cpp.

2098{
2099 status_map::const_iterator i = status.find(target);
2100 assert(i != status.end());
2101 if (i->second.status != RunningRecheck) return true;
2102 DEBUG_open << "Rechecking obsoleteness of " << target << "... ";
2103 dependency_map::const_iterator j = dependencies.find(target);
2104 assert(j != dependencies.end());
2105 dependency_t const &dep = *j->second;
2106 for (string_set::const_iterator k = dep.deps.begin(),
2107 k_end = dep.deps.end(); k != k_end; ++k)
2108 {
2109 if (status[*k].status != Uptodate) return true;
2110 }
2111 for (string_list::const_iterator k = dep.targets.begin(),
2112 k_end = dep.targets.end(); k != k_end; ++k)
2113 {
2114 status[*k].status = Uptodate;
2115 }
2116 DEBUG_close << "no longer obsolete\n";
2117 return false;
2118}
@ RunningRecheck
Static prerequisites are being rebuilt.
Definition remake.cpp:528

Referenced by complete_request().

◆ update_status()

void update_status ( std::string const & target)
static

Change the status of target to Remade or Uptodate depending on whether its modification time changed.

Definition at line 2064 of file remake.cpp.

2065{
2066 DEBUG_open << "Rechecking status of " << target << "... ";
2067 status_map::iterator i = status.find(target);
2068 assert(i != status.end());
2069 status_t &ts = i->second;
2070 ts.status = Remade;
2071 if (ts.last >= now)
2072 {
2073 DEBUG_close << "possibly remade\n";
2074 return;
2075 }
2076 struct stat s;
2077 if (stat(target.c_str(), &s) != 0)
2078 {
2079 DEBUG_close << "missing\n";
2080 ts.last = 0;
2081 }
2082 else if (s.st_mtime != ts.last)
2083 {
2084 DEBUG_close << "remade\n";
2085 ts.last = s.st_mtime;
2086 }
2087 else
2088 {
2089 DEBUG_close << "unchanged\n";
2090 ts.status = Uptodate;
2091 }
2092}
static time_t now
Definition remake.cpp:729
@ Remade
Target was successfully rebuilt.
Definition remake.cpp:529

Referenced by complete_job().