Skip to content

Commit eebe0ff

Browse files
authored
Merge branch 'master' into local-depends
2 parents 24b115e + 49de89e commit eebe0ff

File tree

5 files changed

+174
-161
lines changed

5 files changed

+174
-161
lines changed

fpm/app/main.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ program main
77
fpm_test_settings, &
88
fpm_install_settings, &
99
get_command_line_settings
10-
use fpm, only: cmd_build, cmd_install, cmd_new, cmd_run, cmd_test
10+
use fpm, only: cmd_build, cmd_install, cmd_run, cmd_test
11+
use fpm_cmd_new, only: cmd_new
1112

1213
implicit none
1314

fpm/src/fpm.f90

Lines changed: 3 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module fpm
33
use fpm_backend, only: build_package
44
use fpm_command_line, only: fpm_build_settings, fpm_new_settings, &
55
fpm_run_settings, fpm_install_settings, fpm_test_settings
6-
use fpm_environment, only: run, get_os_type, OS_LINUX, OS_MACOS, OS_WINDOWS
7-
use fpm_filesystem, only: is_dir, join_path, number_of_rows, list_files, exists, basename, mkdir
6+
use fpm_environment, only: run
7+
use fpm_filesystem, only: is_dir, join_path, number_of_rows, list_files, exists, basename
88
use fpm_model, only: srcfile_ptr, srcfile_t, fpm_model_t, &
99
FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, &
1010
FPM_SCOPE_DEP, FPM_SCOPE_APP, FPM_SCOPE_TEST
@@ -21,7 +21,7 @@ module fpm
2121
use fpm_manifest_dependency, only: dependency_t
2222
implicit none
2323
private
24-
public :: cmd_build, cmd_install, cmd_new, cmd_run, cmd_test
24+
public :: cmd_build, cmd_install, cmd_run, cmd_test
2525

2626
contains
2727

@@ -284,160 +284,6 @@ subroutine cmd_install(settings)
284284
error stop 8
285285
end subroutine cmd_install
286286

287-
288-
subroutine cmd_new(settings) ! --with-executable F --with-test F '
289-
type(fpm_new_settings), intent(in) :: settings
290-
integer :: ierr
291-
character(len=:),allocatable :: bname ! baeename of NAME
292-
character(len=:),allocatable :: message(:)
293-
character(len=:),allocatable :: littlefile(:)
294-
295-
call mkdir(settings%name) ! make new directory
296-
call run('cd '//settings%name) ! change to new directory as a test. New OS routines to improve this; system dependent potentially
297-
!! NOTE: need some system routines to handle filenames like "." like realpath() or getcwd().
298-
bname=basename(settings%name)
299-
300-
!! weird gfortran bug?? lines truncated to concatenated string length, not 80
301-
!! hit some weird gfortran bug when littlefile data was an argument to warnwrite(3f), ok when a variable
302-
303-
call warnwrite(join_path(settings%name, '.gitignore'), ['build/*']) ! create NAME/.gitignore file
304-
305-
littlefile=[character(len=80) :: '# '//bname, 'My cool new project!']
306-
307-
call warnwrite(join_path(settings%name, 'README.md'), littlefile) ! create NAME/README.md
308-
309-
message=[character(len=80) :: & ! start building NAME/fpm.toml
310-
&'name = "'//bname//'" ', &
311-
&'version = "0.1.0" ', &
312-
&'license = "license" ', &
313-
&'author = "Jane Doe" ', &
314-
&'maintainer = "[email protected]" ', &
315-
&'copyright = "2020 Jane Doe" ', &
316-
&' ', &
317-
&'']
318-
319-
if(settings%with_lib)then
320-
call mkdir(join_path(settings%name,'src') )
321-
message=[character(len=80) :: message, & ! create next section of fpm.toml
322-
&'[library] ', &
323-
&'source-dir="src" ', &
324-
&'']
325-
littlefile=[character(len=80) :: & ! create placeholder module src/bname.f90
326-
&'module '//bname, &
327-
&' implicit none', &
328-
&' private', &
329-
&'', &
330-
&' public :: say_hello', &
331-
&'contains', &
332-
&' subroutine say_hello', &
333-
&' print *, "Hello, '//bname//'!"', &
334-
&' end subroutine say_hello', &
335-
&'end module '//bname]
336-
! a proposed alternative default
337-
call warnwrite(join_path(settings%name, 'src', bname//'.f90'), littlefile) ! create NAME/src/NAME.f90
338-
endif
339-
340-
if(settings%with_test)then
341-
call mkdir(join_path(settings%name, 'test')) ! create NAME/test or stop
342-
message=[character(len=80) :: message, & ! create next section of fpm.toml
343-
&'[[test]] ', &
344-
&'name="runTests" ', &
345-
&'source-dir="test" ', &
346-
&'main="main.f90" ', &
347-
&'']
348-
349-
littlefile=[character(len=80) :: &
350-
&'program main', &
351-
&'implicit none', &
352-
&'', &
353-
&'print *, "Put some tests in here!"', &
354-
&'end program main']
355-
! a proposed alternative default a little more substantive
356-
call warnwrite(join_path(settings%name, 'test/main.f90'), littlefile) ! create NAME/test/main.f90
357-
endif
358-
359-
if(settings%with_executable)then
360-
call mkdir(join_path(settings%name, 'app')) ! create NAME/app or stop
361-
message=[character(len=80) :: message, & ! create next section of fpm.toml
362-
&'[[executable]] ', &
363-
&'name="'//bname//'" ', &
364-
&'source-dir="app" ', &
365-
&'main="main.f90" ', &
366-
&'']
367-
368-
littlefile=[character(len=80) :: &
369-
&'program main', &
370-
&' use '//bname//', only: say_hello', &
371-
&'', &
372-
&' implicit none', &
373-
&'', &
374-
&' call say_hello', &
375-
&'end program main']
376-
call warnwrite(join_path(settings%name, 'app/main.f90'), littlefile)
377-
endif
378-
379-
call warnwrite(join_path(settings%name, 'fpm.toml'), message) ! now that built it write NAME/fpm.toml
380-
381-
call run('cd ' // settings%name // ';git init') ! assumes these commands work on all systems and git(1) is installed
382-
contains
383-
384-
subroutine warnwrite(fname,data)
385-
character(len=*),intent(in) :: fname
386-
character(len=*),intent(in) :: data(:)
387-
388-
if(.not.exists(fname))then
389-
call filewrite(fname,data)
390-
else
391-
write(stderr,'(*(g0,1x))')'fpm::new<WARNING>',fname,'already exists. Not overwriting'
392-
endif
393-
394-
end subroutine warnwrite
395-
396-
subroutine filewrite(filename,filedata)
397-
use,intrinsic :: iso_fortran_env, only : stdin=>input_unit, stdout=>output_unit, stderr=>error_unit
398-
! write filedata to file filename
399-
character(len=*),intent(in) :: filename
400-
character(len=*),intent(in) :: filedata(:)
401-
integer :: lun, i, ios
402-
character(len=256) :: message
403-
404-
message=' '
405-
ios=0
406-
if(filename.ne.' ')then
407-
open(file=filename, &
408-
& newunit=lun, &
409-
& form='formatted', & ! FORM = FORMATTED | UNFORMATTED
410-
& access='sequential', & ! ACCESS = SEQUENTIAL | DIRECT | STREAM
411-
& action='write', & ! ACTION = READ|WRITE | READWRITE
412-
& position='rewind', & ! POSITION = ASIS | REWIND | APPEND
413-
& status='new', & ! STATUS = NEW | REPLACE | OLD | SCRATCH | UNKNOWN
414-
& iostat=ios, &
415-
& iomsg=message)
416-
else
417-
lun=stdout
418-
ios=0
419-
endif
420-
if(ios.ne.0)then
421-
write(stderr,'(*(a:,1x))')'*filewrite* error:',filename,trim(message)
422-
error stop 1
423-
endif
424-
do i=1,size(filedata) ! write file
425-
write(lun,'(a)',iostat=ios,iomsg=message)trim(filedata(i))
426-
if(ios.ne.0)then
427-
write(stderr,'(*(a:,1x))')'*filewrite* error:',filename,trim(message)
428-
error stop 4
429-
endif
430-
enddo
431-
close(unit=lun,iostat=ios,iomsg=message) ! close file
432-
if(ios.ne.0)then
433-
write(stderr,'(*(a:,1x))')'*filewrite* error:',trim(message)
434-
error stop 2
435-
endif
436-
end subroutine filewrite
437-
438-
end subroutine cmd_new
439-
440-
441287
subroutine cmd_run(settings)
442288
type(fpm_run_settings), intent(in) :: settings
443289
character(len=:),allocatable :: release_name, cmd, fname

fpm/src/fpm/cmd/new.f90

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
module fpm_cmd_new
2+
3+
use fpm_command_line, only : fpm_new_settings
4+
use fpm_environment, only : run, OS_LINUX, OS_MACOS, OS_WINDOWS
5+
use fpm_filesystem, only : join_path, exists, basename, mkdir
6+
use,intrinsic :: iso_fortran_env, only : stderr=>error_unit
7+
implicit none
8+
private
9+
public :: cmd_new
10+
11+
contains
12+
13+
subroutine cmd_new(settings) ! --with-executable F --with-test F '
14+
type(fpm_new_settings), intent(in) :: settings
15+
character(len=:),allocatable :: bname ! baeename of NAME
16+
character(len=:),allocatable :: message(:)
17+
character(len=:),allocatable :: littlefile(:)
18+
19+
call mkdir(settings%name) ! make new directory
20+
call run('cd '//settings%name) ! change to new directory as a test. System dependent potentially
21+
!! NOTE: need some system routines to handle filenames like "." like realpath() or getcwd().
22+
bname=basename(settings%name)
23+
24+
!! weird gfortran bug?? lines truncated to concatenated string length, not 80
25+
!! hit some weird gfortran bug when littlefile data was an argument to warnwrite(3f), ok when a variable
26+
27+
call warnwrite(join_path(settings%name, '.gitignore'), ['build/*']) ! create NAME/.gitignore file
28+
29+
littlefile=[character(len=80) :: '# '//bname, 'My cool new project!']
30+
31+
call warnwrite(join_path(settings%name, 'README.md'), littlefile) ! create NAME/README.md
32+
33+
message=[character(len=80) :: & ! start building NAME/fpm.toml
34+
&'name = "'//bname//'" ', &
35+
&'version = "0.1.0" ', &
36+
&'license = "license" ', &
37+
&'author = "Jane Doe" ', &
38+
&'maintainer = "[email protected]" ', &
39+
&'copyright = "2020 Jane Doe" ', &
40+
&' ', &
41+
&'']
42+
43+
if(settings%with_lib)then
44+
call mkdir(join_path(settings%name,'src') )
45+
message=[character(len=80) :: message, & ! create next section of fpm.toml
46+
&'[library] ', &
47+
&'source-dir="src" ', &
48+
&'']
49+
littlefile=[character(len=80) :: & ! create placeholder module src/bname.f90
50+
&'module '//bname, &
51+
&' implicit none', &
52+
&' private', &
53+
&'', &
54+
&' public :: say_hello', &
55+
&'contains', &
56+
&' subroutine say_hello', &
57+
&' print *, "Hello, '//bname//'!"', &
58+
&' end subroutine say_hello', &
59+
&'end module '//bname]
60+
! a proposed alternative default
61+
call warnwrite(join_path(settings%name, 'src', bname//'.f90'), littlefile) ! create NAME/src/NAME.f90
62+
endif
63+
64+
if(settings%with_test)then
65+
call mkdir(join_path(settings%name, 'test')) ! create NAME/test or stop
66+
message=[character(len=80) :: message, & ! create next section of fpm.toml
67+
&'[[test]] ', &
68+
&'name="runTests" ', &
69+
&'source-dir="test" ', &
70+
&'main="main.f90" ', &
71+
&'']
72+
73+
littlefile=[character(len=80) :: &
74+
&'program main', &
75+
&'implicit none', &
76+
&'', &
77+
&'print *, "Put some tests in here!"', &
78+
&'end program main']
79+
! a proposed alternative default a little more substantive
80+
call warnwrite(join_path(settings%name, 'test/main.f90'), littlefile) ! create NAME/test/main.f90
81+
endif
82+
83+
if(settings%with_executable)then
84+
call mkdir(join_path(settings%name, 'app')) ! create NAME/app or stop
85+
message=[character(len=80) :: message, & ! create next section of fpm.toml
86+
&'[[executable]] ', &
87+
&'name="'//bname//'" ', &
88+
&'source-dir="app" ', &
89+
&'main="main.f90" ', &
90+
&'']
91+
92+
littlefile=[character(len=80) :: &
93+
&'program main', &
94+
&' use '//bname//', only: say_hello', &
95+
&'', &
96+
&' implicit none', &
97+
&'', &
98+
&' call say_hello', &
99+
&'end program main']
100+
call warnwrite(join_path(settings%name, 'app/main.f90'), littlefile)
101+
endif
102+
103+
call warnwrite(join_path(settings%name, 'fpm.toml'), message) ! now that built it write NAME/fpm.toml
104+
105+
call run('cd ' // settings%name // '&&git init') ! assumes these commands work on all systems and git(1) is installed
106+
contains
107+
108+
subroutine warnwrite(fname,data)
109+
character(len=*),intent(in) :: fname
110+
character(len=*),intent(in) :: data(:)
111+
112+
if(.not.exists(fname))then
113+
call filewrite(fname,data)
114+
else
115+
write(stderr,'(*(g0,1x))')'fpm::new<WARNING>',fname,'already exists. Not overwriting'
116+
endif
117+
118+
end subroutine warnwrite
119+
120+
subroutine filewrite(filename,filedata)
121+
use,intrinsic :: iso_fortran_env, only : stdin=>input_unit, stdout=>output_unit, stderr=>error_unit
122+
! write filedata to file filename
123+
character(len=*),intent(in) :: filename
124+
character(len=*),intent(in) :: filedata(:)
125+
integer :: lun, i, ios
126+
character(len=256) :: message
127+
128+
message=' '
129+
ios=0
130+
if(filename.ne.' ')then
131+
open(file=filename, &
132+
& newunit=lun, &
133+
& form='formatted', & ! FORM = FORMATTED | UNFORMATTED
134+
& access='sequential', & ! ACCESS = SEQUENTIAL | DIRECT | STREAM
135+
& action='write', & ! ACTION = READ|WRITE | READWRITE
136+
& position='rewind', & ! POSITION = ASIS | REWIND | APPEND
137+
& status='new', & ! STATUS = NEW | REPLACE | OLD | SCRATCH | UNKNOWN
138+
& iostat=ios, &
139+
& iomsg=message)
140+
else
141+
lun=stdout
142+
ios=0
143+
endif
144+
if(ios.ne.0)then
145+
write(stderr,'(*(a:,1x))')'*filewrite* error:',filename,trim(message)
146+
error stop 1
147+
endif
148+
do i=1,size(filedata) ! write file
149+
write(lun,'(a)',iostat=ios,iomsg=message)trim(filedata(i))
150+
if(ios.ne.0)then
151+
write(stderr,'(*(a:,1x))')'*filewrite* error:',filename,trim(message)
152+
error stop 4
153+
endif
154+
enddo
155+
close(unit=lun,iostat=ios,iomsg=message) ! close file
156+
if(ios.ne.0)then
157+
write(stderr,'(*(a:,1x))')'*filewrite* error:',trim(message)
158+
error stop 2
159+
endif
160+
end subroutine filewrite
161+
162+
end subroutine cmd_new
163+
164+
end module fpm_cmd_new

fpm/src/fpm_command_line.f90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,9 @@ subroutine set_help()
416416
' ', &
417417
' The "new" subcommand creates a directory and runs the command ', &
418418
' "git init" in that directory and makes an example "fpm.toml" ', &
419-
' file, a src/ directory, and optionally a test/ and app/ ', &
420-
' directory with trivial example Fortran source files. ', &
419+
' file. and src/ directory and a sample module file. It ', &
420+
' optionally also creates a test/ and app/ directory with ', &
421+
' trivial example Fortran program sources. ', &
421422
' ', &
422423
' Remember to update the information in the sample "fpm.toml" ', &
423424
' file with such information as your name and e-mail address. ', &

fpm/test/cli_test/cli_test.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ subroutine parse()
193193
fpm_test_settings, &
194194
fpm_install_settings, &
195195
get_command_line_settings
196-
use fpm, only: cmd_build, cmd_install, cmd_new, cmd_run, cmd_test
196+
use fpm, only: cmd_build, cmd_install, cmd_run, cmd_test
197+
use fpm_cmd_new, only: cmd_new
197198
class(fpm_cmd_settings), allocatable :: cmd_settings
198199
! duplicates the calls as seen in the main program for fpm
199200
call get_command_line_settings(cmd_settings)

0 commit comments

Comments
 (0)