#include <cmt_deps_builder.h>
Collaboration diagram for DepsBuilder:
Public Member Functions | |
void | clear () |
void | add (const cmt_string &path, const cmt_string &substitution) |
void | add_includes (const Use &use) |
CmtSystem::cmt_string_vector & | run (const cmt_string &file_name) |
Private Attributes | |
CmtSystem::cmt_string_vector | m_include_paths |
CmtSystem::cmt_string_vector | m_substitutions |
CmtSystem::cmt_string_vector | m_deps |
CmtSystem::cmt_string_vector | m_all_deps |
|
Definition at line 604 of file cmt_deps_builder.cxx. References cmt_string::erase(), CmtSystem::file_separator(), m_include_paths, m_substitutions, cmt_vector< T >::push_back(), and cmt_string::size(). Referenced by add_includes(), and CmtGenerator::prepare_use_context().
00605 { 00606 if (path[path.size () - 1] == CmtSystem::file_separator ()) 00607 { 00608 cmt_string p = path; 00609 p.erase (path.size () - 1); 00610 m_include_paths.push_back (p); 00611 } 00612 else 00613 { 00614 m_include_paths.push_back (path); 00615 } 00616 00617 m_substitutions.push_back (substitution); 00618 } |
|
Definition at line 621 of file cmt_deps_builder.cxx. References add(), CmtSystem::file_separator(), Symbol::find(), cmt_string::find(), CmtSystem::getenv(), Use::includes, Include::IncludeVector, log, Log, log_endl, Include::name, cmt_string::replace_all(), Symbol::resolve_macro_value(), cmt_vector< T >::size(), and cmt_string::substr(). Referenced by CmtGenerator::prepare_use_context().
00622 { 00623 Log; 00624 00625 const Include::IncludeVector& includes = use.includes; 00626 int include_number; 00627 00628 for (include_number = 0; 00629 include_number < includes.size (); 00630 include_number++) 00631 { 00632 const Include& include = includes[include_number]; 00633 00634 cmt_string temp = include.name; 00635 cmt_string pattern; 00636 cmt_string name; 00637 char end_pattern; 00638 00639 int start = 0; 00640 00641 for (;;) 00642 { 00643 int begin; 00644 00645 begin = temp.find (start, "${"); 00646 if (begin != cmt_string::npos) 00647 { 00648 end_pattern = '}'; 00649 } 00650 else 00651 { 00652 begin = temp.find (start, "$("); 00653 if (begin != cmt_string::npos) 00654 { 00655 end_pattern = ')'; 00656 } 00657 else 00658 { 00659 break; 00660 } 00661 } 00662 00663 start = begin + 2; 00664 00665 int end; 00666 end = temp.find (start, end_pattern); 00667 if (end == cmt_string::npos) break; 00668 if (end < begin) break; 00669 start = end + 1; 00670 00671 temp.substr (begin, end - begin + 1, pattern); 00672 temp.substr (begin + 2, end - begin - 2, name); 00673 00674 Symbol* macro = Symbol::find (name); 00675 if (macro != 0) 00676 { 00677 cmt_string value = macro->resolve_macro_value (); 00678 value += CmtSystem::file_separator (); 00679 temp.replace_all (pattern, value); 00680 } 00681 else 00682 { 00683 cmt_string value = CmtSystem::getenv (name); 00684 value += CmtSystem::file_separator (); 00685 temp.replace_all (pattern, value); 00686 } 00687 } 00688 00689 log << "include = " << temp << log_endl; 00690 00691 add (temp, include.name); 00692 } 00693 } |
|
Definition at line 597 of file cmt_deps_builder.cxx. References cmt_vector< T >::clear(), m_include_paths, and m_substitutions. Referenced by CmtGenerator::prepare_use_context().
00598 { 00599 m_include_paths.clear (); 00600 m_substitutions.clear (); 00601 } |
|
Definition at line 696 of file cmt_deps_builder.cxx. References CmtSystem::basename(), build_deps(), cmt_vector< T >::clear(), CmtSystem::cmt_string_vector, CmtSystem::dirname(), CmtSystem::execute(), Symbol::find(), m_all_deps, m_deps, m_include_paths, m_substitutions, cmt_vector< T >::push_back(), cmt_string::replace_all(), Symbol::resolve_macro_value(), cmt_vector< T >::size(), and CmtSystem::split(). Referenced by DependencyGenerator::build().
00697 { 00698 m_deps.clear (); 00699 m_all_deps.clear (); 00700 00701 cmt_string preprocessor; 00702 Symbol* macro = Symbol::find ("preprocessor_command"); 00703 if (macro != 0) 00704 { 00705 preprocessor = macro->resolve_macro_value (); 00706 } 00707 00708 if (preprocessor == "") 00709 { 00710 // 00711 // Since no preprocessor command is defined, 00712 // we use the internal mechanism provided here. 00713 // 00714 cmt_string new_dir; 00715 00716 CmtSystem::dirname (file_name, new_dir); 00717 00718 build_deps (file_name, 00719 new_dir, 00720 0, 00721 m_include_paths, 00722 m_substitutions, 00723 m_all_deps, 00724 m_deps); 00725 } 00726 else 00727 { 00728 // 00729 // An external preprocessor command is defined. We expect it 00730 // to follow a "standard" syntax for its output, ie: 00731 // o It starts with: 00732 // <module>.o: ... 00733 // o There may be many lines with trailing back-slashes 00734 // o All entries are space-separated 00735 // o One of the entries is the source file name itself 00736 // 00737 // The preprocessor command expects the list of -I options 00738 // (resolved from the "includes" macro) and the list of 00739 // -D/-U options (resolved from the "*_pp_*flags" macros) 00740 // 00741 00742 // 00743 // Building the complete command (still the pp_*flags are 00744 // missing) 00745 // 00746 preprocessor += " "; 00747 macro = Symbol::find ("includes"); 00748 preprocessor += macro->resolve_macro_value (); 00749 preprocessor += " "; 00750 preprocessor += file_name; 00751 00752 cmt_string output; 00753 00754 CmtSystem::execute (preprocessor, output); 00755 00756 // 00757 // Make the output as one single big line. 00758 // 00759 00760 output.replace_all ("\n", " "); 00761 output.replace_all ("\\ ", " "); 00762 00763 CmtSystem::cmt_string_vector files; 00764 00765 CmtSystem::split (output, " \t", files); 00766 00767 // 00768 // Analyze each entry 00769 // 00770 00771 for (int i = 1; i < files.size (); i++) 00772 { 00773 const cmt_string& file = files[i]; 00774 if (file == file_name) continue; 00775 00776 cmt_string dir; 00777 cmt_string name; 00778 cmt_string full_name; 00779 00780 CmtSystem::dirname (file, dir); 00781 00782 // 00783 // Only declared include_paths will be taken into account 00784 // Others are considered as system include paths. 00785 // 00786 00787 for (int j = 0; j < m_include_paths.size (); j++) 00788 { 00789 const cmt_string& p = m_include_paths[j]; 00790 if (dir == p) 00791 { 00792 CmtSystem::basename (file, name); 00793 full_name = m_substitutions[j]; 00794 full_name += name; 00795 00796 // 00797 // We add in the "m_deps" list the symbolic form 00798 // of the path rather that the expanded one. 00799 // 00800 00801 m_deps.push_back (full_name); 00802 00803 break; 00804 } 00805 } 00806 } 00807 } 00808 00809 return (m_deps); 00810 } |
|
Definition at line 28 of file cmt_deps_builder.h. Referenced by run(). |
|
Definition at line 27 of file cmt_deps_builder.h. Referenced by run(). |
|
Definition at line 24 of file cmt_deps_builder.h. |
|
Definition at line 25 of file cmt_deps_builder.h. |