0

lein uberjar2 回続けて実行すると、2 つの異なるビルドが得られます。いくつかのunzip / find / sort / diff shell魔法の後、Maven ファイル、より具体的にはpom.propertiesファイルにたどり着きました。

ここに違いがあります:

< #Tue Jan 14 07:07:50 CET 2014
---
> #Tue Jan 14 07:07:01 CET 2014

Leiningen (したがって Maven) を使用して決定論的な Clojure ビルドを取得するにはどうすればよいですか?

4

2 に答える 2

4

私はlein-voom (私がChouserで維持しているプロジェクト)へのローカル パッチを持っています。これはこれに対処しpom.properties、作業コピーが完全にクリーンな場合にヘッダー時間を VCS (現在は git のみ) コミット時間に修正します。この機能の構成可能性についてはまだ考えていますが、このコミットは来週中に完了すると予想しています。

これだけでは安定したジャーにはなりませんが、最初の些細な部分です。また、興味深いのは、zip ヘッダーを変更する jar 内のファイルのタイムスタンプです。タイムスタンプの正規化も簡単ですが、別の手順です。

決定論的ビルドは lein-voom にとって興味深いものです。これは、アーティファクトを完全に回避して、コミット sha によって依存関係を特定のソース バージョンに直接向けることができるため、一般的に関心のあるプロジェクトです。

lein-voom はかなり新しく、ドキュメントと CLI はかなり粗いですが、コア機能はしっかりしています。GitHub プロジェクトに問題や質問を投稿してください。

于 2014-01-18T04:37:01.550 に答える
1

しばらく前に、Maven を使用した決定論的ビルドについて取り上げた記事を書きました。ここで重要なポイントを抽出しました。

アセンブリ プラグインを使用して、次のように構成します。

src/main/assembly/zip.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  <id>deterministic</id>
  <baseDirectory>/</baseDirectory>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.build.directory}/classes</directory>
      <outputDirectory>/</outputDirectory>
    </fileSet>
  </fileSets>
</assembly>

MANIFEST.MF最後に余分な CRLF を覚えている独自のものを追加しないと、無効になります。

src/main/resources/META-INF/MANIFEST.MF:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: yourapp
Build-Jdk: 1.7.0

pom.xml にいくつかのプラグインを追加します。

pom.xml:

<plugins>

... other plugins ...

    <!-- Step 1: Set all timestamps to same value -->
    <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
      <execution>
        <id>1-touch-classes</id>
        <phase>prepare-package</phase>
        <configuration>
          <target>
            <touch datetime="01/01/2000 00:10:00 am">
              <fileset dir="target/classes"/>
            </touch>
          </target>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
    </plugin>

    <!-- Step 2: Assemble as a ZIP to avoid MANIFEST.MF timestamp -->
    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <configuration>
      <descriptors>
        <descriptor>src/main/assembly/zip.xml</descriptor>
      </descriptors>
    </configuration>
    <executions>
      <execution>
        <id>2-make-assembly</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
    </plugin>

    <!-- Step 3: Rename ZIP as JAR -->
    <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
      <execution>
        <id>3-rename-assembly</id>
        <phase>package</phase>
        <configuration>
          <target>
            <move file="${project.build.directory}/${project.build.finalName}-deterministic.zip"
                  tofile="${project.build.directory}/${project.build.finalName}-deterministic.jar"/>
          </target>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
    </plugin>

... more plugins ...

</plugins>

これにより確定的な JAR が作成されますが、JVM の正確なバージョンとビルドに使用するオペレーティング システムに依存します。これを克服するには、Bitcoin Core プロジェクトで使用されている gitian アプローチを調べて、VirtualBox 環境内で特定の JVM を強制する必要があります。このようにして、複数の開発者がソースから個別にビルドし、バイナリに署名して合意していることを示すことができます。特定のしきい値に達すると、コードは確定的であることが証明され、リリースできると見なされます。

于 2014-03-13T17:23:48.567 に答える