From 2e587b33965541575b95d7940c265b3bc5aa2054 Mon Sep 17 00:00:00 2001 From: aditya Chaudhry Date: Mon, 7 Oct 2019 20:31:59 -0400 Subject: [PATCH 1/7] Added function in main.cpp, is_created(), that checks if a given file has been created or not. Using that helper, double check to see if the executable is in the current directory, if not then rebuild --- main.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index c385b8c..a5459ae 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,6 @@ #include #include #include -#include using namespace std; const int MAX_PROCESSES = 4; @@ -92,12 +91,23 @@ void link_executable(const Buildfile& buildfile, const vector& cpp_files } } +bool is_created(const string filename){ + + // tests for the existence of the file with success being a 0 + if(access(filename.c_str(), F_OK) == 0) + { + return true; + } + return false; +} + int main() { /* * 1) get the cpp files - * 2) determine what cpp files to recompile + * 2) determine what files to recompile * - need to recompile if no obj file we have to create it, or if there is an obj file, * but the cpp file has been modified more recently than the obj file + * - need to check to see if there is an executable created * 3) if none, we are done * 4) else, recompile them (done!) * 5) relink everything @@ -111,8 +121,8 @@ int main() { if (has_changed(file)) changed.push_back(file); } - //now we know what cpp files have changed - if (changed.empty()) //TODO: also ensure exe exists + // if there is nothing to reompile and the executable has been created we are done + if (changed.empty() && is_created(Buildfile.executable)) return 0; //3 compile_object_files(buildfile, changed); //4 From 87e8ac1f0013d548ab38074b1836c0e69b1fe924 Mon Sep 17 00:00:00 2001 From: aditya Chaudhry Date: Mon, 7 Oct 2019 20:52:31 -0400 Subject: [PATCH 2/7] adding back a bad removal of an include --- main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/main.cpp b/main.cpp index a5459ae..f706993 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include using namespace std; const int MAX_PROCESSES = 4; From 819dbeda4683e26a9d0d47e6b1ef1ff47ff342fb Mon Sep 17 00:00:00 2001 From: aditya Chaudhry Date: Sun, 20 Oct 2019 12:24:10 -0400 Subject: [PATCH 3/7] fixed 2 small bugs: typo in comment and passing a string by reference to is_created --- main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index f706993..4aac9d5 100644 --- a/main.cpp +++ b/main.cpp @@ -92,7 +92,7 @@ void link_executable(const Buildfile& buildfile, const vector& cpp_files } } -bool is_created(const string filename){ +bool is_created(const string &filename){ // tests for the existence of the file with success being a 0 if(access(filename.c_str(), F_OK) == 0) @@ -105,7 +105,7 @@ bool is_created(const string filename){ int main() { /* * 1) get the cpp files - * 2) determine what files to recompile + * 2) determine what cpp files to recompile * - need to recompile if no obj file we have to create it, or if there is an obj file, * but the cpp file has been modified more recently than the obj file * - need to check to see if there is an executable created @@ -122,7 +122,7 @@ int main() { if (has_changed(file)) changed.push_back(file); } - // if there is nothing to reompile and the executable has been created we are done + // if there is nothing to recompile and the executable has been created we are done if (changed.empty() && is_created(Buildfile.executable)) return 0; //3 From dcb9762cf3175a790cec0c660a3038fa3fd472fa Mon Sep 17 00:00:00 2001 From: aditya Chaudhry Date: Sun, 20 Oct 2019 13:58:17 -0400 Subject: [PATCH 4/7] added commandline parsing and preliminary help message --- main.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index 4aac9d5..b05749c 100644 --- a/main.cpp +++ b/main.cpp @@ -4,11 +4,26 @@ #include #include #include +#include using namespace std; const int MAX_PROCESSES = 4; const char* const COMPILER = "g++"; +const string help= "\n\ +KTPuild\n\ + An application to help making the compiling of large projects easier. The\n\ + intended use for EECS 280 and 281 students attending the University of \n\ + Michigan. Built and maintained by Kappa Theta Pi Alpha Chapter. For reporting\n\ + bugs or requesting features please visit: https://github.com/ktp-dev/KTPuild\n\ + \n\ +Usages:\n\ + KTPuild\n\ + KTPuild -h | --help\n\ + \n\ +Options:\n\ + -h | --help: display help information\n\n"; + void run_command(const vector& command) { //To run a command, we have to call execvp. execvp expects a char** (C style array) that is null terminated. Thus, convert our nice C++ array of strings to a C array of C strings. Also, print them out so the user knows what we are running. @@ -102,19 +117,45 @@ bool is_created(const string &filename){ return false; } -int main() { +void parse_commandline_args(int argc, char** &argv) +{ + struct option longOpts[] = { + { "help", no_argument, nullptr, 'h' }, + { nullptr, 0, nullptr, '\0' } + }; + + int option, optionIndex; + + while((option = getopt_long(argc, argv, "h", longOpts, &optionIndex))!= -1) + { + switch(option) + { + case 'h':{ + + cout< cpp_filename = buildfile.get_cpp_files(); //1 vector changed; @@ -123,7 +164,7 @@ int main() { changed.push_back(file); } // if there is nothing to recompile and the executable has been created we are done - if (changed.empty() && is_created(Buildfile.executable)) + if (changed.empty() && is_created(buildfile.get_executable_name())) return 0; //3 compile_object_files(buildfile, changed); //4 From 1b2841e81aa73202e857b461738944942c663948 Mon Sep 17 00:00:00 2001 From: aditya Chaudhry Date: Sun, 20 Oct 2019 14:19:15 -0400 Subject: [PATCH 5/7] added error checking for bad usage in commandline args --- main.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index b05749c..3abff32 100644 --- a/main.cpp +++ b/main.cpp @@ -5,18 +5,20 @@ #include #include #include +#include using namespace std; const int MAX_PROCESSES = 4; const char* const COMPILER = "g++"; -const string help= "\n\ +const string help_header = "\ KTPuild\n\ An application to help making the compiling of large projects easier. The\n\ intended use for EECS 280 and 281 students attending the University of \n\ Michigan. Built and maintained by Kappa Theta Pi Alpha Chapter. For reporting\n\ - bugs or requesting features please visit: https://github.com/ktp-dev/KTPuild\n\ - \n\ + bugs or requesting features please visit: https://github.com/ktp-dev/KTPuild\n"; + +const string help_msg = "\n\ Usages:\n\ KTPuild\n\ KTPuild -h | --help\n\ @@ -117,7 +119,7 @@ bool is_created(const string &filename){ return false; } -void parse_commandline_args(int argc, char** &argv) +bool parse_commandline_args(int argc, char** &argv) { struct option longOpts[] = { { "help", no_argument, nullptr, 'h' }, @@ -130,15 +132,20 @@ void parse_commandline_args(int argc, char** &argv) { switch(option) { - case 'h':{ - - cout< cpp_filename = buildfile.get_cpp_files(); //1 vector changed; From d9fb6437b35522dbc4cf0138a1c7773756cf10de Mon Sep 17 00:00:00 2001 From: aditya Chaudhry Date: Mon, 28 Oct 2019 19:54:47 -0400 Subject: [PATCH 6/7] Change from string to char * and throwing an error when unknown flag is thrown --- main.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index 3abff32..8f317dc 100644 --- a/main.cpp +++ b/main.cpp @@ -13,8 +13,8 @@ const char* const COMPILER = "g++"; const string help_header = "\ KTPuild\n\ - An application to help making the compiling of large projects easier. The\n\ - intended use for EECS 280 and 281 students attending the University of \n\ + An application that makes the compiling of large projects easier. The\n\ + intended use for EECS 280 students attending the University of \n\ Michigan. Built and maintained by Kappa Theta Pi Alpha Chapter. For reporting\n\ bugs or requesting features please visit: https://github.com/ktp-dev/KTPuild\n"; @@ -134,14 +134,12 @@ bool parse_commandline_args(int argc, char** &argv) { case 'h': { - cout< Date: Mon, 28 Oct 2019 20:07:31 -0400 Subject: [PATCH 7/7] remove optionsIndex --- main.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 8f317dc..ce2300a 100644 --- a/main.cpp +++ b/main.cpp @@ -126,9 +126,9 @@ bool parse_commandline_args(int argc, char** &argv) { nullptr, 0, nullptr, '\0' } }; - int option, optionIndex; + int option; - while((option = getopt_long(argc, argv, "h", longOpts, &optionIndex))!= -1) + while((option = getopt_long(argc, argv, "h", longOpts, nullptr))!= -1) { switch(option) { @@ -181,6 +181,21 @@ int main(int argc, char ** argv) { if (changed.empty() && is_created(buildfile.get_executable_name())) return 0; //3 +int main() +{ + +} + +int main() +{ + +} + +int main() +{ + +} + compile_object_files(buildfile, changed); //4 link_executable(buildfile, cpp_filename); //4