Remake
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups 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 1823 of file remake.cpp.

Referenced by find_rule().

1824 {
1825  size_t tlen = target.length(), plen = tlen + 1;
1826  for (rule_list::const_iterator i = generic_rules.begin(),
1827  i_end = generic_rules.end(); i != i_end; ++i)
1828  {
1829  for (string_list::const_iterator j = i->targets.begin(),
1830  j_end = i->targets.end(); j != j_end; ++j)
1831  {
1832  size_t len = j->length();
1833  if (tlen < len) continue;
1834  if (plen <= tlen - (len - 1)) continue;
1835  size_t pos = j->find('%');
1836  if (pos == std::string::npos) continue;
1837  size_t len2 = len - (pos + 1);
1838  if (j->compare(0, pos, target, 0, pos) ||
1839  j->compare(pos + 1, len2, target, tlen - len2, len2))
1840  continue;
1841  plen = tlen - (len - 1);
1842  job.stem = target.substr(pos, plen);
1843  job.rule = rule_t();
1844  job.rule.script = i->script;
1845  substitute_pattern(job.stem, i->targets, job.rule.targets);
1846  substitute_pattern(job.stem, i->deps, job.rule.deps);
1847  substitute_pattern(job.stem, i->wdeps, job.rule.wdeps);
1848  break;
1849  }
1850  }
1851 }
string_list wdeps
Like deps, except that they are not registered as dependencies.
Definition: remake.cpp:547
string_list deps
Dependencies used for an implicit call to remake at the start of the script.
Definition: remake.cpp:546
std::string stem
Pattern used to instantiate the generic rule, if any.
Definition: remake.cpp:563
string_list targets
Files produced by this rule.
Definition: remake.cpp:545
std::string script
Shell script for building the targets.
Definition: remake.cpp:549
static void substitute_pattern(std::string const &pat, string_list const &src, string_list &dst)
Definition: remake.cpp:1807
rule_t rule
Original rule.
Definition: remake.cpp:562
static rule_list generic_rules
Definition: remake.cpp:617
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 1858 of file remake.cpp.

Referenced by start().

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

Definition at line 1784 of file remake.cpp.

Referenced by find_rule(), and register_transparent_rule().

1785 {
1786  dest.deps.insert(dest.deps.end(), src.deps.begin(), src.deps.end());
1787  dest.wdeps.insert(dest.wdeps.end(), src.wdeps.begin(), src.wdeps.end());
1788  for (assign_map::const_iterator i = src.assigns.begin(),
1789  i_end = src.assigns.end(); i != i_end; ++i)
1790  {
1791  if (!i->second.append)
1792  {
1793  new_assign:
1794  dest.assigns[i->first] = i->second;
1795  continue;
1796  }
1797  assign_map::iterator j = dest.assigns.find(i->first);
1798  if (j == dest.assigns.end()) goto new_assign;
1799  j->second.value.insert(j->second.value.end(),
1800  i->second.value.begin(), i->second.value.end());
1801  }
1802 }
string_list wdeps
Like deps, except that they are not registered as dependencies.
Definition: remake.cpp:547
string_list deps
Dependencies used for an implicit call to remake at the start of the script.
Definition: remake.cpp:546
assign_map assigns
Assignment of variables.
Definition: remake.cpp:548
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 1807 of file remake.cpp.

Referenced by find_generic_rule().

1808 {
1809  for (string_list::const_iterator i = src.begin(),
1810  i_end = src.end(); i != i_end; ++i)
1811  {
1812  size_t pos = i->find('%');
1813  if (pos == std::string::npos) dst.push_back(*i);
1814  else dst.push_back(i->substr(0, pos) + pat + i->substr(pos + 1));
1815  }
1816 }