Remake
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Functions
Rule resolution

Functions

static void merge_rule (rule_t &dest, rule_t const &src)
 
static void substitute_pattern (std::string const &pat, string_list const &src, string_list &dst)
 
static void find_generic_rule (job_t &job, std::string const &target)
 
static void find_rule (job_t &job, std::string const &target)
 

Detailed Description

Function Documentation

static void find_generic_rule ( job_t job,
std::string const &  target 
)
static

Find a generic rule matching target:

  • the one leading to shorter matches has priority,
  • among equivalent rules, the earliest one has priority.

Definition at line 1830 of file remake.cpp.

Referenced by find_rule().

1831 {
1832  size_t tlen = target.length(), plen = tlen + 1;
1833  for (rule_list::const_iterator i = generic_rules.begin(),
1834  i_end = generic_rules.end(); i != i_end; ++i)
1835  {
1836  for (string_list::const_iterator j = i->targets.begin(),
1837  j_end = i->targets.end(); j != j_end; ++j)
1838  {
1839  size_t len = j->length();
1840  if (tlen < len) continue;
1841  if (plen <= tlen - (len - 1)) continue;
1842  size_t pos = j->find('%');
1843  if (pos == std::string::npos) continue;
1844  size_t len2 = len - (pos + 1);
1845  if (j->compare(0, pos, target, 0, pos) ||
1846  j->compare(pos + 1, len2, target, tlen - len2, len2))
1847  continue;
1848  plen = tlen - (len - 1);
1849  job.stem = target.substr(pos, plen);
1850  job.rule = rule_t();
1851  job.rule.script = i->script;
1852  substitute_pattern(job.stem, i->targets, job.rule.targets);
1853  substitute_pattern(job.stem, i->deps, job.rule.deps);
1854  substitute_pattern(job.stem, i->wdeps, job.rule.wdeps);
1855  break;
1856  }
1857  }
1858 }
string_list wdeps
Like deps, except that they are not registered as dependencies.
Definition: remake.cpp:549
string_list deps
Dependencies used for an implicit call to remake at the start of the script.
Definition: remake.cpp:548
std::string stem
Pattern used to instantiate the generic rule, if any.
Definition: remake.cpp:565
string_list targets
Files produced by this rule.
Definition: remake.cpp:547
std::string script
Shell script for building the targets.
Definition: remake.cpp:551
static void substitute_pattern(std::string const &pat, string_list const &src, string_list &dst)
Definition: remake.cpp:1814
rule_t rule
Original rule.
Definition: remake.cpp:564
static rule_list generic_rules
Definition: remake.cpp:619
static void find_rule ( job_t job,
std::string const &  target 
)
static

Find a specific rule matching target. Return a generic one otherwise. If there is both a specific rule with an empty script and a generic rule, the generic one is returned after adding the dependencies of the specific one.

Definition at line 1865 of file remake.cpp.

Referenced by start().

1866 {
1867  rule_map::const_iterator i = specific_rules.find(target),
1868  i_end = specific_rules.end();
1869  // If there is a specific rule with a script, return it.
1870  if (i != i_end && !i->second->script.empty())
1871  {
1872  job.rule = *i->second;
1873  return;
1874  }
1875  find_generic_rule(job, target);
1876  // If there is no generic rule, return the specific rule (no script), if any.
1877  if (job.rule.targets.empty())
1878  {
1879  if (i != i_end)
1880  {
1881  job.rule = *i->second;
1882  return;
1883  }
1884  }
1885  // Optimize the lookup when there is only one target (already looked up).
1886  if (job.rule.targets.size() == 1)
1887  {
1888  if (i == i_end) return;
1889  merge_rule(job.rule, *i->second);
1890  return;
1891  }
1892  // Add the dependencies of the specific rules of every target to the
1893  // generic rule. If any of those rules has a nonempty script, error out.
1894  for (string_list::const_iterator j = job.rule.targets.begin(),
1895  j_end = job.rule.targets.end(); j != j_end; ++j)
1896  {
1897  i = specific_rules.find(*j);
1898  if (i == i_end) continue;
1899  if (!i->second->script.empty()) return;
1900  merge_rule(job.rule, *i->second);
1901  }
1902 }
static rule_map specific_rules
Definition: remake.cpp:624
static void merge_rule(rule_t &dest, rule_t const &src)
Definition: remake.cpp:1791
string_list targets
Files produced by this rule.
Definition: remake.cpp:547
static void find_generic_rule(job_t &job, std::string const &target)
Definition: remake.cpp:1830
rule_t rule
Original rule.
Definition: remake.cpp:564
static void merge_rule ( rule_t dest,
rule_t const &  src 
)
static

Definition at line 1791 of file remake.cpp.

Referenced by find_rule(), and register_transparent_rule().

1792 {
1793  dest.deps.insert(dest.deps.end(), src.deps.begin(), src.deps.end());
1794  dest.wdeps.insert(dest.wdeps.end(), src.wdeps.begin(), src.wdeps.end());
1795  for (assign_map::const_iterator i = src.assigns.begin(),
1796  i_end = src.assigns.end(); i != i_end; ++i)
1797  {
1798  if (!i->second.append)
1799  {
1800  new_assign:
1801  dest.assigns[i->first] = i->second;
1802  continue;
1803  }
1804  assign_map::iterator j = dest.assigns.find(i->first);
1805  if (j == dest.assigns.end()) goto new_assign;
1806  j->second.value.insert(j->second.value.end(),
1807  i->second.value.begin(), i->second.value.end());
1808  }
1809 }
string_list wdeps
Like deps, except that they are not registered as dependencies.
Definition: remake.cpp:549
string_list deps
Dependencies used for an implicit call to remake at the start of the script.
Definition: remake.cpp:548
assign_map assigns
Assignment of variables.
Definition: remake.cpp:550
static void substitute_pattern ( std::string const &  pat,
string_list const &  src,
string_list dst 
)
static

Substitute a pattern into a list of strings.

Definition at line 1814 of file remake.cpp.

Referenced by find_generic_rule().

1815 {
1816  for (string_list::const_iterator i = src.begin(),
1817  i_end = src.end(); i != i_end; ++i)
1818  {
1819  size_t pos = i->find('%');
1820  if (pos == std::string::npos) dst.push_back(*i);
1821  else dst.push_back(i->substr(0, pos) + pat + i->substr(pos + 1));
1822  }
1823 }