-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcs-archive.jam
169 lines (143 loc) · 3.88 KB
/
vcs-archive.jam
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Version Control System - Web Archives
#
# @todo detect if curl or wget is available
import path ;
import errors ;
import assert ;
# Generates a version string from an archive directory assuming a
# naming convention.
#
# <tag-name>
rule generate-version-string ( directory )
{
# @todo not sure why this doesn't work
# assert.true path.exists $(directory)/.vcs-archive-version-string ;
return [ read-file $(directory)/.vcs-archive-version-string ] ;
}
# Fetches from the given url to the given directory.
rule fetch ( root-url : directory )
{
path.makedirs $(directory) ;
# @todo check results
# @todo lots more work, package types, etc
local r = [ fetch-url $(root-url) : $(directory)/.vcs-archive.tar.gz ] ;
# @todo should work, but doesn't
# assert.true path.exists $(directory) ;
# store the root-url for use later
write-file $(directory)/.vcs-archive-root-url : $(root-url) ;
}
# Checks out the indicated symbolic reference for the archive
# repository at directory.
#
# A symbolic reference for an archive repository is the URL it was
# fetched from.
#
# trunk
# tags/1.1.1
# branches/devel-fixes
rule checkout ( directory : symbolic-ref )
{
### program-string = "
###import tarfile
###
###archive = tarfile.open('$(directory)/.vcs-archive.tar.gz')
###archive.extractall('$(directory)', members=stripped_leading_directory)
###archive.close()
###" ;
###
### python-with-string $(program-string) ;
# @todo check results
local r = [ SHELL "tar -x -C $(directory) --strip-components 1 -z -f $(directory)/.vcs-archive.tar.gz" ] ;
write-file $(directory)/.vcs-archive-version-string : $(symbolic-ref) ;
}
# Returns the root URL of the archive repository at the given
# directory.
rule root-url ( directory )
{
return [ read-file $(directory)/.vcs-archive-root-url ] ;
}
# Returns the ref for the symbolic-ref if it is not empty or HEAD for
# the archive repository at directory.
#
# For an archive repository, a ref is the URL fragment beyond the root
# and the last changed revision.
#
# tags/1.1.1@12345
rule ref ( directory : symbolic-ref ? )
{
if $(symbolic-ref)
{
# @todo not sure why this doesn't work
# assert.true path.exists $(directory)/.vcs-archive-version-string ;
local current-symbolic-ref = [ read-file $(directory)/.vcs-archive-version-string ] ;
if $(current-symbolic-ref) = $(symbolic-ref)
{
return [ read-file $(directory)/.vcs-archive-root-url ] ;
}
else
{
# we only know the "ref" to what we have, so return nothing
return ;
}
}
else
{
return [ read-file $(directory)/.vcs-archive-root-url ] ;
}
}
# Returns true if the given directory is an archive repository.
rule is-repository ( directory )
{
# @todo is there a better way?
return [ path.exists $(directory)/.vcs-archive-root-url ] ;
}
# Return true if the executable exists to operate on archives.
#
# @todo maybe we should just require python and 7z.
#
# - python and 7z
#
# OR
#
# - wget or curl
# - tar + gzip/bzip2
# - unzip
# - 7z
rule executable-exists ( )
{
# @todo always say true for now
return 1 == 1 ;
}
local rule fetch-url ( url : filename )
{
program-string = "
import urllib
urllib.urlretrieve('$(url)','$(filename)')
" ;
local r = [ python-with-string $(program-string) ] ;
}
# Returns the contents of file referenced by filename as a string.
local rule read-file ( filename )
{
program-string = "
import sys
with open('$(filename)', 'r') as fp:
sys.stdout.write(fp.read())
" ;
return [ python-with-string $(program-string) ] ;
}
# Writes the string to the contents of the file referenced to by
# filename.
local rule write-file ( filename : string )
{
echo $(string) ;
program-string = "
with open('$(filename)', 'w') as fp:
fp.write('$(string)')
" ;
python-with-string $(program-string) ;
}
local rule python-with-string ( program-string )
{
return [ SHELL "echo \"$(program-string)\" | python -" ] ;
}