| author | nipkow | 
| Fri, 23 Aug 2024 18:40:12 +0200 | |
| changeset 80738 | 6adf6cc82013 | 
| parent 77566 | 2a99fcb283ee | 
| child 83152 | 5708aa8d1493 | 
| permissions | -rw-r--r-- | 
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
changeset | 1 | /* Title: Pure/Admin/component_pdfjs.scala | 
| 75105 | 2 | Author: Makarius | 
| 3 | ||
| 4 | Build Isabelle component for Mozilla PDF.js. | |
| 5 | ||
| 6 | See also: | |
| 7 | ||
| 8 | - https://github.com/mozilla/pdf.js | |
| 9 | - https://github.com/mozilla/pdf.js/releases | |
| 10 | - https://github.com/mozilla/pdf.js/wiki/Setup-PDF.js-in-a-website | |
| 11 | */ | |
| 12 | ||
| 13 | package isabelle | |
| 14 | ||
| 15 | ||
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
changeset | 16 | object Component_PDFjs {
 | 
| 75105 | 17 | /* build pdfjs component */ | 
| 18 | ||
| 19 | val default_url = "https://github.com/mozilla/pdf.js/releases/download" | |
| 75706 | 20 | val default_version = "2.14.305" | 
| 75105 | 21 | |
| 22 | def build_pdfjs( | |
| 23 | base_url: String = default_url, | |
| 24 | version: String = default_version, | |
| 25 | target_dir: Path = Path.current, | |
| 75393 | 26 | progress: Progress = new Progress | 
| 27 |   ): Unit = {
 | |
| 75105 | 28 | /* component name */ | 
| 29 | ||
| 30 | val component = "pdfjs-" + version | |
| 76518 | 31 | val component_dir = | 
| 76547 | 32 | Components.Directory(target_dir + Path.basic(component)).create(progress = progress) | 
| 75105 | 33 | |
| 34 | ||
| 35 | /* download */ | |
| 36 | ||
| 37 | val download_url = base_url + "/v" + version | |
| 75394 | 38 |     Isabelle_System.with_tmp_file("archive", ext = "zip") { archive_file =>
 | 
| 75706 | 39 | Isabelle_System.download_file(download_url + "/pdfjs-" + version + "-legacy-dist.zip", | 
| 75105 | 40 | archive_file, progress = progress) | 
| 76530 | 41 | Isabelle_System.extract(archive_file, component_dir.path) | 
| 75394 | 42 | } | 
| 75105 | 43 | |
| 44 | ||
| 45 | /* settings */ | |
| 46 | ||
| 76548 | 47 |     component_dir.write_settings("""
 | 
| 75105 | 48 | ISABELLE_PDFJS_HOME="$COMPONENT" | 
| 49 | """) | |
| 50 | ||
| 51 | ||
| 52 | /* README */ | |
| 53 | ||
| 76518 | 54 | File.write(component_dir.README, | 
| 75105 | 55 | """This is PDF.js from | 
| 56 | """ + download_url + """ | |
| 57 | ||
| 58 | ||
| 59 | Makarius | |
| 60 | """ + Date.Format.date(Date.now()) + "\n") | |
| 61 | } | |
| 62 | ||
| 63 | ||
| 64 | /* Isabelle tool wrapper */ | |
| 65 | ||
| 66 | val isabelle_tool = | |
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
changeset | 67 |     Isabelle_Tool("component_pdfjs", "build component for Mozilla PDF.js",
 | 
| 75394 | 68 | Scala_Project.here, | 
| 69 |       { args =>
 | |
| 70 | var target_dir = Path.current | |
| 71 | var base_url = default_url | |
| 72 | var version = default_version | |
| 75105 | 73 | |
| 75394 | 74 |         val getopts = Getopts("""
 | 
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
changeset | 75 | Usage: isabelle component_pdfjs [OPTIONS] | 
| 75105 | 76 | |
| 77 | Options are: | |
| 78 | -D DIR target directory (default ".") | |
| 79 | -U URL download URL (default: """" + default_url + """") | |
| 80 | -V VERSION version (default: """" + default_version + """") | |
| 81 | ||
| 82 | Build component for PDF.js. | |
| 83 | """, | |
| 75394 | 84 | "D:" -> (arg => target_dir = Path.explode(arg)), | 
| 85 | "U:" -> (arg => base_url = arg), | |
| 86 | "V:" -> (arg => version = arg)) | |
| 75105 | 87 | |
| 75394 | 88 | val more_args = getopts(args) | 
| 89 | if (more_args.nonEmpty) getopts.usage() | |
| 75105 | 90 | |
| 75394 | 91 | val progress = new Console_Progress() | 
| 75105 | 92 | |
| 75394 | 93 | build_pdfjs(base_url = base_url, version = version, target_dir = target_dir, | 
| 94 | progress = progress) | |
| 95 | }) | |
| 75105 | 96 | } |