Changeset 32cd4fc in rtems-tools
- Timestamp:
- Sep 7, 2014, 12:47:00 AM (6 years ago)
- Branches:
- 4.10, 4.11, 5, master
- Children:
- b28e8b3
- Parents:
- 3f5e31f
- Location:
- linkers
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
linkers/rld-path.cpp
r3f5e31f r32cd4fc 20 20 21 21 #include <sys/stat.h> 22 #include <unistd.h> 22 23 23 24 #include <rld.h> … … 84 85 } 85 86 86 void path_join (const std::string& base, const paths& parts, std::string& joined) 87 void 88 path_join (const std::string& base, const paths& parts, std::string& joined) 87 89 { 88 90 joined = base; … … 129 131 } 130 132 133 void 134 unlink (const std::string& path, bool not_present_error) 135 { 136 struct stat sb; 137 if (::stat (path.c_str (), &sb) >= 0) 138 { 139 if (!S_ISREG (sb.st_mode)) 140 throw rld::error ("Not a regular file", "unlinking: " + path); 141 142 int r; 143 #if _WIN32 144 r = ::remove(path.c_str ()); 145 #else 146 r = ::unlink (path.c_str ()); 147 #endif 148 if (r < 0) 149 throw rld::error (::strerror (errno), "unlinking: " + path); 150 } 151 else 152 { 153 if (not_present_error) 154 throw rld::error ("Not found", "unlinking: " + path); 155 } 156 } 131 157 } 132 158 } -
linkers/rld-path.h
r3f5e31f r32cd4fc 129 129 paths& search_paths); 130 130 131 /** 132 * Unlink the file. 133 * 134 * @param path The path of the file to unlink. 135 */ 136 void unlink (const std::string& path, bool not_present_error = false); 137 131 138 } 132 139 } -
linkers/rld-process.cpp
r3f5e31f r32cd4fc 61 61 { 62 62 /** 63 * Keep thetemporary files if true. Used to help debug a system.63 * Global keep of temporary files if true. Used to help debug a system. 64 64 */ 65 65 bool keep_temporary_files = false; … … 80 80 81 81 const std::string 82 temporary_files::get (const std::string& suffix )82 temporary_files::get (const std::string& suffix, bool keep) 83 83 { 84 84 char* temp = ::make_temp_file (suffix.c_str ()); … … 87 87 throw rld::error ("bad temp name", "temp-file"); 88 88 89 std::string name = temp; 90 91 name = rld::find_replace (name, 92 RLD_PATH_SEPARATOR_STR RLD_PATH_SEPARATOR_STR, 93 RLD_PATH_SEPARATOR_STR); 94 95 tempfiles.push_back (name); 96 89 const std::string name = rld::find_replace (temp, 90 RLD_PATH_SEPARATOR_STR RLD_PATH_SEPARATOR_STR, 91 RLD_PATH_SEPARATOR_STR); 92 tempfile_ref ref (name, keep); 93 tempfiles.push_back (ref); 97 94 return name; 98 95 } 99 96 100 97 void 101 temporary_files::unlink (const std::string& name) 102 { 103 if (!keep_temporary_files) 104 { 105 struct stat sb; 106 if ((::stat (name.c_str (), &sb) >= 0) && S_ISREG (sb.st_mode)) 107 { 108 int r; 109 #if _WIN32 110 r = ::remove(name.c_str ()); 111 #else 112 r = ::unlink (name.c_str ()); 113 #endif 114 if (r < 0) 115 { 116 std::cerr << "error: unlinking temp file: " << name << std::endl; 117 ::exit (100); 118 } 119 } 120 } 98 temporary_files::unlink (const tempfile_ref& ref) 99 { 100 if (!keep_temporary_files && !ref.keep) 101 rld::path::unlink (ref.name); 121 102 } 122 103 … … 128 109 ++tfi) 129 110 { 130 if ( *tfi== name)131 { 132 unlink ( name);111 if ((*tfi).name == name) 112 { 113 unlink (*tfi); 133 114 tempfiles.erase (tfi); 134 115 break; … … 138 119 139 120 void 140 temporary_files:: clean_up ()121 temporary_files::keep (const std::string& name) 141 122 { 142 123 for (tempfile_container::iterator tfi = tempfiles.begin (); … … 144 125 ++tfi) 145 126 { 127 if ((*tfi).name == name) 128 { 129 (*tfi).keep = true; 130 break; 131 } 132 } 133 } 134 135 void 136 temporary_files::clean_up () 137 { 138 for (tempfile_container::iterator tfi = tempfiles.begin (); 139 tfi != tempfiles.end (); 140 ++tfi) 141 { 146 142 unlink (*tfi); 147 143 } 148 144 } 149 145 150 tempfile::tempfile (const std::string& suffix )146 tempfile::tempfile (const std::string& suffix, bool _keep) 151 147 : suffix (suffix), 148 overridden (false), 152 149 fd (-1), 153 150 level (0) 154 151 { 155 _name = temporaries.get (suffix );152 _name = temporaries.get (suffix, _keep); 156 153 } 157 154 … … 165 162 tempfile::open (bool writable) 166 163 { 167 if ((fd < 0) && rld::path::check_file (_name)) 168 { 164 if (fd < 0) 165 { 166 bool ok = rld::path::check_file (_name); 167 int flags = writable ? O_RDWR : O_RDONLY; 168 169 if (overridden) 170 { 171 flags |= O_CREAT | O_TRUNC; 172 } 173 else 174 { 175 if (!ok) 176 throw rld::error ("Not found.", "tempfile open:" + _name); 177 } 178 169 179 level = 0; 170 fd = ::open (_name.c_str (), writable ? O_RDWR : O_RDONLY);180 fd = ::open (_name.c_str (), flags); 171 181 if (fd < 0) 172 182 throw rld::error (::strerror (errno), "tempfile open:" + _name); … … 183 193 level = 0; 184 194 } 195 } 196 197 void 198 tempfile::override (const std::string& name_) 199 { 200 if (fd >= 0) 201 throw rld::error ("Already open", "tempfile override"); 202 rld::path::unlink (_name); 203 overridden = true; 204 _name = name_ + suffix; 205 } 206 207 void 208 tempfile::keep () 209 { 210 temporaries.keep (_name); 185 211 } 186 212 -
linkers/rld-process.h
r3f5e31f r32cd4fc 35 35 { 36 36 /** 37 * Temporary file is a name and keep state. 38 */ 39 struct tempfile_ref 40 { 41 const std::string name; //< The name of the tempfile. 42 bool keep; //< If true do not delete this file. 43 44 tempfile_ref (const std::string& name, bool keep = false) 45 : name (name), 46 keep (keep) { 47 } 48 }; 49 50 /** 37 51 * Manage temporary files. We keep these so we can delete them when 38 52 * we exit. … … 44 58 * Container of temporary file names. 45 59 */ 46 typedef std::list < std::string> tempfile_container;60 typedef std::list < tempfile_ref > tempfile_container; 47 61 48 62 /** … … 59 73 * Get a new temporary file name. 60 74 */ 61 const std::string get (const std::string& suffix = ".rldxx"); 75 const std::string get (const std::string& suffix = ".rldxx", 76 bool keep = false); 62 77 63 78 /** … … 67 82 68 83 /** 84 * Set the tempfile reference keep state to true. 85 */ 86 void keep (const std::string& name); 87 88 /** 69 89 * Remove all temporary files. 70 90 */ … … 74 94 75 95 /* 76 * Delete the file.77 */ 78 void unlink (const std::string& name);96 * Delete the tempfile given the reference if not keeping. 97 */ 98 void unlink (const tempfile_ref& ref); 79 99 80 100 tempfile_container tempfiles; //< The temporary files. … … 90 110 91 111 /** 92 * Get a temporary file name .93 */ 94 tempfile (const std::string& suffix = ".rldxx" );112 * Get a temporary file name given a suffix. 113 */ 114 tempfile (const std::string& suffix = ".rldxx", bool keep = false); 95 115 96 116 /** … … 108 128 */ 109 129 void close (); 130 131 /** 132 * Override the temp file name automatically assigned with this name. The 133 * suffix is appended. 134 */ 135 void override (const std::string& name); 136 137 /** 138 * Set the temp file keep state to true so it is not deleted. 139 */ 140 void keep (); 110 141 111 142 /** … … 158 189 private: 159 190 160 std::string _name; //< The name of the file. 161 const std::string suffix; //< The temp file's suffix. 162 int fd; //< The file descriptor 163 char buf[256]; //< The read buffer. 164 int level; //< The level of data in the buffer. 191 std::string _name; //< The name of the file. 192 const std::string suffix; //< The temp file's suffix. 193 bool overridden; //< The name is overridden; may no exist. 194 int fd; //< The file descriptor 195 char buf[256]; //< The read buffer. 196 int level; //< The level of data in the buffer. 165 197 }; 166 198 -
linkers/rld.h
r3f5e31f r32cd4fc 273 273 274 274 /** 275 * The RTEMS version string. 275 * The RTEMS version string. @todo move to rld-rtems. 276 276 */ 277 277 const std::string rtems_version (); -
linkers/rtems-tld.cpp
r3f5e31f r32cd4fc 728 728 rld::cc::append_flags (rld::cc::ft_cflags, args); 729 729 730 args.push_back ("-O2"); 731 args.push_back ("-g"); 730 732 args.push_back ("-c"); 731 args.push_back ("-o 733 args.push_back ("-o"); 732 734 args.push_back (o.name ()); 733 735 args.push_back (c.name ()); … … 783 785 { "rtems-bsp", required_argument, NULL, 'B' }, 784 786 { "config", required_argument, NULL, 'C' }, 787 { "wrapper", required_argument, NULL, 'W' }, 785 788 { NULL, 0, NULL, 0 } 786 789 }; … … 791 794 std::cout << "rtems-trace-ld [options] objects" << std::endl 792 795 << "Options and arguments:" << std::endl 793 << " -h : help (also --help)" << std::endl 794 << " -V : print linker version number and exit (also --version)" << std::endl 795 << " -v : verbose (trace import parts), can supply multiple times" << std::endl 796 << " to increase verbosity (also --verbose)" << std::endl 797 << " -w : generate warnings (also --warn)" << std::endl 798 << " -k : keep temporary files (also --keep)" << std::endl 799 << " -E prefix : the RTEMS tool prefix (also --exec-prefix)" << std::endl 800 << " -c cflags : C compiler flags (also --cflags)" << std::endl 801 << " -r path : RTEMS path (also --rtems)" << std::endl 802 << " -B bsp : RTEMS arch/bsp (also --rtems-bsp)" << std::endl 803 << " -C ini : user configuration INI file (also --config)" << std::endl; 796 << " -h : help (also --help)" << std::endl 797 << " -V : print linker version number and exit (also --version)" << std::endl 798 << " -v : verbose (trace import parts), can supply multiple times" << std::endl 799 << " to increase verbosity (also --verbose)" << std::endl 800 << " -w : generate warnings (also --warn)" << std::endl 801 << " -k : keep temporary files (also --keep)" << std::endl 802 << " -E prefix : the RTEMS tool prefix (also --exec-prefix)" << std::endl 803 << " -c cflags : C compiler flags (also --cflags)" << std::endl 804 << " -r path : RTEMS path (also --rtems)" << std::endl 805 << " -B bsp : RTEMS arch/bsp (also --rtems-bsp)" << std::endl 806 << " -W wrapper : Wrapper file name without ext (also --wrapper)" << std::endl 807 << " -C ini : user configuration INI file (also --config)" << std::endl; 804 808 ::exit (exit_code); 805 809 } … … 852 856 std::string configuration; 853 857 std::string trace = "tracer"; 858 std::string wrapper; 854 859 bool arch_bsp_load = false; 855 860 856 861 while (true) 857 862 { 858 int opt = ::getopt_long (argc, argv, "hvwkVE:c:C:r:B: ", rld_opts, NULL);863 int opt = ::getopt_long (argc, argv, "hvwkVE:c:C:r:B:W:", rld_opts, NULL); 859 864 if (opt < 0) 860 865 break; … … 903 908 break; 904 909 910 case 'W': 911 wrapper = optarg; 912 break; 913 905 914 case '?': 906 915 usage (3); … … 946 955 try 947 956 { 957 linker.load_config (configuration, trace); 958 948 959 rld::process::tempfile c (".c"); 949 960 rld::process::tempfile o (".o"); 950 961 951 linker.load_config (configuration, trace); 962 if (!wrapper.empty ()) 963 { 964 c.override (wrapper); 965 c.keep (); 966 o.override (wrapper); 967 o.keep (); 968 } 969 952 970 linker.generate_wrapper (c); 953 971 linker.compile_wrapper (c, o);
Note: See TracChangeset
for help on using the changeset viewer.