From cbd6aa3384ec270e08c437db0a38a415f9771f87 Mon Sep 17 00:00:00 2001 From: "John S. Urban" Date: Fri, 30 Jul 2021 13:51:43 -0400 Subject: [PATCH 1/3] git-specific, but not git-dependent but is it better if managed directly by fpm --- src/fpm.f90 | 7 ++++++- src/fpm/cmd/new.f90 | 3 --- src/fpm/cmd/update.f90 | 3 ++- src/fpm_command_line.f90 | 7 ++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index 89eca1a891..68e2bbdfcb 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -5,7 +5,7 @@ module fpm fpm_run_settings, fpm_install_settings, fpm_test_settings use fpm_dependency, only : new_dependency_tree use fpm_environment, only: run, get_env -use fpm_filesystem, only: is_dir, join_path, number_of_rows, list_files, exists, basename +use fpm_filesystem, only: is_dir, join_path, number_of_rows, list_files, exists, basename, filewrite, mkdir use fpm_model, only: fpm_model_t, srcfile_t, show_model, & FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, FPM_SCOPE_DEP, & FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE, FPM_SCOPE_TEST @@ -58,6 +58,11 @@ subroutine build_model(model, settings, package, error) call model%deps%add(package, error) if (allocated(error)) return + ! build/ directory should now exist + if (.not.exists("build/.gitignore")) then + call filewrite(join_path("build", ".gitignore"),["*"]) + end if + if(settings%compiler.eq.'')then model%fortran_compiler = 'gfortran' else diff --git a/src/fpm/cmd/new.f90 b/src/fpm/cmd/new.f90 index 81cf62fc4d..0afe651309 100644 --- a/src/fpm/cmd/new.f90 +++ b/src/fpm/cmd/new.f90 @@ -98,9 +98,6 @@ subroutine cmd_new(settings) ! like realpath() or getcwd(). bname=basename(settings%name) - ! create NAME/.gitignore file - call warnwrite(join_path(settings%name, '.gitignore'), ['build/*']) - littlefile=[character(len=80) :: '# '//bname, 'My cool new project!'] ! create NAME/README.md diff --git a/src/fpm/cmd/update.f90 b/src/fpm/cmd/update.f90 index aa99ca30ab..a9918bf7ac 100644 --- a/src/fpm/cmd/update.f90 +++ b/src/fpm/cmd/update.f90 @@ -2,7 +2,7 @@ module fpm_cmd_update use fpm_command_line, only : fpm_update_settings use fpm_dependency, only : dependency_tree_t, new_dependency_tree use fpm_error, only : error_t, fpm_stop - use fpm_filesystem, only : exists, mkdir, join_path, delete_file + use fpm_filesystem, only : exists, mkdir, join_path, delete_file, filewrite use fpm_manifest, only : package_config_t, get_package_data implicit none private @@ -26,6 +26,7 @@ subroutine cmd_update(settings) if (.not.exists("build")) then call mkdir("build") + call filewrite(join_path("build", ".gitignore"),["*"]) end if cache = join_path("build", "cache.toml") diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 2ed7ac6c71..513bed3498 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -936,14 +936,11 @@ subroutine set_help() ' o runs the command "git init" in that directory ', & ' o populates the directory with the default project directories ', & ' o adds sample Fortran source files ', & - ' o adds a ".gitignore" file for ignoring the build/ directory ', & - ' (where fpm-generated output will be placed) ', & ' ', & ' The default file structure (that will be automatically scanned) is ', & ' ', & ' NAME/ ', & ' fpm.toml ', & - ' .gitignore ', & ' src/ ', & ' NAME.f90 ', & ' app/ ', & @@ -1004,8 +1001,8 @@ subroutine set_help() ' depend extensively on non-default build options. ', & ' ', & ' --bare A minimal manifest file ("fpm.toml") is created and ', & - ' a ".gitignore" and "README.md" file is created but no ', & - ' directories or sample Fortran is generated. ', & + ' "README.md" file is created but no directories or ', & + ' sample Fortran are generated. ', & ' ', & ' --help print this help and exit ', & ' --version print program version information and exit ', & From 5ab9dab49274b193a58eb6d372cf7160a791d420 Mon Sep 17 00:00:00 2001 From: "John S. Urban" Date: Sat, 31 Jul 2021 13:14:41 -0400 Subject: [PATCH 2/3] put NAME/.gitignore back So I put the orginal .gitignore back in, and even made it bigger if "fpm new -full" is used. Here is why ... Although I preferred only auto-generating .gitignore in build/ initially, after reviewing the comments I built a list of public github projects containing fpm.toml files and pulled them and eliminated most trivial ones that appeared to just be experiments in using fpm by somewhat arbitrarily removing those with less than one hundred lines of Fortran source and found the majority of those remaining had a customized (ie. not the default one built by the "fpm new" subcommand) .gitignore file; indicating many projects need a .gitignore file in the top directory, so might as well keep seeding it(?), I found seven that did not have a .gitignore at all, reinforcing the need to put one in the build directory itself, as this still does. For the most part those appeared to be unintentional and looked like several were inadvertently storing binaries on github as a result, indicating the change to making a build/.gitignore file is a good idea. stdlib-fpm does not have one, but did not have a build/ directory on github, but the change to put one in build/ itself will prevent that being a problem for anyone that forks or clones it, so that is covered now. I found a pattern where it looks like a number of large sites are setting up to be able to build with other systems other than fpm(1), which by itself does not need a .gitignore file of any complexity; just perhaps skipping non-core files like logs and fodder and other user-specific needs it is not too easy to optimize except by exclusion (that is, exclude everything except the default files used by fpm, which does not feel like a good direction). On the other hand, I found two other others using the default github list for Fortran projects, and saw several other projects essentially making their own attempt at the same list, but I think a large .gitignore file is conflating for a new (and probably typical) user so I put back the simple one by default when "fpm new" is used, but if "fpm new -full" is used, add the github recommendations. The github recommendations do not directly benefit a pure fpm project, but at least so far that is still a minority of the sample packages I found; so adding it at all or adding it via --full is a bit kluge, but seemed like it would make handy information readily available if perhaps not in the most intuitive way, but would not conflate basic usage. --- src/fpm/cmd/new.f90 | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/fpm/cmd/new.f90 b/src/fpm/cmd/new.f90 index 0afe651309..913b81e44f 100644 --- a/src/fpm/cmd/new.f90 +++ b/src/fpm/cmd/new.f90 @@ -100,6 +100,44 @@ subroutine cmd_new(settings) littlefile=[character(len=80) :: '# '//bname, 'My cool new project!'] + if(settings%with_full)then + ! create NAME/.gitignore file + call warnwrite(join_path(settings%name, '.gitignore'), [character(len=80):: & + &'# to ignore build/ only in the top level',& + &'/build*/',& + &'',& + &'# GitHub default for Fortran projects',& + &'# Prerequisites',& + &'*.d',& + &'# Compiled Object files',& + &'*.slo',& + &'*.lo',& + &'*.o',& + &'*.obj',& + &'# Precompiled Headers',& + &'*.gch',& + &'*.pch',& + &'# Compiled Dynamic libraries',& + &'*.so',& + &'*.dylib',& + &'*.dll',& + &'# Fortran module files',& + &'*.mod',& + &'*.smod',& + &'# Compiled Static libraries',& + &'*.lai',& + &'*.la',& + &'*.a',& + &'*.lib',& + &'# Executables',& + &'*.exe',& + &'*.out',& + &'*.app',& + &'#']) + else + call warnwrite(join_path(settings%name, '.gitignore'), ['/build/*']) + endif + ! create NAME/README.md call warnwrite(join_path(settings%name, 'README.md'), littlefile) From 1eba840dcaeb405d8170511c182742b7fcf2c9ba Mon Sep 17 00:00:00 2001 From: "John S. Urban" Date: Sat, 31 Jul 2021 17:53:33 -0400 Subject: [PATCH 3/3] no .gitignore generated by subcommand new --- src/fpm/cmd/new.f90 | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/src/fpm/cmd/new.f90 b/src/fpm/cmd/new.f90 index 913b81e44f..0afe651309 100644 --- a/src/fpm/cmd/new.f90 +++ b/src/fpm/cmd/new.f90 @@ -100,44 +100,6 @@ subroutine cmd_new(settings) littlefile=[character(len=80) :: '# '//bname, 'My cool new project!'] - if(settings%with_full)then - ! create NAME/.gitignore file - call warnwrite(join_path(settings%name, '.gitignore'), [character(len=80):: & - &'# to ignore build/ only in the top level',& - &'/build*/',& - &'',& - &'# GitHub default for Fortran projects',& - &'# Prerequisites',& - &'*.d',& - &'# Compiled Object files',& - &'*.slo',& - &'*.lo',& - &'*.o',& - &'*.obj',& - &'# Precompiled Headers',& - &'*.gch',& - &'*.pch',& - &'# Compiled Dynamic libraries',& - &'*.so',& - &'*.dylib',& - &'*.dll',& - &'# Fortran module files',& - &'*.mod',& - &'*.smod',& - &'# Compiled Static libraries',& - &'*.lai',& - &'*.la',& - &'*.a',& - &'*.lib',& - &'# Executables',& - &'*.exe',& - &'*.out',& - &'*.app',& - &'#']) - else - call warnwrite(join_path(settings%name, '.gitignore'), ['/build/*']) - endif - ! create NAME/README.md call warnwrite(join_path(settings%name, 'README.md'), littlefile)