diff -r 000000000000 -r 509e4801c378 srcanamdw/appdep/src/appdep_otherfunc.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/srcanamdw/appdep/src/appdep_otherfunc.cpp Sat Jan 09 10:04:12 2010 +0530 @@ -0,0 +1,708 @@ +/* +* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Other non-categorized AppDep functionality +* +*/ + + +#include "appdep.hpp" + +// ---------------------------------------------------------------------------------------------------------- + +void ParseCommandLineParameters(int argc, char* argv[]) +{ + // loop through the command line parameters and check their usage + int i=1; + while (i 0) + _targets.push_back(new_target); + + last_found_plus_pos = plus_pos; + i = last_found_plus_pos; + } + } + + // set more values of targets vector + for (unsigned int i=0; i<_targets.size(); i++) + { + // set path where release the release can be found, eg z:\epoc32\release\armv5\ . + _targets.at(i).release_dir = _cl_releasedir + EPOC32_RELEASE + _targets.at(i).name + DIR_SEPARATOR; + + // set path where the import libraries of the release can be found, eg z:\epoc32\release\armv5\lib\ . + string lib_dir; + if (_cl_use_gcce || _cl_use_rvct) + lib_dir = "lib"; // lib dir used in Symbian OS 9.x + else + lib_dir = _target_mode; + + _targets.at(i).release_lib_dir = _targets.at(i).release_dir + lib_dir + DIR_SEPARATOR; + + // set path where the binaries of the release can be found, eg z:\epoc32\release\armv5\urel\ . + _targets.at(i).release_bin_dir = _targets.at(i).release_dir + _target_mode + DIR_SEPARATOR; + + // set location of the cache files of this target, eg z:\caches\armv5\urel\xxx.txt + _targets.at(i).cache_dir = _cl_cachedir + _targets.at(i).name + DIR_SEPARATOR + _target_mode + DIR_SEPARATOR; + _targets.at(i).st_cache_path = _targets.at(i).cache_dir + CACHE_ST_FILENAME; + _targets.at(i).dep_cache_path = _targets.at(i).cache_dir + CACHE_DEP_FILENAME; + + // check if those cache files exists + _targets.at(i).cache_files_valid = FileExists(_targets.at(i).st_cache_path) && FileExists(_targets.at(i).dep_cache_path); + } +} + +// ---------------------------------------------------------------------------------------------------------- + +void DoCacheGenerationChecksAndPreparations() +{ + if (!_cl_use_gcc && !_cl_use_gcce && !_cl_use_rvct) + { + cerr << "ERROR: No tool chain defined!" << endl; + cerr << "Type appdep -? for help" << endl; + exit(EXIT_WRONG_USAGE); + } + + if (_cl_use_rvct && _cl_cfiltloc.empty()) + { + cerr << "ERROR: Specify -cfilt when RVCT is defined!" << endl; + cerr << "Type appdep -? for help" << endl; + exit(EXIT_WRONG_USAGE); + } + + if ( (_cl_use_gcc && (_cl_use_gcce || _cl_use_rvct)) || (_cl_use_gcce && (_cl_use_gcc || _cl_use_rvct)) || + (_cl_use_rvct && (_cl_use_gcc || _cl_use_gcce)) ) + { + cerr << "ERROR: Specify only one tool chain!" << endl; + cerr << "Type appdep -? for help" << endl; + exit(EXIT_WRONG_USAGE); + } + + // make sure the vectors are empty when generating clean cache + if (_cl_generate_clean_cache) + { + for (unsigned int i=0; i<_targets.size(); i++) // loop each target + { + _targets.at(i).import_libraries.clear(); + _targets.at(i).binaries.clear(); + } + } + + // if tools parameter is empty, try get it from path, otherwise check given parameter + if (_cl_toolsdir.empty()) + { + GetToolsPathFromEnvironmentVariable(); + } + else + { + // check the given tools directory parameter is valid + if (_cl_use_gcc) + { + _gcc_nm_location = _cl_toolsdir + GCC_NM_EXE; + + if (!FileExists(_gcc_nm_location)) + { + cerr << "ERROR: Unable to find " + _gcc_nm_location << ", check -tools parameter" << endl; + cerr << "Tip: GCC is typically installed to \\epoc32\\gcc\\bin directory" << endl; + exit(EXIT_TOOLCHAIN_NOT_FOUND); + } + + // extra quotes needed to prevent white space problems while executing the tool + InsertQuotesToFilePath(_gcc_nm_location); + } + + else if (_cl_use_gcce) + { + _gcce_nm_location = _cl_toolsdir + GCCE_NM_EXE; + _gcce_readelf_location = _cl_toolsdir + GCCE_READELF_EXE; + _gcce_cfilt_location = _cl_toolsdir + GCCE_CFILT_EXE; + + if (!FileExists(_gcce_nm_location)) + { + cerr << "ERROR: Unable to find " + _gcce_nm_location << ", check -tools param" << endl; + cerr << "Tip: GCCE is typically installed to C:\\Program Files\\CSL Arm Toolchain\\bin" << endl; + exit(EXIT_TOOLCHAIN_NOT_FOUND); + } + + if (!FileExists(_gcce_readelf_location)) + { + cerr << "ERROR: Unable to find " + _gcce_readelf_location << ", check -tools param" << endl; + cerr << "Tip: GCCE is typically installed to C:\\Program Files\\CSL Arm Toolchain\\bin" << endl; + exit(EXIT_TOOLCHAIN_NOT_FOUND); + } + + if (!FileExists(_gcce_cfilt_location)) + { + cerr << "ERROR: Unable to find " + _gcce_cfilt_location << ", check -tools param" << endl; + cerr << "Tip: GCCE is typically installed to C:\\Program Files\\CSL Arm Toolchain\\bin" << endl; + exit(EXIT_TOOLCHAIN_NOT_FOUND); + } + + // extra quotes needed to prevent white space problems while executing the tool + InsertQuotesToFilePath(_gcce_nm_location); + InsertQuotesToFilePath(_gcce_readelf_location); + InsertQuotesToFilePath(_gcce_cfilt_location); + + } + + else if (_cl_use_rvct) + { + _rvct_armar_location = _cl_toolsdir + RVCT_ARMAR_EXE; + _rvct_fromelf_location = _cl_toolsdir + RVCT_FROMELF_EXE; + + if (!FileExists(_rvct_armar_location)) + { + cerr << "ERROR: Unable to find " + _rvct_armar_location << ", check -tools param" << endl; + cerr << "Tip: Check your environment variables to see the directory where RVCT has been installed" << endl; + exit(EXIT_TOOLCHAIN_NOT_FOUND); + } + + if (!FileExists(_rvct_fromelf_location)) + { + cerr << "ERROR: Unable to find " + _rvct_fromelf_location << ", check -tools param" << endl; + cerr << "Tip: Check your environment variables to see the directory where RVCT has been installed" << endl; + exit(EXIT_TOOLCHAIN_NOT_FOUND); + } + + // extra quotes needed to prevent white space problems while executing the tool + InsertQuotesToFilePath(_rvct_armar_location); + InsertQuotesToFilePath(_rvct_fromelf_location); + } + } // else of if (!cl_toolsdir) + + + // check path of RVCT's cfilt is correct + if (_cl_use_rvct) + { + _rvct_cfilt_location = _cl_cfiltloc; + + if (!FileExists(_rvct_cfilt_location)) + { + cerr << "ERROR: Unable to find " + _rvct_cfilt_location << ", check -cfilt param" << endl; + cerr << "Tip: Working cfilt.exe can be found from the same directory where appdep has been installed" << endl; + exit(EXIT_CFILT_NOT_FOUND); + } + + // extra quotes needed to prevent white space problems while executing the tool + InsertQuotesToFilePath(_rvct_cfilt_location); + } + + + // check Petran can be found + SetAndCheckPetranPath(); + + // loop all targets + for (unsigned int i=0; i<_targets.size(); i++) + { + // check directories for given targets are valid + if (!DirectoryExists(_targets.at(i).release_dir)) + { + cerr << "ERROR: Directory " << _targets.at(i).release_dir << " not found!" << endl; + cerr << "Please check that -targets parameter is valid and you have a full release environment" << endl; + exit(EXIT_TARGETDIR_NOT_FOUND); + } + else + { + //cerr << "NOTE: " << targets.at(i) << " is a valid target in your release" << endl; + } + + // make sure that the cache directory exists + MkDirAll(_targets.at(i).cache_dir); + } + + // check that it is possible to create the temporary file under the cache directory + _tempfile_location = _cl_cachedir + TEMP_FILENAME; + ofstream tempf(_tempfile_location.c_str(), ios::trunc); + if (!tempf.is_open()) + { + tempf.close(); + cerr << "ERROR: Cannot open " << _tempfile_location << " for writing!" << endl; + cerr << "Please check that the directory exists and there are no write permission problems" << endl; + exit(EXIT_CANNOT_WRITE_TO_TEMP_FILE); + } + else + tempf.close(); + +} + +// ---------------------------------------------------------------------------------------------------------- + +void GetToolsPathFromEnvironmentVariable() +{ + #ifdef WIN32 + // get path environment variable + const char* env_path = getenv("PATH"); + + if (env_path != NULL) + { + string env_path_str = env_path; + + string::size_type previous_delimpos = 0; + bool match_found(false); + string test_path; + + for (unsigned int i=0; i5000) + break; // something went wrong.. + } + + if (!match_found) + { + cerr << "ERROR: Cannot find specified compiler toolset from PATH environment" << endl; + cerr << "Fix PATH environment variable or specify -tools parameter" << endl; + exit(EXIT_TOOLCHAIN_NOT_FOUND_FROM_PATH); + } + + } + else + { + cerr << "ERROR: PATH environment variable not available, please specify -tools parameter" << endl; + exit(EXIT_PATH_VARIABLE_NOT_FOUND); + } + + #else + + cerr << "ERROR: Optional -tools parameter is only supported in Windows environment " << endl; + exit(EXIT_ONLY_SUPPORTED_IN_WIN32); + + #endif + +} + +// ---------------------------------------------------------------------------------------------------------- + +void FindImportLibrariesAndBinariesFromReleases() +{ + // check if analysing .dso or .lib files + string lib_filter; + if (_cl_use_gcc || _cl_use_libs) // for GCC use always .lib files + lib_filter = "*.lib"; + else + lib_filter = "*.dso"; + + for (unsigned int i=0; i<_targets.size(); i++) // loop each target + { + // get import libraries + GetFileNamesFromDirectory(_targets.at(i).release_lib_dir, lib_filter, _targets.at(i).lib_files); + _max_progress += _targets.at(i).lib_files.size(); + + // get binaries + GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.app", _targets.at(i).bin_files); + GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.exe", _targets.at(i).bin_files); + GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.dll", _targets.at(i).bin_files); + GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.prt", _targets.at(i).bin_files); + GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.?sy", _targets.at(i).bin_files); + GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.fep", _targets.at(i).bin_files); + GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.agt", _targets.at(i).bin_files); + GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.fxt", _targets.at(i).bin_files); + + // increase the value of total number of files + _max_progress += _targets.at(i).bin_files.size(); + } +} + +// ---------------------------------------------------------------------------------------------------------- + +void GetFileNamesFromDirectory(const string& directory, const string& filter, vector& resultset) +{ + // get list of files from the directory by executing OS specific dir/ls command + string dir_command = DIR_COMMAND; + string cmd = dir_command + " \"" + directory + "\"" + filter + " " + CERR_TO_NULL; + + vector tempVector; + ExecuteCommand(cmd, tempVector); + + // loop through all returned files + for (unsigned int i=0; i