Changeset a136346 in rtems-tools
- Timestamp:
- 08/05/14 13:01:15 (8 years ago)
- Branches:
- 4.10, 4.11, 5, master
- Children:
- 4fd758e
- Parents:
- 058d502
- Location:
- linkers
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
linkers/rld-cc.cpp
r058d502 ra136346 100 100 { 101 101 std::string line; 102 out. getline (line);102 out.read_line (line); 103 103 if (line.size () == 0) 104 104 break; … … 144 144 out.output ("cc", std::cout, true); 145 145 out.open (); 146 out. get(path);146 out.read (path); 147 147 out.close (); 148 148 if (rld::verbose () >= RLD_VERBOSE_DETAILS) -
linkers/rld-process.cpp
r058d502 ra136346 60 60 namespace process 61 61 { 62 /** 63 * Keep the temporary files if true. Used to help debug a system. 64 */ 65 bool keep_temporary_files = false; 66 67 /** 68 * The temporary files. 69 */ 70 temporary_files temporaries; 71 62 72 temporary_files::temporary_files () 63 73 { … … 70 80 71 81 const std::string 72 temporary_files::get ( )73 { 74 char* temp = ::make_temp_file ( "rldXXXXXX");82 temporary_files::get (const std::string& suffix) 83 { 84 char* temp = ::make_temp_file (suffix.c_str ()); 75 85 76 86 if (!temp) 77 throw rld::error ("bad temp name", " pex");87 throw rld::error ("bad temp name", "temp-file"); 78 88 79 89 std::string name = temp; … … 87 97 temporary_files::unlink (const std::string& name) 88 98 { 89 struct stat sb; 90 if ((::stat (name.c_str (), &sb) >= 0) && S_ISREG (sb.st_mode)) 91 { 92 int r; 99 if (!keep_temporary_files) 100 { 101 struct stat sb; 102 if ((::stat (name.c_str (), &sb) >= 0) && S_ISREG (sb.st_mode)) 103 { 104 int r; 93 105 #if _WIN32 94 r = ::remove(name.c_str ());106 r = ::remove(name.c_str ()); 95 107 #else 96 r = ::unlink (name.c_str ()); 97 #endif 98 if (r < 0) 99 { 100 std::cerr << "error: unlinking temp file: " << name << std::endl; 101 ::exit (100); 108 r = ::unlink (name.c_str ()); 109 #endif 110 if (r < 0) 111 { 112 std::cerr << "error: unlinking temp file: " << name << std::endl; 113 ::exit (100); 114 } 102 115 } 103 116 } … … 131 144 } 132 145 133 tempfile::tempfile () 134 : fd (-1), 146 tempfile::tempfile (const std::string& suffix) 147 : suffix (suffix), 148 fd (-1), 135 149 level (0) 136 150 { 137 _name = temporaries.get ( );151 _name = temporaries.get (suffix); 138 152 } 139 153 … … 145 159 146 160 void 147 tempfile::open ( )161 tempfile::open (bool writable) 148 162 { 149 163 if ((fd < 0) && rld::files::check_file (_name)) 150 164 { 151 165 level = 0; 152 fd = ::open (_name.c_str (), O_RDONLY);166 fd = ::open (_name.c_str (), writable ? O_RDWR : O_RDONLY); 153 167 if (fd < 0) 154 168 throw rld::error (::strerror (errno), "tempfile open:" + _name); … … 187 201 188 202 void 189 tempfile:: get(std::string& all)203 tempfile::read (std::string& all) 190 204 { 191 205 all.clear (); … … 209 223 210 224 void 211 tempfile:: getline (std::string& line)225 tempfile::read_line (std::string& line) 212 226 { 213 227 line.clear (); … … 243 257 244 258 void 259 tempfile::write (const std::string& s) 260 { 261 const char* p = s.c_str (); 262 size_t l = s.length (); 263 while (l) 264 { 265 int written = ::write (fd, p, l); 266 if (written < 0) 267 throw rld::error (::strerror (errno), "tempfile write:" + _name); 268 if (written == 0) 269 break; 270 l -= written; 271 } 272 } 273 274 void 275 tempfile::write_line (const std::string& s) 276 { 277 write (s); 278 write (RLD_LINE_SEPARATOR); 279 } 280 281 void 282 tempfile::write_lines (const rld::strings& ss) 283 { 284 for (rld::strings::const_iterator ssi = ss.begin (); 285 ssi != ss.end (); 286 ++ssi) 287 { 288 write_line (*ssi); 289 } 290 } 291 292 void 245 293 tempfile::output (std::ostream& out) 246 294 { … … 261 309 while (true) 262 310 { 263 getline (line);311 read_line (line); 264 312 ++lc; 265 313 if (line.empty ()) … … 275 323 } 276 324 325 void 326 set_keep_temporary_files () 327 { 328 keep_temporary_files = true; 329 } 330 331 void 332 temporaries_clean_up () 333 { 334 temporaries.clean_up (); 335 } 336 277 337 status 278 338 execute (const std::string& pname, -
linkers/rld-process.h
r058d502 ra136346 1 1 /* 2 * Copyright (c) 2011, Chris Johns <chrisj@rtems.org> 2 * Copyright (c) 2011, Chris Johns <chrisj@rtems.org> 3 3 * 4 4 * Permission to use, copy, modify, and/or distribute this software for any 5 5 * purpose with or without fee is hereby granted, provided that the above 6 6 * copyright notice and this permission notice appear in all copies. 7 * 7 * 8 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF … … 45 45 */ 46 46 typedef std::list < std::string > tempfile_container; 47 47 48 48 /** 49 49 * Construct the temporary files. … … 59 59 * Get a new temporary file name. 60 60 */ 61 const std::string get ( );61 const std::string get (const std::string& suffix = ".rldxx"); 62 62 63 63 /** … … 81 81 82 82 }; 83 84 /**85 * The temporary files.86 */87 static temporary_files temporaries;88 83 89 84 /** … … 97 92 * Get a temporary file name. 98 93 */ 99 tempfile ( );94 tempfile (const std::string& suffix = ".rldxx"); 100 95 101 96 /** … … 105 100 106 101 /** 107 * Open the temporary file. 108 */ 109 void open ( );102 * Open the temporary file. It can optionally be written too. 103 */ 104 void open (bool writable = false); 110 105 111 106 /** … … 125 120 126 121 /** 127 * Get all the file. 128 */ 129 void get (std::string& all); 130 131 /** 132 * Get time. 133 */ 134 void getline (std::string& line); 122 * Read all the file. 123 */ 124 void read (std::string& all); 125 126 /** 127 * Read a line at a time. 128 */ 129 void read_line (std::string& line); 130 131 /** 132 * Write the string to the file. 133 */ 134 void write (const std::string& s); 135 136 /** 137 * Write the string as a line to the file. 138 */ 139 void write_line (const std::string& s); 140 141 /** 142 * Write the strings to the file using a suitable line separator. 143 */ 144 void write_lines (const rld::strings& ss); 135 145 136 146 /** 137 147 * Output the file. 138 148 */ 139 void output (const std::string& prefix, 140 std::ostream& out, 149 void output (const std::string& prefix, 150 std::ostream& out, 141 151 bool line_numbers = false); 142 152 … … 148 158 private: 149 159 150 std::string _name; //< The name of the file. 151 int fd; //< The file descriptor 152 char buf[256]; //< The read buffer. 153 int level; //< The level of data in the buffer. 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. 154 165 }; 155 166 167 /** 168 * Keep the temporary files. 169 */ 170 void set_keep_temporary_files (); 171 172 /** 173 * Clean up the temporaryes. 174 */ 175 void temporaries_clean_up (); 176 156 177 /** 157 178 * The arguments containter has a single argument per element. … … 170 191 stopped //< The process has not terminated, but has stopped and can be restarted. 171 192 }; 172 193 173 194 types type; //< Type of status. 174 195 int code; //< The status code returned. … … 179 200 * the program name to run. Return an error code. 180 201 */ 181 status execute (const std::string& pname, 202 status execute (const std::string& pname, 182 203 const arg_container& args, 183 204 const std::string& outname, … … 188 209 * string. Return an error code. 189 210 */ 190 status execute (const std::string& pname, 211 status execute (const std::string& pname, 191 212 const std::string& command, 192 213 const std::string& outname, -
linkers/rtems-ld.cpp
r058d502 ra136346 133 133 signal (signum, SIG_DFL); 134 134 135 rld::process::temporaries .clean_up ();135 rld::process::temporaries_clean_up (); 136 136 137 137 /* -
linkers/rtems-ra.cpp
r058d502 ra136346 118 118 signal (signum, SIG_DFL); 119 119 120 rld::process::temporaries .clean_up ();120 rld::process::temporaries_clean_up (); 121 121 122 122 /* … … 316 316 */ 317 317 rld::files::find_libraries (libraries, libpaths, libs); 318 318 319 319 /* 320 320 * Are we to load standard libraries ? … … 331 331 rld::symbols::table symbols; 332 332 rld::files::cache* cache = new rld::files::cache (); 333 333 334 334 library.clear (); 335 335 library.push_back (*p); 336 336 337 337 /* 338 338 * Open the cache. 339 339 */ 340 340 cache->open (); 341 341 342 342 /* 343 343 * Load the library to the cache. 344 344 */ 345 345 cache->add_libraries (library); 346 346 347 347 cache->load_symbols (symbols); 348 348 349 349 try 350 350 { 351 351 352 352 rld::files::objects& objs = cache->get_objects (); 353 353 rld::files::paths raobjects; 354 354 355 355 int pos = -1; 356 356 std::string rap_name; … … 360 360 { 361 361 rld::files::object* obj = (*obi).second; 362 362 363 363 dependents.clear (); 364 364 365 365 rap_name = obj->name ().oname (); 366 366 367 367 pos = obj->name ().oname ().rfind ('.', rap_name.length ()); 368 368 if (pos != -1) … … 370 370 rap_name.erase (pos, rap_name.length ()); 371 371 } 372 372 373 373 rap_name += ".rap"; 374 374 375 375 dependents.push_back (obj); 376 376 377 377 raobjects.push_back (rap_name); 378 378 379 379 /* Todo: include absolute name for rap_name */ 380 380 381 381 rld::outputter::application (rap_name, entry, exit, 382 382 dependents, *cache, symbols, 383 383 true); 384 384 } 385 385 386 386 dependents.clear (); 387 387 for (rld::files::paths::iterator ni = raobjects.begin (); ni != raobjects.end (); ++ni) … … 390 390 dependents.push_back (obj); 391 391 } 392 392 393 393 bool ra_rap = true; 394 394 bool ra_exist = false; 395 395 rld::files::cache cachera; 396 396 std::string raname = *p; 397 397 398 398 pos = -1; 399 399 pos = raname.rfind ('/', raname.length ()); … … 402 402 raname.erase (0, pos); 403 403 } 404 404 405 405 pos = -1; 406 406 pos = raname.rfind ('.', raname.length ()); … … 410 410 } 411 411 raname += ".ra"; 412 412 413 413 raname = output_path + raname; 414 414 415 415 rld::outputter::archivera (raname, dependents, cachera, 416 416 ra_exist, ra_rap); 417 417 std::cout << "Generated: " << raname << std::endl; 418 419 418 419 420 420 for (rld::files::object_list::iterator oi = dependents.begin (); 421 421 oi != dependents.end (); … … 431 431 throw; 432 432 } 433 433 434 434 cache->archives_end (); 435 435 delete cache; … … 439 439 { 440 440 /* 441 * Add, replace, delete files from the ra file. 441 * Add, replace, delete files from the ra file. 442 442 */ 443 443 for (rld::files::paths::iterator pl = libs.begin (); pl != libs.end (); ++pl) … … 445 445 rld::files::paths library; 446 446 rld::files::cache* cache = new rld::files::cache (); 447 447 448 448 library.clear (); 449 449 library.push_back (*pl); 450 450 451 451 /* 452 452 * Open the cache. 453 453 */ 454 454 cache->open (); 455 455 456 456 /* 457 457 * Load the library to the cache. 458 458 */ 459 459 cache->add_libraries (library); 460 460 461 461 rld::files::objects& objs = cache->get_objects (); 462 462 rld::files::paths raobjects; 463 463 464 464 std::string rap_name; 465 465 bool rap_delete = false; 466 466 467 467 dependents.clear (); 468 468 /* … … 474 474 { 475 475 rld::files::object* obj = (*obi).second; 476 476 477 477 rap_name = obj->name ().oname (); 478 478 rap_delete = false; 479 479 480 480 for (rld::files::paths::iterator pa = raps_delete.begin (); 481 481 pa != raps_delete.end (); … … 488 488 } 489 489 } 490 490 491 491 if (!rap_delete) 492 492 dependents.push_back (obj); 493 493 } 494 494 495 495 /* 496 496 * Add rap files into ra file, add supports replace. … … 503 503 { 504 504 rap_exist = false; 505 505 506 506 for (rld::files::object_list::iterator oi = dependents.begin (); 507 507 oi != dependents.end (); … … 516 516 } 517 517 } 518 518 519 519 if (!rap_exist) 520 520 rap_objects.push_back (*pa); 521 521 } 522 522 523 523 for (rld::files::paths::iterator pa = rap_objects.begin (); 524 524 pa != rap_objects.end (); … … 533 533 else dependents.push_back (obj); 534 534 } 535 535 536 536 /* 537 537 * Replace rap files in ra file … … 539 539 bool rap_replace = false; 540 540 rld::files::cache cachera; 541 541 542 542 rap_objects.clear (); 543 543 cachera.open (); 544 544 545 545 for (rld::files::paths::iterator pa = raps_replace.begin (); 546 546 pa != raps_replace.end (); … … 548 548 { 549 549 rap_replace = false; 550 550 551 551 for (rld::files::object_list::iterator oi = dependents.begin (); 552 552 oi != dependents.end (); … … 562 562 ++oi; 563 563 } 564 564 565 565 if (rap_replace) 566 566 rap_objects.push_back (*pa); 567 567 } 568 568 569 569 for (rld::files::paths::iterator pa = rap_objects.begin (); 570 570 pa != rap_objects.end (); … … 579 579 else dependents.push_back (obj); 580 580 } 581 581 582 582 rld::outputter::archivera (*pl, dependents, cachera, 583 583 true, true); 584 584 std::cout << "End" << std::endl; 585 585 586 586 cache->archives_end (); 587 587 delete cache; -
linkers/rtems-rapper.cpp
r058d502 ra136346 1112 1112 signal (signum, SIG_DFL); 1113 1113 1114 rld::process::temporaries .clean_up ();1114 rld::process::temporaries_clean_up (); 1115 1115 1116 1116 /* -
linkers/rtems-syms.cpp
r058d502 ra136346 93 93 signal (signum, SIG_DFL); 94 94 95 rld::process::temporaries .clean_up ();95 rld::process::temporaries_clean_up (); 96 96 97 97 /*
Note: See TracChangeset
for help on using the changeset viewer.