mirror of
https://github.com/nasa/trick.git
synced 2024-12-20 05:37:55 +00:00
Move search for library dependencies to make_makefile
Moved the search for all library dependencies into make_makefile. Made a couple of minor clean up edits as well. refs #92
This commit is contained in:
parent
fc9c604056
commit
a5929dbe6c
@ -13,8 +13,8 @@ use get_lib_deps ;
|
||||
my %processed_files ;
|
||||
my %non_lib_processed_files ;
|
||||
|
||||
sub read_lib_deps(@) {
|
||||
my (@files_to_process) = @_ ;
|
||||
sub read_lib_deps($@) {
|
||||
my ($indent , @files_to_process) = @_ ;
|
||||
foreach my $l ( @files_to_process ) {
|
||||
next if ( $l eq "" ) ;
|
||||
if ( ! exists $processed_files{$l} ) {
|
||||
@ -28,20 +28,21 @@ sub read_lib_deps(@) {
|
||||
my (@all_lines) = <FH> ;
|
||||
close FH ;
|
||||
chomp @all_lines ;
|
||||
read_lib_deps(@all_lines) ;
|
||||
read_lib_deps($indent + 1 , @all_lines) ;
|
||||
} else {
|
||||
print "Getting Dependencies for $l\n" ;
|
||||
print "Getting Dependencies for " , " " x $indent, "$l\n" ;
|
||||
if ( -e $l ) {
|
||||
my $contents ;
|
||||
my @resolved_files ;
|
||||
@resolved_files = write_lib_deps($l) ;
|
||||
read_lib_deps(@resolved_files) ;
|
||||
read_lib_deps($indent + 1 , @resolved_files) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Update out of date lib_dep files
|
||||
for my $f ( @ARGV ) {
|
||||
# Makefile_io_src is listed as a dependency of make_makefile_src and comes in as
|
||||
# an argument from make. Ignore it.
|
||||
@ -51,21 +52,19 @@ for my $f ( @ARGV ) {
|
||||
}
|
||||
}
|
||||
|
||||
open FILE, "build/ICG_lib_deps" or die 'cannot open build/header_lib_deps' ;
|
||||
my (@top_lib_dep_file_names) = <FILE> ;
|
||||
# Start the top level files which are all of the header files and S_define
|
||||
open FILE, "build/ICG_processed" or die 'cannot open build/ICG_processed' ;
|
||||
my (@top_file_names) = <FILE> ;
|
||||
close FILE ;
|
||||
chomp @top_lib_dep_file_names ;
|
||||
push @top_lib_dep_file_names, "build/S_define.lib_deps" ;
|
||||
open FILE, "build/S_define.lib_deps" or die 'cannot open build/S_define.lib_deps' ;
|
||||
my (@s_define_lib_deps) = <FILE> ;
|
||||
close FILE ;
|
||||
push @top_file_names , @s_define_lib_deps ;
|
||||
chomp @top_file_names ;
|
||||
|
||||
foreach my $f ( @top_lib_dep_file_names ) {
|
||||
my @all_lines ;
|
||||
next if ( $f eq "" ) ;
|
||||
open FH, "$f" or die "cannot open $f" ;
|
||||
@all_lines = <FH> ;
|
||||
close FH ;
|
||||
chomp @all_lines ;
|
||||
read_lib_deps(@all_lines) ;
|
||||
}
|
||||
# Read in all of the lib_dep files.
|
||||
# read_lib_deps wil create lib_dep files that don't exist and read them in too.
|
||||
read_lib_deps(0, @top_file_names) ;
|
||||
|
||||
#print map {"$_\n"} (sort keys %processed_files) ;
|
||||
|
||||
@ -364,19 +363,17 @@ foreach ( @all_read_only_libs ) {
|
||||
}
|
||||
|
||||
print MAKEFILE "\n\n
|
||||
test: TRICK_SYSTEM_CXXFLAGS += -DTRICK_UNIT_TEST
|
||||
test: TRICK_SYSTEM_CFLAGS += -DTRICK_UNIT_TEST
|
||||
|
||||
all: S_main
|
||||
|
||||
test: all
|
||||
test: TRICK_SYSTEM_CXXFLAGS += -DTRICK_UNIT_TEST
|
||||
test: TRICK_SYSTEM_CFLAGS += -DTRICK_UNIT_TEST
|
||||
|
||||
S_main : \$(S_MAIN) build/S_define.deps S_sie.resource
|
||||
\t@ echo \"\"
|
||||
\t@ echo \"[32m=== Simulation make complete ===[00m\"
|
||||
|
||||
#\t\t\$(S_OBJECT_FILES) build/lib/*.o
|
||||
|
||||
\$(S_MAIN): \${TRICK_STATIC_LIB} \$(OBJECTS) \$(S_OBJECT_FILES)
|
||||
\t\$(PRINT_EXE_LINK)
|
||||
\t\$(ECHO_CMD)\$(TRICK_LD) \$(TRICK_LDFLAGS) -o \$@ \\
|
||||
@ -398,19 +395,13 @@ S_main : \$(S_MAIN) build/S_define.deps S_sie.resource
|
||||
|
||||
build/S_define.deps:
|
||||
\t\$(PRINT_S_DEF_DEPS)
|
||||
\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_SFLAGS) \$(TRICK_SYSTEM_SFLAGS) -M -MT Makefile_sim -MF build/S_define.deps -x c++ S_define
|
||||
|
||||
\$(CURDIR)/build/S_source.cpp S_default.dat: S_define
|
||||
\t\$(PERL) \${TRICK_HOME}/bin/trick-CP -s -d
|
||||
\t\$(ECHO_CMD)\$(TRICK_CPPC) \$(TRICK_SFLAGS) \$(TRICK_SYSTEM_SFLAGS) -M -MT S_source.hh -MF build/S_define.deps -x c++ S_define
|
||||
|
||||
sie: S_sie.resource
|
||||
|
||||
S_sie.resource: \$(S_MAIN)
|
||||
\t@ echo \"[34mGenerating S_sie.resource...[0m\"
|
||||
\t\$(ECHO_CMD)\$(S_MAIN) sie
|
||||
|
||||
S_define_exp:
|
||||
\t\$(TRICK_CC) -E -C -xc++ \${TRICK_SFLAGS} \$(TRICK_SYSTEM_SFLAGS) S_define > \$@\n\n" ;
|
||||
\t\$(ECHO_CMD)\$(S_MAIN) sie\n\n" ;
|
||||
|
||||
# write out the override files we have read in
|
||||
foreach $k ( sort keys %files_by_dir ) {
|
||||
@ -425,6 +416,7 @@ print MAKEFILE "include build/Makefile_swig\n" ;
|
||||
print MAKEFILE "-include S_overrides.mk\n" ;
|
||||
close MAKEFILE ;
|
||||
|
||||
# write out all of partial linked objects to link_objs that is read in during final linking
|
||||
open LINKOBJS, ">build/link_objs" or die "Could not open build/link_objs" ;
|
||||
foreach $k ( sort keys %files_by_dir ) {
|
||||
foreach my $ext ( qw{ c C cc cxx cpp c++ l y} ) {
|
||||
|
@ -89,7 +89,7 @@ sub get_lib_deps ($$) {
|
||||
}
|
||||
|
||||
if ( $found == 0 ) {
|
||||
print STDERR "[33m$source_file_name: Warning: Could not find dependency $l[0m\n" ;
|
||||
print STDERR "[33mWarning: Could not find dependency $l[0m\n" ;
|
||||
}
|
||||
}
|
||||
return (sort keys %resolved_files) ;
|
||||
|
@ -210,7 +210,7 @@ sub parse_s_define ($) {
|
||||
my $cmd;
|
||||
|
||||
$cmd = "$CC -C -E -xc $ENV{TRICK_SFLAGS} $ENV{TRICK_SYSTEM_SFLAGS} $s_define_file";
|
||||
print "$cmd\n" ;
|
||||
#print "$cmd\n" ;
|
||||
|
||||
@preprocess_output = `$cmd`;
|
||||
|
||||
|
@ -84,15 +84,17 @@ convert_swig:
|
||||
$(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS}
|
||||
@ touch $(CURDIR)/build/convert_swig_last_run
|
||||
|
||||
S_define_exp:
|
||||
$(TRICK_CC) -E -C -xc++ ${TRICK_SFLAGS} $(TRICK_SYSTEM_SFLAGS) S_define > $@
|
||||
|
||||
# Pass these options
|
||||
sie S_define_exp:
|
||||
sie:
|
||||
@if [ -f build/Makefile_src ] ; then $(MAKE) --no-print-directory -f build/Makefile_src $@ ; else echo "No build/Makefile_src found" ; fi
|
||||
|
||||
help:
|
||||
@ echo -e "\
|
||||
Simulation make options:\n\
|
||||
make [debug] [TRICK_VERBOSE_BUILD=1] - Makes everything: S_main and S_sie.resource\n\
|
||||
make model_dirs - Lists model directories use to build simulation\n\
|
||||
make sie - Builds the S_sie.resource file.\n\
|
||||
make clean - Removes all object files in simulation directory\n\
|
||||
make spotless - Performs a clean\n\
|
||||
|
@ -32,7 +32,7 @@ class ballSimObject : public Trick::SimObject {
|
||||
("integration") trick_ret = obj.state_integ() ;
|
||||
|
||||
{BLUE} (10.0, "scheduled") trick_ret = obj.state_print() ;
|
||||
{BLUE} (1.0, "freeze_scheduled") trick_ret = obj.state_print() ;
|
||||
{BLUE} (10.0, "freeze_scheduled") trick_ret = obj.state_print() ;
|
||||
|
||||
("shutdown") obj.shutdown() ;
|
||||
}
|
||||
|
@ -196,68 +196,3 @@ std::set< std::string > CommentSaver::getIgnoreTypes( std::string file_name ) {
|
||||
return ignore_types ;
|
||||
}
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
/*
|
||||
As of right now I call a perl script to parse the header comment and return
|
||||
the library dependencies because perl is awesome!
|
||||
TODO: Someday when C++11 is working on all the platforms we support we should
|
||||
rewrite this using the language built in regular expressions.
|
||||
TODO: Only fork and exec a single instance of the script.
|
||||
*/
|
||||
|
||||
std::vector< std::string > CommentSaver::getLibraryDependencies( std::string file_name ) {
|
||||
|
||||
pid_t pid ;
|
||||
int pipes[4] ;
|
||||
|
||||
// Open two pipes to allow us to write to and read from child process.
|
||||
pipe(&pipes[0]) ;
|
||||
pipe(&pipes[2]) ;
|
||||
if (( pid = fork()) == 0 ) {
|
||||
// child pipes: read = pipe[2], write = pipe[1]
|
||||
close(pipes[0]) ;
|
||||
close(pipes[3]) ;
|
||||
dup2(pipes[2], STDIN_FILENO) ;
|
||||
dup2(pipes[1], STDOUT_FILENO) ;
|
||||
|
||||
// exec the perl script that parses header comments.
|
||||
std::string parse_lib_deps_path = std::string(getenv("TRICK_HOME")) + "/libexec/trick/ICG_lib_deps_helper" ;
|
||||
execl(parse_lib_deps_path.c_str(), parse_lib_deps_path.c_str(), file_name.c_str(), (char *)NULL) ;
|
||||
exit(1) ;
|
||||
}
|
||||
// parent pipes: read = pipe[0], write = pipe[3]
|
||||
close(pipes[1]) ;
|
||||
close(pipes[2]) ;
|
||||
|
||||
// get the header comment and send it with a end delimiter to the perl script
|
||||
std::string header = getTrickHeaderComment(file_name) + "\nEND ICG PROCESSING\n" ;
|
||||
write(pipes[3], header.c_str() , header.size()) ;
|
||||
|
||||
// wait for the child process to end
|
||||
int status ;
|
||||
waitpid(pid, &status, 0) ;
|
||||
|
||||
// read the result from the perl script
|
||||
int num_read ;
|
||||
char buf[4096] ;
|
||||
std::string response ;
|
||||
while (( num_read = read(pipes[0], buf, sizeof(buf) - 1) ) > 0 ) {
|
||||
buf[num_read] = 0 ;
|
||||
response += buf ;
|
||||
}
|
||||
|
||||
// parse the single string result into a vector of strings.
|
||||
std::vector< std::string > lib_deps ;
|
||||
std::string::size_type pos = 0;
|
||||
std::string::size_type prev = 0;
|
||||
while ((pos = response.find("\n", prev)) != std::string::npos)
|
||||
{
|
||||
lib_deps.push_back(response.substr(prev, pos - prev));
|
||||
prev = pos + 1;
|
||||
}
|
||||
lib_deps.push_back(response.substr(prev));
|
||||
|
||||
return lib_deps ;
|
||||
}
|
||||
|
@ -77,12 +77,6 @@ class CommentSaver : public clang::CommentHandler {
|
||||
*/
|
||||
std::set< std::string > getIgnoreTypes( std::string file_name ) ;
|
||||
|
||||
/** Returns a vector of library dependencies from the Trick comment
|
||||
@param file_name = File name to search
|
||||
@return vector of library dependency strings
|
||||
*/
|
||||
std::vector< std::string > getLibraryDependencies( std::string file_name ) ;
|
||||
|
||||
private:
|
||||
/** The compiler's source manager. Holds file/line info for everything. */
|
||||
clang::CompilerInstance & ci ;
|
||||
|
@ -512,56 +512,6 @@ void PrintAttributes::printIOMakefile() {
|
||||
ext_lib.close() ;
|
||||
}
|
||||
|
||||
void PrintAttributes::printHeaderLibraryDependencies() {
|
||||
std::ofstream header_lib_deps ;
|
||||
|
||||
std::cout << "[34mSearching header files for Library Dependencies[0m" << std::endl ;
|
||||
header_lib_deps.open("build/ICG_lib_deps") ;
|
||||
std::map< std::string , std::string >::iterator mit ;
|
||||
for ( mit = all_io_files.begin() ; mit != all_io_files.end() ; mit++ ) {
|
||||
size_t found ;
|
||||
found = (*mit).first.find_last_of(".") ;
|
||||
std::string lib_dep_file = std::string("build") + (*mit).first.substr(0,found) + ".lib_deps" ;
|
||||
header_lib_deps << lib_dep_file << std::endl ;
|
||||
if ( out_of_date_io_files.find((*mit).first) != out_of_date_io_files.end()) {
|
||||
std::ofstream file_list ;
|
||||
file_list.open(lib_dep_file) ;
|
||||
std::vector< std::string > lib_deps = cs.getLibraryDependencies((*mit).first) ;
|
||||
std::vector< std::string >::iterator vit ;
|
||||
for ( vit = lib_deps.begin() ; vit != lib_deps.end() ; vit++ ) {
|
||||
file_list << *vit << std::endl ;
|
||||
}
|
||||
file_list.close() ;
|
||||
}
|
||||
}
|
||||
|
||||
std::set< std::string >::iterator sit ;
|
||||
for ( sit = empty_header_files.begin() ; sit != empty_header_files.end() ; sit++ ) {
|
||||
size_t found ;
|
||||
found = (*sit).find_last_of(".") ;
|
||||
std::string lib_dep_file = std::string("build") + (*sit).substr(0,found) + ".lib_deps" ;
|
||||
|
||||
char * tmp_str = strdup(lib_dep_file.c_str()) ;
|
||||
char * dir_name = dirname(tmp_str) ;
|
||||
_mkdir(dir_name) ;
|
||||
free(tmp_str) ;
|
||||
|
||||
std::vector< std::string > lib_deps = cs.getLibraryDependencies((*sit)) ;
|
||||
std::vector< std::string >::iterator vit ;
|
||||
if ( lib_deps.size() > 0 ) {
|
||||
header_lib_deps << lib_dep_file << std::endl ;
|
||||
std::ofstream file_list ;
|
||||
file_list.open(lib_dep_file) ;
|
||||
for ( vit = lib_deps.begin() ; vit != lib_deps.end() ; vit++ ) {
|
||||
file_list << *vit << std::endl ;
|
||||
}
|
||||
file_list.close() ;
|
||||
}
|
||||
}
|
||||
|
||||
header_lib_deps.close() ;
|
||||
}
|
||||
|
||||
void PrintAttributes::printICGNoFiles() {
|
||||
if ( ! sim_services_flag ) {
|
||||
std::vector< std::string >::iterator it ;
|
||||
|
@ -45,9 +45,6 @@ class PrintAttributes {
|
||||
/** Create makefile for IO files */
|
||||
virtual void printIOMakefile() ;
|
||||
|
||||
/** Print header library dependencies */
|
||||
virtual void printHeaderLibraryDependencies() ;
|
||||
|
||||
/** Prints list of files that contain ICG:(No) in the Trick header */
|
||||
virtual void printICGNoFiles() ;
|
||||
|
||||
|
@ -191,7 +191,6 @@ int main( int argc , char * argv[] ) {
|
||||
|
||||
if ( ! sim_services_flag ) {
|
||||
pa.printIOMakefile() ;
|
||||
pa.printHeaderLibraryDependencies() ;
|
||||
}
|
||||
|
||||
// Close the map files
|
||||
|
Loading…
Reference in New Issue
Block a user