|
| 1 | +require "fileutils" |
| 2 | +require "json" |
| 3 | + |
| 4 | +include FileUtils::Verbose |
| 5 | + |
| 6 | +def sh(*args, **kwargs) |
| 7 | + puts "::group::$ #{args.join(" ")}" |
| 8 | + system(*args, exception: true, **kwargs) |
| 9 | + puts "::endgroup::" |
| 10 | +end |
| 11 | + |
| 12 | +os = case RbConfig::CONFIG['host_os'] |
| 13 | +in /linux/ then "linux" |
| 14 | +in /darwin/ then "darwin" |
| 15 | +end |
| 16 | + |
| 17 | +arch = case RbConfig::CONFIG['host_cpu'] |
| 18 | +in /amd64|x86_64|x64/ then "amd64" |
| 19 | +in /arm64|aarch64/ then "aarch64" |
| 20 | +end |
| 21 | + |
| 22 | +url = "https://github.com/graalvm/graal-languages-ea-builds/raw/HEAD/truffleruby/versions/latest-jvm-#{os}-#{arch}.url" |
| 23 | +puts url |
| 24 | +url = `curl -Ls #{url}` |
| 25 | +puts url |
| 26 | + |
| 27 | +ea_build_archive = "truffleruby-jvm-ea-build.tar.gz" |
| 28 | + |
| 29 | +unless File.exist? ea_build_archive |
| 30 | + sh "wget", "--progress=dot:mega", "-O", ea_build_archive, url |
| 31 | +end |
| 32 | + |
| 33 | +ea_build = `tar tf truffleruby-jvm-ea-build.tar.gz | head -1`[/^(.+?)\//, 1] |
| 34 | +puts "EA build dir: #{ea_build}" |
| 35 | + |
| 36 | +unless Dir.exist? ea_build |
| 37 | + sh "tar", "xf", ea_build_archive |
| 38 | +end |
| 39 | + |
| 40 | +ea_files = Dir.glob("**/{*,.*}", base: ea_build) |
| 41 | + |
| 42 | +ea_commit_info = File.read("#{ea_build}/release")[/COMMIT_INFO=(.+)/, 1] |
| 43 | +ea_truffle_commit = JSON.load(ea_commit_info).fetch("truffle").fetch("commit.rev") |
| 44 | +puts "EA build Truffle commit: #{ea_truffle_commit}" |
| 45 | + |
| 46 | +# Build with the same truffle version as in ea_build |
| 47 | +sh "git", "checkout", ea_truffle_commit, chdir: "../graal" |
| 48 | +# unset JAVA_HOME to download the correct JDK from graal common.json |
| 49 | +ENV.delete "JAVA_HOME" |
| 50 | +sh({ "JT_IMPORTS_DONT_ASK" => "true" }, "bin/jt", "build") |
| 51 | + |
| 52 | +master_build = "mxbuild/truffleruby-jvm" |
| 53 | + |
| 54 | +master_files = Dir.glob("**/{*,.*}", base: master_build) |
| 55 | + |
| 56 | +result = "truffleruby-jvm-ea-master-build" |
| 57 | + |
| 58 | +EXPECTED_DIFFERENT = %w[ |
| 59 | + jvm |
| 60 | +] |
| 61 | + |
| 62 | +OVERRIDE_WITH_EA_BUILD = %w[ |
| 63 | + jvm |
| 64 | + release |
| 65 | +] |
| 66 | + |
| 67 | +EXPECTED_EXTRA_IN_EA_BUILD = %w[ |
| 68 | + license-information-user-manual.zip |
| 69 | + DISCLAIMER.txt |
| 70 | + |
| 71 | + modules/nativebridge.jar |
| 72 | + modules/sulong-enterprise-native.jar |
| 73 | + modules/sulong-enterprise.jar |
| 74 | + modules/truffle-enterprise.jar |
| 75 | +] |
| 76 | + |
| 77 | +EXPECTED_EXTRA_IN_MASTER_BUILD = %w[ |
| 78 | + 3rd_party_licenses_truffleruby.txt |
| 79 | +] |
| 80 | + |
| 81 | +# There might be more or less files in these directories, that's OK, these are "Ruby home" files |
| 82 | +CHANGES_ALLOWED_IN_MASTER_BUILD = %w[ |
| 83 | + bin |
| 84 | + doc |
| 85 | + lib |
| 86 | + logo |
| 87 | + src |
| 88 | +] |
| 89 | + |
| 90 | +def check_diff(a_files, b_files, expected_extra) |
| 91 | + diff = a_files - b_files |
| 92 | + diff = diff.reject { |path| expected_extra.any? { |e| path.start_with?(e) } } |
| 93 | + unless diff.empty? |
| 94 | + puts diff |
| 95 | + raise "ERROR: Unexpected files!" |
| 96 | + end |
| 97 | +end |
| 98 | + |
| 99 | +puts "extra master files (master_files - ea_files)" |
| 100 | +check_diff(master_files, ea_files, EXPECTED_EXTRA_IN_MASTER_BUILD + CHANGES_ALLOWED_IN_MASTER_BUILD + EXPECTED_DIFFERENT) |
| 101 | + |
| 102 | +puts "extra EA files (ea_files - master_files)" |
| 103 | +check_diff(ea_files, master_files, EXPECTED_EXTRA_IN_EA_BUILD + EXPECTED_DIFFERENT) |
| 104 | + |
| 105 | +rm_rf result |
| 106 | +cp_r master_build, result |
| 107 | + |
| 108 | +EXPECTED_EXTRA_IN_MASTER_BUILD.each { |path| |
| 109 | + rm_r "#{result}/#{path}" if File.exist? "#{result}/#{path}" |
| 110 | +} |
| 111 | + |
| 112 | +(EXPECTED_EXTRA_IN_EA_BUILD + OVERRIDE_WITH_EA_BUILD).each { |path| |
| 113 | + rm_r "#{result}/#{path}" if File.exist? "#{result}/#{path}" |
| 114 | + cp_r "#{ea_build}/#{path}", "#{result}/#{path}" |
| 115 | +} |
| 116 | + |
| 117 | +result_files = Dir.glob("**/{*,.*}", base: result) |
| 118 | +puts "extra result files (result_files - ea_files)" |
| 119 | +check_diff(result_files, ea_files, []) |
| 120 | + |
| 121 | +# Run specs after to make sure it works correctly: |
| 122 | +sh "bin/jt", "-u", "#{Dir.pwd}/#{result}", "test", "fast" |
0 commit comments