Changeset 588 for CMT/HEAD/source/cmt_generators.cxx
- Timestamp:
- Nov 27, 2011, 4:36:15 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
CMT/HEAD/source/cmt_generators.cxx
r561 r588 12 12 #include "cmt_error.h" 13 13 #include <assert.h> 14 #include "cmt_project.h" 14 15 15 16 //-------------------------------------------------- … … 200 201 if (Cmt::get_debug ()) 201 202 { 202 cout << " CmtGenerator::analyze_file> constituent=" <<203 cout << "LibraryGenerator::analyze_file> constituent=" << 203 204 constituent.name << 204 205 " obj=" << obj << endl; … … 408 409 409 410 //-------------------------------------------------- 411 void LibraryGenerator::fill_names_outputs () 412 { 413 bool l_first = true; 414 bool o_first = true; 415 416 m_LINE = ""; 417 m_OBJS = ""; 418 419 for (int i = 0; i < m_source_files.size (); i++) 420 { 421 const SourceFile& file = m_source_files[i]; 422 const cmt_string name = file.name (); 423 const cmt_string output = file.output (); 424 Language& language = file.language (); 425 426 if (output != "") 427 { 428 if (o_first) 429 { 430 o_first = false; 431 } 432 else 433 { 434 m_OBJS += " "; 435 } 436 m_OBJS += output; 437 438 if (language == Language::null () || !language.native_dependencies ()) 439 { 440 if (l_first) 441 { 442 l_first = false; 443 } 444 else 445 { 446 m_LINE += " "; 447 } 448 m_LINE += name; 449 } 450 } 451 452 if (Cmt::get_debug ()) 453 { 454 cout << "LibraryGenerator::fill_names_outputs>" << endl; 455 cout << "name=" << name << " LINE=" << m_LINE << endl; 456 cout << "output=" << output << " OBJS=" << m_OBJS << endl; 457 } 458 } 459 460 filter_path (m_LINE.value); 461 } 462 463 //-------------------------------------------------- 410 464 void LibraryGenerator::build (const cmt_string& package, 411 465 const Constituent& constituent, 466 bool& dependencies, 412 467 const cmt_string& file_name) 413 468 { … … 735 790 } 736 791 } 792 dependencies = need_dependencies; 737 793 738 794 if (constituent.build_triggers) … … 893 949 DocumentGenerator::DocumentGenerator () 894 950 { 951 m_FILEEXTENSION.set ("FILEEXTENSION"); 952 895 953 document_header_fragment.set ("document_header"); 954 dependency_fragment.set ("dependency"); 896 955 } 897 956 … … 900 959 { 901 960 AnyDocumentGenerator::reset (); 961 m_FILEEXTENSION = ""; 962 902 963 document_header_fragment.reset (); 964 dependency_fragment.reset (); 903 965 } 904 966 … … 906 968 void DocumentGenerator::build (const cmt_string& package, 907 969 const Constituent& constituent, 970 bool& dependencies, 908 971 const cmt_string& file_name) 909 972 { … … 1062 1125 } 1063 1126 1127 dependencies = fragment.need_dependencies (); 1064 1128 if (fragment.need_dependencies ()) 1065 1129 { … … 1123 1187 if (m_FILEPATH.value != "") m_FILEPATH.value += CmtSystem::file_separator (); 1124 1188 filter_path (m_FILEPATH.value); 1125 CmtSystem::basename (file_name, m_FILENAME.value); 1126 CmtSystem::get_dot_suffix (m_FILENAME.value, m_FILESUFFIX.value); 1189 m_FILENAME.value = m_NAME.value + suffix; 1190 //CmtSystem::basename (file_name, m_FILENAME.value); 1191 m_FILESUFFIX.value = suffix; 1192 //CmtSystem::get_dot_suffix (m_FILENAME.value, m_FILESUFFIX.value); 1193 CmtSystem::get_suffix (m_FILENAME.value, m_FILEEXTENSION .value); 1127 1194 /* 1128 1195 if (!CmtSystem::test_file (file_name) && !CmtSystem::test_directory (file_name)) … … 1133 1200 filter_path (m_FULLNAME.value); 1134 1201 1135 fragment.copy (m_output_file, constituent.variables, 8, 1202 if (fragment.need_dependencies ()) 1203 { 1204 // ensure that ${CONSTITUENT}_dependencies.make gets rebuilt 1205 // whenever source file OR its dependencies change 1206 dependency_fragment.copy (m_output_file, constituent.variables, 9, 1207 &m_FILEPATH, 1208 &m_SUFFIX, 1209 &m_CONSTITUENT, 1210 &m_CONSTITUENTSUFFIX, 1211 &m_FILENAME, 1212 &m_NAME, 1213 &m_FULLNAME, 1214 &m_FILESUFFIX, 1215 &m_FILEEXTENSION); 1216 } 1217 1218 fragment.copy (m_output_file, constituent.variables, 9, 1136 1219 &m_FILEPATH, 1137 1220 &m_SUFFIX, … … 1141 1224 &m_NAME, 1142 1225 &m_FULLNAME, 1143 &m_FILESUFFIX); 1226 &m_FILESUFFIX, 1227 &m_FILEEXTENSION); 1144 1228 } 1145 1229 … … 1201 1285 } 1202 1286 1287 //-------------------------------------------------- 1203 1288 ReadmeGenerator::ReadmeGenerator () 1204 1289 { … … 2702 2787 } 2703 2788 2704 2705 2789 //-------------------------------------------------- 2790 2791 PackagesMakefileGenerator::PackagesMakefileGenerator () 2792 { 2793 m_DEPENDENCIES.set ("DEPENDENCIES"); 2794 m_PACKAGEMGRPATH.set ("PACKAGEMGRPATH"); 2795 m_PACKAGEFULLNAME.set ("PACKAGEFULLNAME"); 2796 m_ISLOCAL.set ("ISLOCAL"); 2797 2798 packages_header_fragment.set ("packages_header"); 2799 packages_trailer_fragment.set ("packages_trailer"); 2800 package_fragment.set ("package"); 2801 } 2802 2803 void PackagesMakefileGenerator::reset () 2804 { 2805 CmtGenerator::reset (); 2806 m_DEPENDENCIES = ""; 2807 m_PACKAGEMGRPATH = ""; 2808 m_PACKAGEFULLNAME = ""; 2809 m_ISLOCAL = ""; 2810 2811 packages_header_fragment.reset (); 2812 packages_trailer_fragment.reset (); 2813 package_fragment.reset (); 2814 } 2815 2816 //-------------------------------------------------- 2817 void PackagesMakefileGenerator::build (const cmt_string& package, 2818 const cmt_string& file) 2819 { 2820 reset (); 2821 2822 cmt_string file_name (file); 2823 if (file_name == "") 2824 { 2825 file_name = "packages."; 2826 2827 if (Cmt::build_nmake ()) 2828 { 2829 file_name += "nmake"; 2830 } 2831 else 2832 { 2833 file_name += "make"; 2834 } 2835 } 2836 2837 cmt_string save_file_name = file_name; 2838 save_file_name += "cmtsave"; 2839 2840 if (CmtSystem::test_file (file_name)) 2841 { 2842 rename (file_name, save_file_name); 2843 } 2844 2845 cmt_string new_file_name = file_name; 2846 new_file_name += "new"; 2847 2848 m_output_file = fopen (new_file_name, "wb"); 2849 if (m_output_file != NULL) 2850 { 2851 m_PACKAGE = package; 2852 2853 packages_header_fragment.copy (m_output_file, 1, &m_PACKAGE); 2854 2855 Project* cur = Project::get_current (); 2856 Use::UsePtrVector uses (Use::get_ordered_uses ()); 2857 uses.push_back (&Use::current ()); 2858 cmt_string temp; 2859 for (int i = uses.size () - 1; i >= 0; i--) 2860 { 2861 Use* use = uses[i]; 2862 if (use->discarded) continue; 2863 if (use->m_hidden) continue; 2864 if (!use->located ()) continue; 2865 if (use->get_package ()->is_cmt ()) continue; 2866 2867 if (use->get_project () == cur) 2868 m_ISLOCAL = "is_local"; 2869 else 2870 m_ISLOCAL = "is_not_local"; 2871 2872 temp = use->get_full_path (); 2873 switch (use->style) 2874 { 2875 case cmt_style: 2876 temp += CmtSystem::file_separator (); 2877 temp += "cmt"; 2878 break; 2879 case mgr_style: 2880 temp += CmtSystem::file_separator (); 2881 temp += "mgr"; 2882 break; 2883 } 2884 #ifdef WIN32 2885 temp += " "; 2886 #endif 2887 m_PACKAGEMGRPATH = temp; 2888 // fprintf (m_output_file, "%s\n", temp.c_str()); 2889 2890 temp = ""; 2891 if (Symbol* s = Symbol::find (use->get_package_name () + "_offset")) 2892 { 2893 cmt_string o = s->build_macro_value (); 2894 if (o != "") 2895 { 2896 temp += o; 2897 temp += CmtSystem::file_separator (); 2898 } 2899 } 2900 else 2901 { 2902 CmtMessage::warning 2903 (CmtError::get_error_name (CmtError::symbol_not_found) 2904 + ": macro " + use->get_package_name () + "_offset"); 2905 } 2906 temp += use->get_package_name (); 2907 temp.replace_all (CmtSystem::file_separator (), "_"); 2908 #ifdef WIN32 2909 temp += " "; 2910 #endif 2911 m_PACKAGEFULLNAME = temp; 2912 // fprintf (m_output_file, "%s\n", temp.c_str()); 2913 2914 m_PACKAGE = use->get_package_name (); 2915 2916 Use::UsePtrVector subuses; 2917 for (int i = 0; i < use->sub_uses.size (); i++) 2918 { 2919 if (use->sub_uses[i]->m_index >= 0 && !use->sub_uses[i]->discarded) 2920 { 2921 if (use->sub_uses[i]->m_hidden) continue; 2922 subuses.push_back (use->sub_uses[i]); 2923 } 2924 else 2925 { 2926 Use* au (Use::find_valid (use->sub_uses[i]->get_package_name ())); 2927 if (au) 2928 { 2929 subuses.push_back (au); 2930 } 2931 } 2932 } 2933 m_DEPENDENCIES = ""; 2934 for (int i = 0; i < subuses.size (); i++) 2935 { 2936 if (i != 0) 2937 { 2938 m_DEPENDENCIES += " " + subuses[i]->get_package_name (); 2939 } 2940 else 2941 { 2942 m_DEPENDENCIES += subuses[i]->get_package_name (); 2943 } 2944 } 2945 2946 package_fragment.copy (m_output_file, 5, &m_PACKAGE, &m_DEPENDENCIES, 2947 &m_PACKAGEMGRPATH, &m_PACKAGEFULLNAME, &m_ISLOCAL); 2948 } 2949 2950 if (Symbol* s = Symbol::find ("CMTINSTALLAREA")) 2951 { 2952 cmt_string o = s->build_macro_value (); 2953 Symbol::expand (o); 2954 if (o != "") 2955 { 2956 temp = "CMTINSTALLAREA="; 2957 temp += o; 2958 #ifdef WIN32 2959 temp += " "; 2960 #endif 2961 fprintf (m_output_file, "%s\n", temp.c_str()); 2962 } 2963 } 2964 2965 packages_trailer_fragment.copy (m_output_file, 0); 2966 2967 CmtSystem::close_ostream (m_output_file, new_file_name); 2968 // fclose (m_output_file); 2969 2970 commit (new_file_name); 2971 } 2972 else 2973 { 2974 CmtError::set (CmtError::file_access_error, new_file_name); 2975 } 2976 } 2977 2978 //-------------------------------------------------- 2706 2979 2707 2980 /** … … 2794 3067 }; 2795 3068 3069 //-------------------------------------------------- 3070 void DependencyGenerator::reset () 3071 { 3072 CmtGenerator::reset (); 3073 m_deps_builder.clear (); 3074 m_stamps = true; 3075 m_name = ""; 3076 } 3077 3078 //-------------------------------------------------- 3079 void DependencyGenerator::prepare_includes () 3080 { 3081 cmt_string path; 3082 cmt_string substitution; 3083 3084 Use* use = &Use::current (); 3085 3086 // m_deps_builder.clear (); 3087 3088 if (use->include_path != "none") 3089 { 3090 if (use->include_path == "") 3091 { 3092 m_deps_builder.add (incdir, "$(src)"); 3093 } 3094 else 3095 { 3096 substitution = use->include_path; 3097 3098 path = substitution; 3099 Symbol::expand (path); 3100 3101 CmtSystem::reduce_file_separators (path); 3102 3103 m_deps_builder.add (path, substitution); 3104 } 3105 } 3106 3107 m_deps_builder.add_includes (*use); 3108 3109 Use::UsePtrVector& uses = Use::get_ordered_uses (); 3110 3111 if (uses.size () > 0) 3112 { 3113 int number; 3114 3115 for (number = 0; number < uses.size (); number++) 3116 { 3117 use = uses[number]; 3118 if (use->discarded) continue; 3119 3120 if (use->real_path != "") 3121 { 3122 if (use->include_path != "none") 3123 { 3124 if (use->include_path == "") 3125 { 3126 use->get_full_path (path); 3127 path += CmtSystem::file_separator (); 3128 path += "src"; 3129 3130 substitution = "$("; 3131 substitution += use->prefix; 3132 substitution += "ROOT)"; 3133 substitution += CmtSystem::file_separator (); 3134 substitution += "src"; 3135 substitution += CmtSystem::file_separator (); 3136 } 3137 else 3138 { 3139 substitution = use->include_path; 3140 3141 path = substitution; 3142 Symbol::expand (path); 3143 3144 CmtSystem::reduce_file_separators (path); 3145 } 3146 3147 m_deps_builder.add (path, substitution); 3148 } 3149 3150 m_deps_builder.add_includes (*use); 3151 } 3152 } 3153 } 3154 } 3155 3156 //-------------------------------------------------- 3157 void DependencyGenerator::prepare_header_file_filters () 3158 { 3159 const Use* current_use = &Use::current (); 3160 Use::UsePtrVector uses (Use::get_ordered_uses ()); 3161 uses.push_back (&Use::current ()); 3162 bool current_only (true); 3163 for (int i = uses.size () - 1; i >= 0; i--) 3164 { 3165 const Use* use = uses[i]; 3166 //cerr << "prepare_header_file_filters(0)> " << use->get_package_name () << "[" << use->get_index () << "]\n"; 3167 if (use->discarded) continue; 3168 if (use->m_hidden) continue; 3169 if (!use->located ()) continue; 3170 3171 if (current_only && use != current_use) 3172 current_only = false; 3173 3174 cmt_string package_name = use->get_package_name (); 3175 if (package_name == "CMT") continue; 3176 3177 const Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter"); 3178 if (filter_macro == 0) continue; 3179 3180 const Symbol* stamp_macro = Symbol::find (package_name + "_header_file_stamp"); 3181 cmt_string stamp; 3182 if (stamp_macro != 0) 3183 { 3184 stamp = stamp_macro->resolve_macro_value (); 3185 } 3186 else 3187 { 3188 use->get_full_path (stamp); 3189 switch (use->style) 3190 { 3191 case cmt_style: 3192 stamp += CmtSystem::file_separator (); 3193 stamp += "cmt"; 3194 break; 3195 case mgr_style: 3196 stamp += CmtSystem::file_separator (); 3197 stamp += "mgr"; 3198 break; 3199 } 3200 stamp += CmtSystem::file_separator (); 3201 stamp += "cmt_header_file.stamp"; 3202 //stamp += "cmt_all_headers.stamp"; 3203 //<package>/cmt/cmt_all_headers.stamp 3204 } 3205 if (!CmtSystem::test_file (stamp)) continue; 3206 3207 //cerr << "0: adding filter: " << use->get_package_name () << "[" << use->get_index () << "]\n"; 3208 cmt_regexp* filter = new cmt_regexp (filter_macro->resolve_macro_value ()); 3209 assert (filter != 0); 3210 3211 m_deps_builder.add_header_filter (use, filter, stamp); 3212 } 3213 3214 if (current_only) 3215 { // we are most likely reading dependencies[_CONSTITUENT].in without CMT 3216 for (int number = 0; number < Symbol::symbol_number (); number++) 3217 { 3218 const Symbol& symbol = Symbol::symbol (number); 3219 if (symbol.type != Symbol::SymbolMacro) continue; 3220 int r = symbol.name.find_last_of ("_header_file_filter"); 3221 if (r == cmt_string::npos || 3222 (r + 19) != symbol.name.size () || 3223 r == 0) continue; 3224 3225 cmt_string package_name = symbol.name.substr(0, r); 3226 const Use* use = Use::find (package_name); 3227 if (use == current_use) continue; 3228 if (0 != use && use->discarded) continue; 3229 if (0 != use && use->m_hidden) continue; 3230 if (0 != use && !use->located ()) continue; 3231 3232 //Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter"); 3233 //if (filter_macro == 0) continue; 3234 3235 const Symbol* stamp_macro = Symbol::find (package_name + "_header_file_stamp"); 3236 cmt_string stamp; 3237 if (stamp_macro != 0) 3238 { 3239 stamp = stamp_macro->resolve_macro_value (); 3240 } 3241 else if (0 != use) 3242 { 3243 use->get_full_path (stamp); 3244 switch (use->style) 3245 { 3246 case cmt_style: 3247 stamp += CmtSystem::file_separator (); 3248 stamp += "cmt"; 3249 break; 3250 case mgr_style: 3251 stamp += CmtSystem::file_separator (); 3252 stamp += "mgr"; 3253 break; 3254 } 3255 stamp += CmtSystem::file_separator (); 3256 stamp += "cmt_header_file.stamp"; 3257 } 3258 if (!CmtSystem::test_file (stamp)) continue; 3259 3260 //cerr << "1: adding filter: " << package_name << "\n"; 3261 cmt_regexp* filter = new cmt_regexp (symbol.resolve_macro_value ()); 3262 assert (filter != 0); 3263 3264 m_deps_builder.add_header_filter (use, filter, stamp); 3265 } 3266 } 3267 } 3268 3269 //-------------------------------------------------- 2796 3270 void DependencyGenerator::build (const CmtSystem::cmt_string_vector& arguments) 2797 3271 { 2798 3272 reset (); 2799 prepare_use_context ();2800 2801 prepare_header_file_filters ();2802 2803 const cmt_string& name = arguments[0];2804 2805 m_constituent = Constituent::find (name);2806 if (m_constituent == 0)2807 {2808 // Error : wrong constituent name...2809 return;2810 }2811 2812 const Constituent& constituent = *m_constituent;2813 2814 cmt_string file_name;2815 cmt_string full_name;2816 cmt_string compressed_name;2817 // cmt_string suffix;2818 cmt_string dependencies;2819 3273 2820 3274 // 2821 // Scan the sources.3275 // Parse arguments first 2822 3276 // 2823 2824 // 2825 // We have to rebuild the dependencies for : 2826 // 2827 // o all sources if the parameter -all_sources has been received 2828 // o otherwise, 2829 // + all source names provided in the argument list (if any) 2830 // + all source names missing from the existing dependency file (if any) 2831 // 2832 2833 const CmtSystem::cmt_string_vector& sources = constituent.modules; 2834 const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs; 2835 const cmt_vector<cmt_regexp>& selects = constituent.select_exprs; 2836 2837 m_stamps = true; 3277 CmtSystem::cmt_string_vector cli_input, all; 2838 3278 bool all_sources = false; 2839 2840 int source_number = arguments.size (); 2841 int i; 2842 2843 //cerr << "source_number=" << source_number << endl; 2844 2845 for (i = source_number-1; i >= 0; i--) 2846 { 2847 file_name = arguments[i]; 2848 2849 //cerr << "file_name=" << file_name << endl; 2850 2851 // Get rid of files that may come from the makefile fragment 2852 if (file_name.find ("requirements") != cmt_string::npos) source_number--; 2853 else if (file_name.substr (0, 5) == "-out=" || 2854 file_name.substr (0, 5) == "-out:" || 2855 file_name.substr (0, 5) == "/out:" || 2856 file_name.substr (0, 5) == "/out=") 2857 { 2858 source_number--; 3279 bool config_files (false); 3280 bool start_all (false); 3281 3282 for (int i = 0; i < arguments.size (); i++) 3283 { 3284 cmt_string file_name = arguments[i]; 3285 3286 //cerr << "i: " << i << " file_name=" << file_name << endl; 3287 3288 if (file_name.substr (0, 5) == "-out=" || 3289 file_name.substr (0, 5) == "-out:" || 3290 file_name.substr (0, 5) == "/out:" || 3291 file_name.substr (0, 5) == "/out=") 3292 { 2859 3293 file_name.erase (0, 5); 2860 3294 m_output_file_name = file_name; 2861 3295 } 2862 else if (file_name.find (".make") != cmt_string::npos) source_number--;2863 3296 else if (file_name == "-all_sources" || 2864 3297 file_name == "/all_sources") 2865 3298 { 2866 source_number = sources.size ();2867 3299 all_sources = true; 2868 3300 } … … 2870 3302 file_name == "/no_stamps") 2871 3303 { 2872 source_number--;2873 3304 m_stamps = false; 2874 3305 } 2875 } 3306 else if (file_name.substr (0, 2) == "-I" || 3307 file_name.substr (0, 2) == "/I") 3308 { 3309 file_name.erase (0, 2); 3310 //cerr << "include: " << file_name << endl; 3311 m_deps_builder.add (file_name, file_name); 3312 } 3313 else if (file_name == "-start_all" || 3314 file_name == "/start_all") 3315 { 3316 if (start_all) 3317 { 3318 CmtError::set(CmtError::syntax_error, 3319 "Unexpected option " + file_name); 3320 return; 3321 } 3322 start_all = true; 3323 } 3324 else if (file_name == "-end_all" || 3325 file_name == "/end_all") 3326 { 3327 if (!start_all) 3328 { 3329 CmtMessage::warning 3330 (CmtError::get_error_name (CmtError::syntax_error) 3331 + ": Unexpected option " + file_name); 3332 } 3333 start_all = false; 3334 } 3335 else if (file_name.substr (0, 1) == "-" 3336 #ifdef WIN32 3337 || file_name.substr (0, 1) == "/" 3338 #endif 3339 ) 3340 { 3341 if (CmtMessage::active (Verbose)) 3342 CmtMessage::warning 3343 (CmtError::get_error_name (CmtError::warning) 3344 + ": Unknown option " + file_name); 3345 } 3346 else if (file_name.substr (file_name.size () - 12) == "requirements" || 3347 file_name.substr (file_name.size () - 5) == ".make" || 3348 file_name.substr (file_name.size () - 3) == ".mk" || 3349 file_name.substr (file_name.size () - 6) == ".nmake" || 3350 file_name.substr (file_name.size () - 3) == ".in" || 3351 file_name.substr (file_name.size () - 6) == ".stamp") 3352 { 3353 // Configuration changed, 3354 // want to rebuild dependencies from scratch 3355 if (!config_files) config_files = true; 3356 if (!all_sources) all_sources = true; 3357 } 3358 else if (start_all) 3359 { 3360 all.push_back (file_name); 3361 } 3362 else if (m_name.size () != 0) 3363 { 3364 cli_input.push_back (file_name); 3365 } 3366 else 3367 { 3368 if (file_name.size () != 0) 3369 m_name = file_name; 3370 } 3371 } 3372 3373 if (start_all) 3374 CmtMessage::warning 3375 (CmtError::get_error_name (CmtError::syntax_error) 3376 + ": Missing option -end_all"); 3377 3378 //cerr << "m_name: " << m_name << endl; 3379 if (m_name.size () == 0) 3380 { 3381 CmtError::set(CmtError::syntax_error, 3382 "Name missing as first argument"); 3383 return; 3384 } 3385 3386 //cerr << "config_files: " << config_files << endl; 3387 3388 m_constituent = Constituent::find (m_name); 3389 3390 if (!config_files && 0 == cli_input.size () && 3391 0 == all.size () && 0 == m_constituent) 3392 { 3393 CmtError::set(CmtError::syntax_error, 3394 m_name + ": Files arguments missing"); 3395 return; 3396 } 3397 /* 3398 cerr << "cli_input:"; 3399 for (int i = 0; i < cli_input.size (); i++) 3400 cerr << " " << cli_input[i]; 3401 cerr << "\n"; 3402 3403 cerr << "all:"; 3404 for (int i = 0; i < all.size (); i++) 3405 cerr << " " << all[i]; 3406 cerr << "\n"; 3407 */ 3408 prepare_includes (); 3409 prepare_header_file_filters (); 2876 3410 2877 3411 // … … 2922 3456 { 2923 3457 m_output_file_name = m_bin; 2924 m_output_file_name += name;3458 m_output_file_name += m_name; 2925 3459 m_output_file_name += "_"; 2926 3460 m_output_file_name += "dependencies."; … … 2935 3469 } 2936 3470 2937 if (all_sources) 2938 { 2939 for (i = 0; i < sources.size (); i++) 2940 { 2941 file_name = sources[i]; 2942 2943 set_full_name (full_name, file_name); 2944 if (full_name == "") continue; 2945 2946 CmtSystem::compress_path (full_name, compressed_name); 2947 full_name = compressed_name; 2948 2949 static CmtSystem::cmt_string_vector files; 2950 2951 get_all_files (full_name, excludes, selects, files); 2952 2953 for (int j = 0; j < files.size (); j++) 2954 { 2955 const cmt_string& name = files[j]; 2956 2957 if (name != "") 2958 { 2959 const cmt_string& line = build (name); 2960 2961 add_line_to_text (line, dependencies); 2962 } 2963 } 2964 } 2965 } 2966 else 2967 { 2968 // 2969 // New read the existing dependency file if any and filter it to 2970 // extract the source names 2971 // 2972 static DependencyFilter filter; 2973 dependencies.read (m_output_file_name); 2974 filter.run (dependencies); 2975 2976 for (i = 1; i < source_number; i++) 2977 { 2978 file_name = arguments[i]; 2979 2980 set_full_name (full_name, file_name); 2981 if (full_name == "") continue; 2982 2983 CmtSystem::compress_path (full_name, compressed_name); 2984 full_name = compressed_name; 2985 2986 const cmt_string& line = build (full_name); 2987 2988 add_line_to_text (line, dependencies); 2989 2990 filter.add_source (full_name); 2991 2992 } 2993 2994 // Now : are there still any missing source file in dependencies?? 2995 2996 for (i = 0; i < sources.size (); i++) 2997 { 2998 file_name = sources[i]; 2999 3000 set_full_name (full_name, file_name); 3001 if (full_name == "") continue; 3002 3003 CmtSystem::compress_path (full_name, compressed_name); 3004 full_name = compressed_name; 3005 3006 static CmtSystem::cmt_string_vector files; 3007 3008 get_all_files (full_name, excludes, selects, files); 3009 3010 for (int j = 0; j < files.size (); j++) 3011 { 3012 const cmt_string& name = files[j]; 3013 if (name != "") 3014 { 3015 if (!filter.has_source (name)) 3016 { 3017 const cmt_string& line = build (name); 3018 3019 add_line_to_text (line, dependencies); 3020 } 3021 } 3022 } 3023 } 3024 } 3471 //------------------------------------------------------------------------------- 3472 // 3473 // For Makefile, we need to select, from cli_input, source files only, 3474 // there may be dependencies of source files (typically, header files) as well 3475 // 3476 cmt_string dependencies; 3477 if (!all_sources) 3478 { 3479 // want to validate cli_input against 3480 // either 3481 // o all cli sources 3482 // or 3483 // o m_constituent sources 3484 set_source_files (all); 3485 if (0 == validate (cli_input)) 3486 { 3487 // cli_input contains source files ONLY 3488 // calculate dependencies for them ONLY 3489 if (CmtSystem::test_file (m_output_file_name)) 3490 { 3491 if (!dependencies.read (m_output_file_name)) 3492 { 3493 CmtError::set (CmtError::file_access_error, m_output_file_name); 3494 return; 3495 } 3496 } 3497 fill_dependencies (dependencies, cli_input); 3498 } 3499 else 3500 { 3501 all_sources = true; 3502 // calculate dependencies for 3503 // all cli sources 3504 // or 3505 // m_constituent sources 3506 fill_dependencies (dependencies); 3507 } 3508 /* 3509 if (0 != all.size ()) 3510 { 3511 // o all cli sources 3512 int n_invalid = 0; 3513 for (int i = 0; i < cli_input.size (); i++) 3514 { 3515 bool valid = false; 3516 for (int j = 0; j < all.size (); j++) 3517 if (cli_input[i] == all[j]) 3518 { 3519 valid = true; 3520 break; 3521 } 3522 if (!valid) 3523 { 3524 n_invalid += 1; 3525 break; 3526 } 3527 } 3528 if (0 == n_invalid) 3529 { 3530 // cli_input contains source files ONLY 3531 // calculate dependencies for them ONLY 3532 if (CmtSystem::test_file (m_output_file_name)) 3533 { 3534 if (!dependencies.read (m_output_file_name)) 3535 { 3536 CmtError::set (CmtError::file_access_error, m_output_file_name); 3537 return; 3538 } 3539 } 3540 fill_dependencies (dependencies, cli_input); 3541 } 3542 else 3543 { 3544 all_sources = true; 3545 // calculate dependencies for all (all cli sources) 3546 fill_dependencies (dependencies, all); 3547 } 3548 } 3549 else // 0 == all.size () 3550 { 3551 // set_source_files (); 3552 if (int n = set_source_files ()) 3553 // if (0 != m_source_files.size ()) 3554 { 3555 // o m_constituent sources 3556 int n_invalid = 0; 3557 for (int i = 0; i < cli_input.size (); i++) 3558 { 3559 bool valid = false; 3560 for (int j = 0; j < n; j++) 3561 if (cli_input[i] == m_source_files[j].name ()) 3562 { 3563 valid = true; 3564 break; 3565 } 3566 if (!valid) 3567 { 3568 n_invalid += 1; 3569 break; 3570 } 3571 } 3572 if (0 == n_invalid) 3573 { 3574 // cli_input contains source files ONLY 3575 // calculate dependencies for them ONLY 3576 if (CmtSystem::test_file (m_output_file_name)) 3577 { 3578 if (!dependencies.read (m_output_file_name)) 3579 { 3580 CmtError::set (CmtError::file_access_error, m_output_file_name); 3581 return; 3582 } 3583 } 3584 fill_dependencies (dependencies, cli_input); 3585 } 3586 else 3587 { 3588 all_sources = true; 3589 // calculate dependencies for m_source_files 3590 // (m_constituent sources) 3591 fill_dependencies (dependencies); 3592 } 3593 } 3594 else // 0 == m_source_files.size ()) 3595 { 3596 // no source files to validate against 3597 fill_dependencies (dependencies, cli_input); 3598 } 3599 } 3600 */ 3601 } 3602 else // all_sources = true 3603 { 3604 if (int n = set_source_files (all)) 3605 { 3606 // calculate dependencies for m_source_files 3607 // either 3608 // o all cli sources 3609 // or 3610 // o m_constituent sources 3611 // if any existing 3612 fill_dependencies (dependencies); 3613 } 3614 else 3615 { 3616 // calculate dependencies for all we have 3617 fill_dependencies (dependencies, cli_input); 3618 } 3619 /* 3620 if (0 != all.size ()) 3621 { 3622 // calculate dependencies for all (all cli sources) 3623 fill_dependencies (dependencies, all); 3624 } 3625 else 3626 { 3627 if (int n = set_source_files ()) 3628 { 3629 // calculate dependencies for m_source_files (m_constituent sources) 3630 fill_dependencies (dependencies); 3631 } 3632 else 3633 { 3634 // calculate dependencies for all we have 3635 fill_dependencies (dependencies, cli_input); 3636 } 3637 } 3638 */ 3639 } 3640 3641 if (CmtError::has_pending_error ()) 3642 { 3643 if (CmtError::get_last_error_code () == CmtError::path_not_found || 3644 CmtError::get_last_error_code () == CmtError::file_access_error || 3645 CmtError::get_last_error_code () == CmtError::execution_failed) 3646 return; 3647 } 3648 //------------------------------------------------------------------------------- 3025 3649 3026 3650 FILE* f = fopen (m_output_file_name.c_str (), "wb"); … … 3030 3654 dependencies.write (f); 3031 3655 CmtSystem::close_ostream (f, m_output_file_name); 3032 // fclose (f);3033 3656 } 3034 3657 else 3035 3658 { 3036 3659 CmtError::set (CmtError::file_access_error, m_output_file_name); 3037 // CmtMessage::error ("Cannot open " + m_output_file_name + " for write");3038 3660 } 3039 3661 … … 3043 3665 //-------------------------------------------------- 3044 3666 // o text contains lines with a pattern like : 3045 // key = xxxxx 3046 // 3667 // key = value 3047 3668 // o line follows the same pattern 3048 3669 // 3049 // This function appends <line> to <text> only if the key found in 3050 // <line> is not found in <text> 3670 // This function 3671 // o if the key found in <line> is found in <text>, removes the first line in <text> with the key, if any 3672 // o appends <line> to <text> 3051 3673 //-------------------------------------------------- 3052 void DependencyGenerator::add_line_to_text (const cmt_string& line, cmt_string& text) 3674 void DependencyGenerator::add_line_to_text (const cmt_string& line, cmt_string& text) const 3053 3675 { 3054 3676 static const cmt_string empty; … … 3091 3713 } 3092 3714 3715 //-------------------------------------------------- 3093 3716 cmt_string DependencyGenerator::build (const cmt_string& file_name) 3094 3717 { 3095 3718 Log; 3096 3719 3097 const Constituent& constituent = *m_constituent;3720 // const Constituent& constituent = *m_constituent; 3098 3721 3099 3722 static cmt_string full_name; … … 3105 3728 line = ""; 3106 3729 3730 /* 3107 3731 if (!CmtSystem::absolute_path (file_name)) 3108 3732 { 3109 3733 full_name = srcdir; 3110 3734 } 3735 */ 3111 3736 3112 3737 full_name += file_name; … … 3116 3741 CmtSystem::get_suffix (full_name, suffix); 3117 3742 3118 if (name == "requirements") return (line); 3119 3120 const CmtSystem::cmt_string_vector& deps = m_deps_builder.run (full_name); 3743 // if (name == "requirements") return (line); 3744 3745 const CmtSystem::cmt_string_vector& deps = m_deps_builder.run (full_name, m_name); 3746 if (CmtError::has_pending_error ()) 3747 { 3748 return line; 3749 } 3750 // CmtError::set (CmtError::execution_failed, preprocessor, status); 3751 // CmtError::set (CmtError::file_access_error, header_file_path); 3752 // CmtError::set (CmtError::path_not_found, name); 3121 3753 3122 3754 line = name; … … 3157 3789 if (m_stamps) 3158 3790 { 3159 cmt_string stamp_output_base = constituent.name; 3791 cmt_string stamp_output_base = m_name; 3792 // cmt_string stamp_output_base = constituent.name; 3160 3793 stamp_output_base += "_deps"; 3161 3794 … … 3165 3798 if (!CmtSystem::mkdir (stamp_output)) 3166 3799 { 3167 CmtMessage::error ("Cannot create the binary output directory for this constituent " + stamp_output); 3168 // cerr << "Cannot create the binary output directory for this constituent" << endl; 3800 CmtError::set (CmtError::file_access_error, 3801 + "Cannot create directory " + stamp_output 3802 + " for " + m_name); 3803 return line; 3169 3804 } 3170 3805 … … 3185 3820 if (CmtSystem::test_file (stamp_output)) 3186 3821 { 3187 old_stamp.read (stamp_output); 3188 } 3189 3190 if (line != old_stamp) 3191 { 3192 line.write (stamp_output); 3822 if (!old_stamp.read (stamp_output)) 3823 { 3824 CmtError::set (CmtError::file_access_error, stamp_output); 3825 return line; 3826 } 3827 // old_stamp.read (stamp_output); 3828 } 3829 3830 if (line != old_stamp.substr(0, old_stamp.size () - 1)) 3831 { 3832 if (!(line + "\n").write (stamp_output)) 3833 { 3834 CmtError::set (CmtError::file_access_error, stamp_output); 3835 return line; 3836 } 3837 // (line + "\n").write (stamp_output); 3193 3838 } 3194 3839 } … … 3198 3843 3199 3844 //-------------------------------------------------- 3200 void DependencyGenerator::prepare_header_file_filters () 3201 { 3202 // Use::UsePtrVector& uses = Use::get_ordered_uses (); 3203 Use::UsePtrVector uses (Use::get_ordered_uses ()); 3204 uses.push_back (&Use::current ()); 3205 for (int i = uses.size () - 1; i >= 0; i--) 3206 { 3207 Use* use = uses[i]; 3208 if (use->discarded) continue; 3209 if (use->m_hidden) continue; 3210 if (!use->located ()) continue; 3211 3212 cmt_string package_name = use->get_package_name (); 3213 if (package_name == "CMT") continue; 3214 3215 Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter"); 3216 if (filter_macro == 0) continue; 3217 3218 Symbol* stamp_macro = Symbol::find (package_name + "_header_file_stamp"); 3219 cmt_string stamp; 3220 if (stamp_macro != 0) 3221 { 3222 stamp = stamp_macro->resolve_macro_value (); 3223 } 3224 else 3225 { 3226 use->get_full_path (stamp); 3227 stamp += CmtSystem::file_separator (); 3228 if (use->style == mgr_style) stamp += "mgr"; 3229 else stamp += "cmt"; 3230 stamp += CmtSystem::file_separator (); 3231 stamp += "cmt_header_file.stamp"; 3232 //stamp += "cmt_all_headers.stamp"; 3233 //<package>/cmt/cmt_all_headers.stamp 3234 } 3235 if (!CmtSystem::test_file (stamp)) continue; 3236 3237 cmt_regexp* filter = new cmt_regexp (filter_macro->resolve_macro_value ()); 3238 assert (filter != 0); 3239 3240 m_deps_builder.add_header_filter (use, filter, stamp); 3241 } 3242 } 3845 int DependencyGenerator::fill_dependencies (cmt_string& dependencies) 3846 { 3847 CmtSystem::cmt_string_vector sources; 3848 for (int i = 0; i < m_source_files.size (); i++) 3849 { 3850 const SourceFile& file = m_source_files[i]; 3851 sources.push_back (file.name ()); 3852 } 3853 return fill_dependencies (dependencies, sources); 3854 } 3855 3856 //-------------------------------------------------- 3857 int DependencyGenerator::fill_dependencies (cmt_string& dependencies, 3858 const CmtSystem::cmt_string_vector& sources) 3859 { 3860 int retval (0); 3861 cmt_string file_name; 3862 cmt_string compressed_name; 3863 3864 for (int i = 0; i < sources.size (); i++) 3865 { 3866 file_name = sources[i]; 3867 //set_full_name (full_name, file_name); 3868 CmtSystem::reduce_file_separators (file_name); 3869 if (file_name == "") continue; 3870 CmtSystem::compress_path (file_name, compressed_name); 3871 file_name = compressed_name; 3872 //cerr << "file_name: " << file_name << endl; 3873 if (file_name == "") continue; 3874 3875 const cmt_string& line = build (file_name); 3876 if (CmtError::has_pending_error ()) 3877 { 3878 // if (CmtError::get_last_error_code () == CmtError::file_access_error) 3879 return -1; 3880 } 3881 3882 //cerr << "line: " << line << endl; 3883 add_line_to_text (line, dependencies); 3884 //cerr << "dependencies: " << dependencies << endl; 3885 } 3886 3887 return retval; 3888 } 3889 3890 //-------------------------------------------------- 3891 int DependencyGenerator::set_source_files (const CmtSystem::cmt_string_vector& files) 3892 { 3893 m_source_files.clear (); 3894 3895 for (int j = 0; j < files.size (); j++) 3896 { 3897 const cmt_string& name = files[j]; 3898 if (name == "") continue; 3899 3900 bool included = false; 3901 for (int k = m_source_files.size () - 1; k >= 0; k--) 3902 if (m_source_files[k].name () == name) 3903 { 3904 included = true; 3905 break; 3906 } 3907 if (included) continue; 3908 3909 SourceFile& source = m_source_files.add (); 3910 source.set (name, Language::null (), ""); 3911 } 3912 3913 if (m_source_files.size ()) return m_source_files.size (); 3914 else return set_source_files (); 3915 } 3916 3917 //-------------------------------------------------- 3918 int DependencyGenerator::set_source_files () 3919 { 3920 if (0 == m_constituent && 0 != m_name.size ()) 3921 m_constituent = Constituent::find (m_name); 3922 if (0 == m_constituent) return 0; 3923 3924 m_source_files.clear (); 3925 3926 const CmtSystem::cmt_string_vector& sources = m_constituent->modules; 3927 const cmt_vector<cmt_regexp>& excludes = m_constituent->exclude_exprs; 3928 const cmt_vector<cmt_regexp>& selects = m_constituent->select_exprs; 3929 3930 cmt_string file_name, full_name; 3931 cmt_string compressed_name; 3932 cmt_string visited, token; 3933 3934 for (int i = 0; i < sources.size (); i++) 3935 { 3936 file_name = sources[i]; 3937 set_full_name (full_name, file_name); 3938 if (full_name == "") continue; 3939 3940 CmtSystem::compress_path (full_name, compressed_name); 3941 full_name = compressed_name; 3942 3943 static CmtSystem::cmt_string_vector files; 3944 3945 get_all_files (full_name, excludes, selects, files); 3946 3947 for (int j = 0; j < files.size (); j++) 3948 { 3949 const cmt_string& name = files[j]; 3950 3951 if (name == "") continue; 3952 3953 cmt_string suffix; 3954 CmtSystem::get_suffix (name, suffix); 3955 Language& language = Language::find_with_suffix (suffix); 3956 3957 if ((m_constituent->type == Application || m_constituent->type == Library) 3958 && language != Language::null () && language.native_dependencies ()) 3959 continue; 3960 3961 bool included = false; 3962 for (int k = m_source_files.size () - 1; k >= 0; k--) 3963 if (m_source_files[k].name () == name) 3964 { 3965 included = true; 3966 break; 3967 } 3968 if (included) continue; 3969 3970 SourceFile& source = m_source_files.add (); 3971 source.set (name, language, ""); 3972 } 3973 } 3974 return m_source_files.size (); 3975 } 3976 3977 //-------------------------------------------------- 3978 /** 3979 * Returns 0, if each file in files is found in m_source_files, 3980 * otherwise returns 1 3981 */ 3982 //-------------------------------------------------- 3983 int DependencyGenerator::validate (const CmtSystem::cmt_string_vector& files) const 3984 { 3985 int n_invalid = 0; 3986 for (int i = 0; i < files.size (); i++) 3987 { 3988 bool valid = false; 3989 for (int j = 0; j < m_source_files.size (); j++) 3990 if (files[i] == m_source_files[j].name ()) 3991 { 3992 valid = true; 3993 break; 3994 } 3995 if (!valid) 3996 { 3997 n_invalid += 1; 3998 break; 3999 } 4000 } 4001 4002 return n_invalid; 4003 }
Note: See TracChangeset
for help on using the changeset viewer.