author | wenzelm |
Wed, 30 Sep 2020 22:55:35 +0200 | |
changeset 72346 | 93e533198bf6 |
child 72362 | 5f17bf3709b8 |
permissions | -rw-r--r-- |
72346
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/Admin/build_sqlite.scala |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
3 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
4 |
Build Isabelle sqlite-jdbc component from official download. |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
6 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
8 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
9 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
10 |
object Build_SQLite |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
11 |
{ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
12 |
/* build sqlite */ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
13 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
14 |
def build_sqlite( |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
15 |
download_url: String, |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
16 |
progress: Progress = new Progress, |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
17 |
target_dir: Path = Path.current) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
18 |
{ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
19 |
val Download_Name = """^.*/([^/]+)\.jar""".r |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
20 |
val download_name = |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
21 |
download_url match { |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
22 |
case Download_Name(download_name) => download_name |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
23 |
case _ => error("Malformed jar download URL: " + quote(download_url)) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
24 |
} |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
25 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
26 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
27 |
/* component */ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
28 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
29 |
val component_dir = target_dir + Path.basic(download_name) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
30 |
if (component_dir.is_dir) error("Component directory already exists: " + component_dir) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
31 |
else { |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
32 |
progress.echo("Component " + component_dir) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
33 |
Isabelle_System.mkdirs(component_dir) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
34 |
} |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
35 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
36 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
37 |
/* README */ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
38 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
39 |
File.write(component_dir + Path.basic("README"), |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
40 |
"This is " + download_name + " from\n" + download_url + |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
41 |
"\n\n Makarius\n " + Date.Format.date(Date.now()) + "\n") |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
42 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
43 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
44 |
/* settings */ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
45 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
46 |
val etc_dir = component_dir + Path.basic("etc") |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
47 |
Isabelle_System.mkdirs(etc_dir) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
48 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
49 |
File.write(etc_dir + Path.basic("settings"), |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
50 |
"""# -*- shell-script -*- :mode=shellscript: |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
51 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
52 |
ISABELLE_SQLITE_HOME="$COMPONENT" |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
53 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
54 |
classpath "$ISABELLE_SQLITE_HOME/""" + download_name + """.jar" |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
55 |
""") |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
56 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
57 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
58 |
/* jar */ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
59 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
60 |
val jar = component_dir + Path.basic(download_name).ext("jar") |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
61 |
progress.echo("Getting " + quote(download_url)) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
62 |
try { |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
63 |
Isabelle_System.bash("curl --fail --silent --location " + Bash.string(download_url) + |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
64 |
" > " + File.bash_path(jar)).check |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
65 |
} |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
66 |
catch { |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
67 |
case ERROR(msg) => cat_error("Failed to download " + quote(download_url), msg) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
68 |
} |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
69 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
70 |
Isabelle_System.with_tmp_dir("sqlite")(jar_dir => |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
71 |
{ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
72 |
progress.echo("Unpacking " + jar) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
73 |
Isabelle_System.bash("isabelle_jdk jar xf " + File.bash_path(jar.absolute), |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
74 |
cwd = jar_dir.file).check |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
75 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
76 |
val jar_files = |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
77 |
List( |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
78 |
"META-INF/maven/org.xerial/sqlite-jdbc/LICENSE" -> ".", |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
79 |
"META-INF/maven/org.xerial/sqlite-jdbc/LICENSE.zentus" -> ".", |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
80 |
"org/sqlite/native/Linux/aarch64/libsqlitejdbc.so" -> "arm64-linux", |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
81 |
"org/sqlite/native/Linux/x86_64/libsqlitejdbc.so" -> "x86_64-linux", |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
82 |
"org/sqlite/native/Mac/x86_64/libsqlitejdbc.jnilib" -> "x86_64-darwin", |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
83 |
"org/sqlite/native/Windows/x86_64/sqlitejdbc.dll" -> "x86_64-windows") |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
84 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
85 |
for ((file, dir) <- jar_files) { |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
86 |
val target = component_dir + Path.explode(dir) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
87 |
Isabelle_System.mkdirs(target) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
88 |
File.copy(jar_dir + Path.explode(file), target) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
89 |
} |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
90 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
91 |
File.set_executable(component_dir + Path.explode("x86_64-windows/sqlitejdbc.dll"), true) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
92 |
}) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
93 |
} |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
94 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
95 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
96 |
/* Isabelle tool wrapper */ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
97 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
98 |
val isabelle_tool = |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
99 |
Isabelle_Tool("build_sqlite", "build Isabelle sqlite-jdbc component from official download", |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
100 |
args => |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
101 |
{ |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
102 |
var target_dir = Path.current |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
103 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
104 |
val getopts = Getopts(""" |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
105 |
Usage: isabelle build_sqlite [OPTIONS] DOWNLOAD |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
106 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
107 |
Options are: |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
108 |
-D DIR target directory (default ".") |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
109 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
110 |
Build sqlite-jdbc component from the specified download URL (JAR), see also |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
111 |
https://github.com/xerial/sqlite-jdbc/releases |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
112 |
""", |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
113 |
"D:" -> (arg => target_dir = Path.explode(arg))) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
114 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
115 |
val more_args = getopts(args) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
116 |
val download_url = |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
117 |
more_args match { |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
118 |
case List(download_url) => download_url |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
119 |
case _ => getopts.usage() |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
120 |
} |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
121 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
122 |
val progress = new Console_Progress() |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
123 |
|
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
124 |
build_sqlite(download_url, progress = progress, target_dir = target_dir) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
125 |
}) |
93e533198bf6
build Isabelle sqlite-jdbc component from official download;
wenzelm
parents:
diff
changeset
|
126 |
} |