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

Functions

static status_t constget_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()

static 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 1989 of file remake.cpp.

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

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

◆ still_need_rebuild()

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

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

Definition at line 2099 of file remake.cpp.

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

Referenced by complete_request().

◆ update_status()

static 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 2066 of file remake.cpp.

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

Referenced by complete_job().