src/Pure/Admin/component_rsync.scala
author wenzelm
Thu, 30 Mar 2023 11:40:51 +0200
changeset 77755 12c8d72df48a
parent 77754 fea7bc828b8b
child 77756 efd5c582d7ae
permissions -rw-r--r--
clarified build options;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Admin/component_rsync.scala
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
     3
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
     4
Build Isabelle rsync component from official source distribution.
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
     5
*/
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
     6
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
     7
package isabelle
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
     8
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
     9
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    10
object Component_Rsync {
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    11
  /* build rsync */
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    12
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    13
  val default_version = "3.2.7"
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    14
  val default_download_url = "https://github.com/WayneD/rsync/archive/refs/tags"
77755
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    15
  val default_build_options: List[String] =
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    16
    List(
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    17
      "--disable-openssl",
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    18
      "--disable-xxhash",
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    19
      "--disable-zstd",
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    20
      "--disable-lz4",
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    21
      "--disable-md2man",
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    22
      "--disable-acl-support",
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    23
      "--disable-xattr-support")
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    24
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    25
  def build_rsync(
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    26
    version: String = default_version,
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    27
    download_url: String = default_download_url,
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    28
    progress: Progress = new Progress,
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    29
    target_dir: Path = Path.current,
77755
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    30
    build_options: List[String] = default_build_options
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    31
  ): Unit = {
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    32
    Isabelle_System.with_tmp_dir("build") { tmp_dir =>
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    33
      /* component */
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    34
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    35
      val component_name = "rsync-" + version
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    36
      val component_dir =
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    37
        Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    38
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    39
      val platform_name =
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    40
        proper_string(Isabelle_System.getenv("ISABELLE_PLATFORM64"))
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    41
          .getOrElse(error("No 64bit platform"))
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    42
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    43
      val platform_dir =
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    44
        Isabelle_System.make_directory(component_dir.path + Path.basic(platform_name))
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    45
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    46
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    47
      /* download source */
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    48
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    49
      val archive_name = "v" + version + ".tar.gz"
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    50
      val archive_path = tmp_dir + Path.explode(archive_name)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    51
      val archive_url = Url.append_path(download_url, archive_name)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    52
      Isabelle_System.download_file(archive_url, archive_path, progress = progress)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    53
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    54
      Isabelle_System.extract(archive_path, tmp_dir)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    55
      val source_dir = File.get_dir(tmp_dir, title = archive_url)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    56
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    57
      Isabelle_System.extract(archive_path, component_dir.src, strip = true)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    58
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    59
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    60
      /* build */
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    61
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    62
      progress.echo("Building rsync for " + platform_name + " ...")
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    63
77755
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
    64
      val build_script = "./configure " + Bash.strings(build_options) + " && make"
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    65
      Isabelle_System.bash(build_script, cwd = source_dir.file,
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    66
        progress_stdout = progress.echo(_, verbose = true),
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    67
        progress_stderr = progress.echo(_, verbose = true)).check
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    68
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    69
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    70
      /* install */
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    71
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    72
      Isabelle_System.copy_file(source_dir + Path.explode("COPYING"), component_dir.LICENSE)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    73
      Isabelle_System.copy_file(source_dir + Path.explode("rsync").platform_exe, platform_dir)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    74
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    75
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    76
      /* settings */
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    77
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    78
      component_dir.write_settings("""
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    79
ISABELLE_RSYNC_HOME="$COMPONENT/$ISABELLE_PLATFORM64"
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    80
ISABELLE_RSYNC="$ISABELLE_RSYNC_HOME/rsync"
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    81
""")
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    82
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    83
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    84
      /* README */
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    85
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    86
      File.write(component_dir.README,
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    87
        "This is rsync " + version + " from " + download_url + """
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    88
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    89
See also:
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    90
  * https://github.com/WayneD/rsync
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    91
  * https://rsync.samba.org
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    92
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    93
The distribution has been built like this:
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    94
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    95
    cd src && """ + build_script + """
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    96
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    97
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    98
        Makarius
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
    99
        """ + Date.Format.date(Date.now()) + "\n")
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   100
    }
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   101
}
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   102
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   103
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   104
  /* Isabelle tool wrapper */
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   105
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   106
  val isabelle_tool =
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   107
    Isabelle_Tool("component_rsync", "build rsync component from source distribution",
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   108
      Scala_Project.here,
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   109
      { args =>
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   110
        var target_dir = Path.current
77755
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
   111
        var build_options = default_build_options
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   112
        var version = default_version
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   113
        var download_url = default_download_url
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   114
        var verbose = false
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   115
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   116
        val getopts = Getopts("""
77755
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
   117
Usage: isabelle component_rsync [OPTIONS]
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   118
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   119
  Options are:
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   120
    -D DIR       target directory (default ".")
77755
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
   121
    -O OPT       add build option
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
   122
    -R OPT       remove build option
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   123
    -U URL       download URL
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   124
                 (default: """" + default_download_url + """")
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   125
    -V VERSION   version (default: """ + default_version + """)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   126
    -v           verbose
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   127
77755
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
   128
  Build rsync component from the specified source distribution.
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   129
77755
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
   130
  The default build options (for ./configure) are:
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
   131
""" + default_build_options.map(opt => "    " + opt + "\n").mkString,
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   132
          "D:" -> (arg => target_dir = Path.explode(arg)),
77755
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
   133
          "O:" -> (arg => build_options = Library.insert(arg)(build_options)),
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
   134
          "R:" -> (arg => build_options = Library.remove(arg)(build_options)),
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   135
          "U:" -> (arg => download_url = arg),
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   136
          "V:" -> (arg => version = arg),
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   137
          "v" -> (_ => verbose = true))
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   138
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   139
        val more_args = getopts(args)
77755
12c8d72df48a clarified build options;
wenzelm
parents: 77754
diff changeset
   140
        if (more_args.nonEmpty) getopts.usage()
77753
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   141
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   142
        val progress = new Console_Progress(verbose = verbose)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   143
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   144
        build_rsync(version = version, download_url = download_url, progress = progress,
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   145
          target_dir = target_dir, build_options = build_options)
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   146
      })
2b5b093a1c08 build rsync from sources, to avoid divergence of protocols on various platforms;
wenzelm
parents:
diff changeset
   147
}