-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpm-prepare.tcl
96 lines (87 loc) · 2.97 KB
/
fpm-prepare.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# fpm-prepare.tcl --
# Prepare the GUI:
# - Get the up-to-date fpm-registry
# - Make sure that the various directories exist
#
# getRegistry --
# Get the registry and put it in the dedicated directory
#
# Arguments:
# url The URL to retrieve fpm-registry project
# checkout The checkout directory
#
# Note:
# If this step fails, the program stops
#
proc getRegistry {url checkout} {
set oldcwd [pwd]
set cloneDir [file tail $url]
if { ! [file exists $checkout] } {
if { [catch {
file mkdir $checkout
} msg] } {
tk_messageBox -icon error -type ok -title "Fpm - preparation failed" \
-message "Could not create the directory $checkout\nPlease specify a different name\nError: $msg"
exit
}
}
if { ! [file isdir $checkout] } {
tk_messageBox -icon error -type ok -title "Fpm - preparation failed" \
-message "$checkout is not a directory $checkout\nPlease specify a different name"
exit
}
cd $checkout
if { ! [file exists $cloneDir] } {
set rc [catch {
exec -ignorestderr git clone $url
} msg]
} else {
set rc [catch {
cd $cloneDir
exec git fetch
exec git merge --ff-only
} msg]
}
if { $rc != 0 } {
tk_messageBox -icon error -type ok -title "Fpm - preparation failed" \
-message "Error cloning the fpm-registry\nPlease check this\nError: $msg"
exit
}
if { ! [file exists [file join $checkout $cloneDir registry.toml]] } {
tk_messageBox -icon error -type ok -title "Fpm - preparation failed" \
-message "Could not clone the fpm-registry\nError: $msg"
exit
}
cd $oldcwd
}
# checkDirectories --
# Check that the various directories to store the source files and the installation exist
#
# Arguments:
# checkoutDir Directory for checking out the sources
# installDir Directory for installing the libraries and such
#
proc checkDirectories {checkoutDir installDir} {
foreach dir [list $checkoutDir $installDir] text [list "checkout directory" "installation directory"] {
if { ! [file exists $dir] } {
set rc [catch {file mkdir $dir} msg]
if { $rc != 0 } {
tk_messageBox -icon error -type ok -title "Fpm - preparation failed" \
-message "Could not create the $text - $dir\nError: $msg"
exit
}
} else {
if { ! [file isdir $dir] } {
tk_messageBox -icon error -type ok -title "Fpm - preparation failed" \
-message "$dir is not a directory\nPlease select a different $text"
exit
}
}
}
}
# test --
#getRegistry xxx e:/xyz
#getRegistry xxx d:/xyz
#getRegistry "https://github.com/fortran-lang/fpm-registry" d:/xyz
#checkDirectories c:/xyz d:/xyzz
#checkDirectories d:/xyzz d:/xyzz