Commit ea1779a2 authored by Yureka's avatar Yureka
Browse files

electron-source.electron_26: init at 26.2.3

parent b2a7b75d
Loading
Loading
Loading
Loading
+204 −0
Original line number Diff line number Diff line
{ lib
, stdenv
, chromium
, nodejs
, python3
, fetchYarnDeps
, fetchNpmDeps
, fixup_yarn_lock
, npmHooks
, yarn
, substituteAll
, libnotify
, unzip
, pkgs
, pkgsBuildHost

, info
}:

let
  fetchdep = dep: let
    opts = removeAttrs dep ["fetcher"];
  in pkgs.${dep.fetcher} opts;

in (chromium.override { upstream-info = info.chromium; }).mkDerivation (base: {
  packageName = "electron";
  inherit (info) version;
  buildTargets = [ "electron:electron_dist_zip" ];

  nativeBuildInputs = base.nativeBuildInputs ++ [ nodejs yarn fixup_yarn_lock unzip npmHooks.npmConfigHook ];
  buildInputs = base.buildInputs ++ [ libnotify ];

  electronOfflineCache = fetchYarnDeps {
    yarnLock = (fetchdep info.deps."src/electron") + "/yarn.lock";
    sha256 = info.electron_yarn_hash;
  };
  npmDeps = fetchNpmDeps {
    src = fetchdep info.deps."src";
    sourceRoot = "source/third_party/node";
    hash = info.chromium_npm_hash;
  };

  src = null;

  patches = base.patches ++ [
    (substituteAll {
      name = "version.patch";
      src = if lib.versionAtLeast info.version "27" then ./version.patch else ./version-old.patch;
      inherit (info) version;
    })
  ];

  unpackPhase = ''
    runHook preUnpack
  '' + (
    lib.concatStrings (lib.mapAttrsToList (path: dep: ''
      mkdir -p ${builtins.dirOf path}
      cp -r ${fetchdep dep}/. ${path}
      chmod u+w -R ${path}
    '') info.deps)
  ) + ''
    sourceRoot=src
    runHook postUnpack
  '';

  npmRoot = "third_party/node";

  postPatch = ''
    mkdir -p third_party/jdk/current/bin

    echo 'build_with_chromium = true' >> build/config/gclient_args.gni
    echo 'checkout_google_benchmark = false' >> build/config/gclient_args.gni
    echo 'checkout_android = false' >> build/config/gclient_args.gni
    echo 'checkout_android_prebuilts_build_tools = false' >> build/config/gclient_args.gni
    echo 'checkout_android_native_support = false' >> build/config/gclient_args.gni
    echo 'checkout_ios_webkit = false' >> build/config/gclient_args.gni
    echo 'checkout_nacl = false' >> build/config/gclient_args.gni
    echo 'checkout_openxr = false' >> build/config/gclient_args.gni
    echo 'checkout_rts_model = false' >> build/config/gclient_args.gni
    echo 'checkout_src_internal = false' >> build/config/gclient_args.gni
    echo 'cros_boards = ""' >> build/config/gclient_args.gni
    echo 'cros_boards_with_qemu_images = ""' >> build/config/gclient_args.gni
    echo 'generate_location_tags = true' >> build/config/gclient_args.gni

    echo 'LASTCHANGE=${info.deps."src".rev}-refs/heads/master@{#0}'        > build/util/LASTCHANGE
    echo "$SOURCE_DATE_EPOCH"                                              > build/util/LASTCHANGE.committime

    cat << EOF > gpu/config/gpu_lists_version.h
    /* Generated by lastchange.py, do not edit.*/
    #ifndef GPU_CONFIG_GPU_LISTS_VERSION_H_
    #define GPU_CONFIG_GPU_LISTS_VERSION_H_
    #define GPU_LISTS_VERSION "${info.deps."src".rev}"
    #endif  // GPU_CONFIG_GPU_LISTS_VERSION_H_
    EOF

    cat << EOF > skia/ext/skia_commit_hash.h
    /* Generated by lastchange.py, do not edit.*/
    #ifndef SKIA_EXT_SKIA_COMMIT_HASH_H_
    #define SKIA_EXT_SKIA_COMMIT_HASH_H_
    #define SKIA_COMMIT_HASH "${info.deps."src/third_party/skia".rev}-"
    #endif  // SKIA_EXT_SKIA_COMMIT_HASH_H_
    EOF

    echo -n '${info.deps."src/third_party/dawn".rev}'                     > gpu/webgpu/DAWN_VERSION

    (
      cd electron
      export HOME=$TMPDIR/fake_home
      yarn config --offline set yarn-offline-mirror $electronOfflineCache
      fixup_yarn_lock yarn.lock
      yarn install --offline --frozen-lockfile --ignore-scripts --no-progress --non-interactive
    )

    (
      cd ..
      PATH=$PATH:${lib.makeBinPath (with pkgsBuildHost; [ jq git ])}
      config=src/electron/patches/config.json
      for key in $(jq -r "keys[]" $config)
      do
        value=$(jq -r ".\"$key\"" $config)
        echo patching $value
        for patch in $(cat $key/.patches)
        do
          git apply -p1 --directory=$value $key/$patch
        done
      done
    )
  '' + base.postPatch;

  preConfigure = ''
    (
      cd third_party/node
      grep patch update_npm_deps | sh
    )
  '' + (base.preConfigure or "");

  gnFlags = rec {
    # build/args/release.gn
    is_component_build = false;
    is_official_build = true;
    rtc_use_h264 = proprietary_codecs;
    is_component_ffmpeg = true;

    # build/args/all.gn
    is_electron_build = true;
    root_extra_deps = [ "//electron" ];
    node_module_version = info.modules;
    v8_promise_internal_field_count = 1;
    v8_embedder_string = "-electron.0";
    v8_enable_snapshot_native_code_counters = false;
    v8_scriptormodule_legacy_lifetime = true;
    v8_enable_javascript_promise_hooks = true;
    enable_cdm_host_verification = false;
    proprietary_codecs = true;
    ffmpeg_branding = "Chrome";
    enable_printing = true;
    angle_enable_vulkan_validation_layers = false;
    dawn_enable_vulkan_validation_layers = false;
    enable_pseudolocales = false;
    allow_runtime_configurable_key_storage = true;
    enable_cet_shadow_stack = false;
    is_cfi = false;
    use_qt = false;

    enable_widevine = false;
    use_perfetto_client_library = false;
    enable_check_raw_ptr_fields = false;
  } // lib.optionalAttrs (lib.versionOlder info.version "26")  {
    use_gnome_keyring = false;
  };

  installPhase = ''
    mkdir -p $libExecPath
    unzip -d $libExecPath out/Release/dist.zip
  '';

  requiredSystemFeatures = [ "big-parallel" ];

  passthru = {
    inherit info;
    headers = stdenv.mkDerivation rec {
      name = "node-v${info.node}-headers.tar.xz";
      nativeBuildInputs = [ python3 ];
      src = fetchdep info.deps."src/third_party/electron_node";
      buildPhase = ''
        make tar-headers
      '';
      installPhase = ''
        mv ${name} $out
      '';
    };
  };

  meta = with lib; {
    description = "Cross platform desktop application shell";
    homepage = "https://github.com/electron/electron";
    platforms = lib.platforms.linux;
    license = licenses.mit;
    maintainers = with maintainers; [ yuka ];
    mainProgram = "electron";
    hydraPlatforms = lib.optionals (!(hasInfix "alpha" info.version) && !(hasInfix "beta" info.version)) ["aarch64-linux" "x86_64-linux"];
    timeout = 172800; # 48 hours (increased from the Hydra default of 10h)
  };
})
+12 −0
Original line number Diff line number Diff line
{ lib, callPackage }:

let
  versions = lib.importJSON ./info.json;
in
  lib.mapAttrs' (version: info:
    lib.nameValuePair "electron_${version}" (
      let
        electron-unwrapped = callPackage ./common.nix { inherit info; };
      in callPackage ./wrapper.nix { inherit electron-unwrapped; }
    )
  ) versions
+2558 −0

File added.

Preview size limit exceeded, changes collapsed.

+277 −0
Original line number Diff line number Diff line
#! /usr/bin/env nix-shell
#! nix-shell -i python -p python3.pkgs.joblib python3.pkgs.click python3.pkgs.click-log nix nix-prefetch-git nix-universal-prefetch prefetch-yarn-deps prefetch-npm-deps

import logging
import click_log
import click
import random
import traceback
import csv
import base64
import os
import re
import tempfile
import subprocess
import json
import sys
from joblib import Parallel, delayed, Memory
from codecs import iterdecode
from datetime import datetime
from urllib.request import urlopen

depot_tools_checkout = tempfile.TemporaryDirectory()
subprocess.check_call([
    "nix-prefetch-git",
    "--builder", "--quiet",
    "--url", "https://chromium.googlesource.com/chromium/tools/depot_tools",
    "--out", depot_tools_checkout.name,
    "--rev", "7a69b031d58081d51c9e8e89557b343bba8518b1"])
sys.path.append(depot_tools_checkout.name)

import gclient_eval
import gclient_utils

memory = Memory("cache", verbose=0)

@memory.cache
def get_repo_hash(fetcher, args):
    cmd = ['nix-universal-prefetch', fetcher]
    for arg_name, arg in args.items():
        cmd.append(f'--{arg_name}')
        cmd.append(arg)

    print(" ".join(cmd), file=sys.stderr)
    out = subprocess.check_output(cmd)
    return out.decode('utf-8').strip()

@memory.cache
def _get_yarn_hash(file):
    print(f'prefetch-yarn-deps', file=sys.stderr)
    with tempfile.TemporaryDirectory() as tmp_dir:
        with open(tmp_dir + '/yarn.lock', 'w') as f:
            f.write(file)
        return subprocess.check_output(['prefetch-yarn-deps', tmp_dir + '/yarn.lock']).decode('utf-8').strip()
def get_yarn_hash(repo, yarn_lock_path = 'yarn.lock'):
    return _get_yarn_hash(repo.get_file(yarn_lock_path))

@memory.cache
def _get_npm_hash(file):
    print(f'prefetch-npm-deps', file=sys.stderr)
    with tempfile.TemporaryDirectory() as tmp_dir:
        with open(tmp_dir + '/package-lock.json', 'w') as f:
            f.write(file)
        return subprocess.check_output(['prefetch-npm-deps', tmp_dir + '/package-lock.json']).decode('utf-8').strip()
def get_npm_hash(repo, package_lock_path = 'package-lock.json'):
    return _get_npm_hash(repo.get_file(package_lock_path))

class Repo:
    def __init__(self):
        self.deps = {}
        self.hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="

    def get_deps(self, repo_vars, path):
        print("evaluating " + json.dumps(self, default = vars), file=sys.stderr)

        deps_file = self.get_file("DEPS")
        evaluated = gclient_eval.Parse(deps_file, filename='DEPS')

        repo_vars = dict(evaluated["vars"]) | repo_vars

        prefix = f"{path}/" if evaluated.get("use_relative_paths", False) else ""

        self.deps = {
            prefix + dep_name: repo_from_dep(dep)
            for dep_name, dep in evaluated["deps"].items()
            if (gclient_eval.EvaluateCondition(dep["condition"], repo_vars) if "condition" in dep else True) and repo_from_dep(dep) != None
        }

        for key in evaluated.get("recursedeps", []):
            dep_path = prefix + key
            if dep_path in self.deps and dep_path != "src/third_party/squirrel.mac":
                self.deps[dep_path].get_deps(repo_vars, dep_path)

    def prefetch(self):
        self.hash = get_repo_hash(self.fetcher, self.args)

    def prefetch_all(self):
        return sum([dep.prefetch_all() for [_, dep] in self.deps.items()], [delayed(self.prefetch)()])

    def flatten_repr(self):
        return {
            "fetcher": self.fetcher,
            "hash": self.hash,
            **self.args
        }

    def flatten(self, path):
        out = {
            path: self.flatten_repr()
        }
        for dep_path, dep in self.deps.items():
            out |= dep.flatten(dep_path)
        return out

class GitRepo(Repo):
    def __init__(self, url, rev):
        super().__init__()
        self.fetcher = 'fetchgit'
        self.args = {
            "url": url,
            "rev": rev,
        }

class GitHubRepo(Repo):
    def __init__(self, owner, repo, rev):
        super().__init__()
        self.fetcher = 'fetchFromGitHub'
        self.args = {
            "owner": owner,
            "repo": repo,
            "rev": rev,
        }

    def get_file(self, filepath):
        return urlopen(f"https://raw.githubusercontent.com/{self.args['owner']}/{self.args['repo']}/{self.args['rev']}/{filepath}").read().decode('utf-8')

class GitilesRepo(Repo):
    def __init__(self, url, rev):
        super().__init__()
        self.fetcher = 'fetchFromGitiles'
        #self.fetcher = 'fetchgit'
        self.args = {
            "url": url,
            "rev": rev,
            #"fetchSubmodules": "false",
        }

        if url == "https://chromium.googlesource.com/chromium/src.git":
            self.args['postFetch'] = "rm -r $out/third_party/blink/web_tests; "
            self.args['postFetch'] += "rm -r $out/third_party/hunspell/tests; "
            self.args['postFetch'] += "rm -r $out/content/test/data; "
            self.args['postFetch'] += "rm -r $out/courgette/testdata; "
            self.args['postFetch'] += "rm -r $out/extensions/test/data; "
            self.args['postFetch'] += "rm -r $out/media/test/data; "

    def get_file(self, filepath):
        return base64.b64decode(urlopen(f"{self.args['url']}/+/{self.args['rev']}/{filepath}?format=TEXT").read()).decode('utf-8')

def repo_from_dep(dep):
    if "url" in dep:
        url, rev = gclient_utils.SplitUrlRevision(dep["url"])

        search_object = re.search(r'https://github.com/(.+)/(.+?)(\.git)?$', url)
        if search_object:
            return GitHubRepo(search_object.group(1), search_object.group(2), rev)

        if re.match(r'https://.+.googlesource.com', url):
            return GitilesRepo(url, rev)

        return GitRepo(url, rev)
    else:
        # Not a git dependency; skip
        return None

def get_gn_source(repo):
    gn_pattern = r"'gn_version': 'git_revision:([0-9a-f]{40})'"
    gn_commit = re.search(gn_pattern, repo.get_file("DEPS")).group(1)
    gn = subprocess.check_output([
        "nix-prefetch-git",
        "--quiet",
        "https://gn.googlesource.com/gn",
        "--rev", gn_commit
        ])
    gn = json.loads(gn)
    return {
        "gn": {
            "version": datetime.fromisoformat(gn["date"]).date().isoformat(),
            "url": gn["url"],
            "rev": gn["rev"],
            "sha256": gn["sha256"]
        }
    }

def get_electron_info(major_version):
    electron_releases = json.loads(urlopen("https://releases.electronjs.org/releases.json").read())
    major_version_releases = filter(lambda item: item["version"].startswith(f"{major_version}."), electron_releases)
    m = max(major_version_releases, key=lambda item: item["date"])

    rev=f"v{m['version']}"

    electron_repo = GitHubRepo("electron", "electron", rev)
    electron_repo.recurse = True

    electron_repo.get_deps({
        f"checkout_{platform}": platform == "linux"
        for platform in ["ios", "chromeos", "android", "mac", "win", "linux"]
    }, "src/electron")

    return (major_version, m, electron_repo)

logger = logging.getLogger(__name__)
click_log.basic_config(logger)

@click.group()
def cli():
    pass

@cli.command("eval")
@click.option("--version", help="The major version, e.g. '23'")
def eval(version):
    (_, _, repo) = electron_repo = get_electron_info(version)
    tree = electron_repo.flatten("src/electron")
    print(json.dumps(tree, indent=4, default = vars))

def get_update(repo):
    (major_version, m, electron_repo) = repo

    tasks = electron_repo.prefetch_all()
    a = lambda: (
        ("electron_yarn_hash", get_yarn_hash(electron_repo))
    )
    tasks.append(delayed(a)())
    a = lambda: (
        ("chromium_npm_hash", get_npm_hash(electron_repo.deps["src"], "third_party/node/package-lock.json"))
    )
    tasks.append(delayed(a)())
    random.shuffle(tasks)

    task_results = {n[0]: n[1] for n in Parallel(n_jobs=3, require='sharedmem', return_as="generator")(tasks) if n != None}

    tree = electron_repo.flatten("src/electron")

    return (f"{major_version}", {
      "deps": tree,
      **{key: m[key] for key in ["version", "modules", "chrome", "node"]},
      "chromium": {
          "version": m['chrome'],
          "deps": get_gn_source(electron_repo.deps["src"])
      },
      **task_results
    })

@cli.command("update")
@click.option("--version", help="The major version, e.g. '23'")
def update(version):
    try:
        with open('info.json', 'r') as f:
            old_info = json.loads(f.read())
    except:
        old_info = {}
    repo = get_electron_info(version)
    update = get_update(repo)
    out = old_info | { update[0]: update[1] }
    with open('info.json', 'w') as f:
        f.write(json.dumps(out, indent=4, default = vars))
        f.write('\n')

@cli.command("update-all")
def update_all():
    repos = Parallel(n_jobs=2, require='sharedmem')(delayed(get_electron_info)(major_version) for major_version in range(27, 24, -1))
    out = {n[0]: n[1] for n in Parallel(n_jobs=2, require='sharedmem')(delayed(get_update)(repo) for repo in repos)}

    with open('info.json', 'w') as f:
        f.write(json.dumps(out, indent=4, default = vars))
        f.write('\n')

if __name__ == "__main__":
    cli()
+42 −0
Original line number Diff line number Diff line
diff --git a/electron/BUILD.gn b/electron/BUILD.gn
index c905891eb8..f2cf11fe88 100644
--- a/electron/BUILD.gn
+++ b/electron/BUILD.gn
@@ -111,8 +111,6 @@ electron_version = exec_script("script/print-version.py",
                                [],
                                "trim string",
                                [
-                                 ".git/packed-refs",
-                                 ".git/HEAD",
                                  "script/lib/get-version.js",
                                ])
 
diff --git a/electron/script/lib/get-version.js b/electron/script/lib/get-version.js
index 45a120482b..ddaf8ab60e 100644
--- a/electron/script/lib/get-version.js
+++ b/electron/script/lib/get-version.js
@@ -1,22 +1 @@
-const { spawnSync } = require('child_process');
-const path = require('path');
-
-module.exports.getElectronVersion = () => {
-  // Find the nearest tag to the current HEAD
-  // This is equivilant to our old logic of "use a value in package.json" for the following reasons
-  //
-  // 1. Whenever we updated the package.json we ALSO pushed a tag with the same version
-  // 2. Whenever we _reverted_ a bump all we actually did was push a commit that deleted the tag and changed the version number back
-  //
-  // The only difference in the "git describe" technique is that technically a commit can "change" it's version
-  // number if a tag is created / removed retroactively.  i.e. the first time a commit is pushed it will be 1.2.3
-  // and after the tag is made rebuilding the same commit will result in it being 1.2.4
-  const output = spawnSync('git', ['describe', '--tags', '--abbrev=0'], {
-    cwd: path.resolve(__dirname, '..', '..')
-  });
-  if (output.status !== 0) {
-    console.error(output.stderr);
-    throw new Error('Failed to get current electron version');
-  }
-  return output.stdout.toString().trim().replace(/^v/g, '');
-};
+module.exports.getElectronVersion = () => "@version@";
Loading