From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6675178267829338112 X-Received: by 2002:a1c:7dc3:: with SMTP id y186mr1544611wmc.13.1554186053252; Mon, 01 Apr 2019 23:20:53 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a1c:b085:: with SMTP id z127ls27336wme.1.experimental-gmail; Mon, 01 Apr 2019 23:20:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlk2zLEdFXdkReZwt7C18HkBcgQzgdMHcGsuQjhUwsNqZyGsXBFdaGr3nWkZyoMGAW02yp X-Received: by 2002:a1c:b48b:: with SMTP id d133mr1398505wmf.6.1554186052650; Mon, 01 Apr 2019 23:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554186052; cv=none; d=google.com; s=arc-20160816; b=aZXOtJXDMjVjvstjBylmZa8oImdKf2h+12kjVQeFzrI1qAgDiGZ80Ja3HGT9Hz3K8y SCtOBDgpdgsz5J1SNemv1F4ouRmnDg16kcAHkZaLeuXauytRQHqzMslpUwVuEwnRsZA2 OkpNX6Ma0Z5+my1KfJNqVSrC8O9XW13hvDPuKA6NACtgCcAt8eYobeX5vVHByvydpSa9 HpRuK2tBp84SH/tP4qbuD0jxRsfL0tqr/E4WmREY3EkfXTdjEMY6T0pn9KGCmUijuBFj P3Qc+pGQ2v4JG39FULuRsmCu41iYdG6aNuTmOc73lX0xRGhr6875wcDb5Zk0QudkaqTv UpUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:to:from; bh=TQyA/XxEjkT8Ix2HvZkDn5OXwovxU6n/kgcsB64fJd4=; b=ib+NmFY8/vlhe1cYwQhHOcLtLuBFELplkliNCjQL7XKvvzRDBG2zbgSSjo4QQRylFP yiwvRuyh1sbGbVDEhHbV7l53hMKyJxf5nRlUSm6MRXsKYKUJEDoBpr5LsJcdmFLeYfBa GfAZTJBXZsJuYLHVJ2hVXviSxgRCxkJjA0s2QyyWBX1ymQGo6V57FixSvr61ynmKLQqZ BixPu8gKlu+bSAljvgEXryw8lleTIe1hmK1ZHLAv0cj/KPY6CClFSInKOJ+UZ65209rg dXJjaXDRsADfVU0bFjw7RJDRYfcWkZm1LY5eQXw5RpOEYm5ND4xvyUROr9hjbY6hFC2b 7GVA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com Return-Path: Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id v1si414348wrd.4.2019.04.01.23.20.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2019 23:20:52 -0700 (PDT) Received-SPF: pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.2 as permitted sender) client-ip=192.35.17.2; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id x326KqKl013123 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 2 Apr 2019 08:20:52 +0200 Received: from md1f2u6c.ad001.siemens.net ([167.87.37.242]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id x326Kp3C016594 for ; Tue, 2 Apr 2019 08:20:52 +0200 From: Jan Kiszka To: isar-users Subject: [PATCH 2/4] Make patch task repeatedly applicable Date: Tue, 2 Apr 2019 08:20:49 +0200 Message-Id: <7f8a9c9bf7040cb3fd3b72d4aaf5920b8c68927c.1554186051.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: References: In-Reply-To: References: X-TUID: K+iHGj7Z0+pO From: Jan Kiszka This allows to rerun the patch task even if it was applied already. This is achieved by recording the executed patch commands and storing them, along with the original patches, in ${S}/.applied_patches and applying them in reverse order before applying new patches. If unpack ran prior to that, .applied_patches was deleted, and nothing is incorrectly reverted. Alternatives to this self-written solution would have been using quilt, which would have added almost 30 MB additional dependencies to our build environment, or even using the OE implementation for the patch task, which would have required importing and adjusting a significant amount of code with only little gain. Signed-off-by: Jan Kiszka --- meta/classes/patch.bbclass | 54 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass index 4c08193..bb203b7 100644 --- a/meta/classes/patch.bbclass +++ b/meta/classes/patch.bbclass @@ -1,13 +1,38 @@ # This software is a part of ISAR. -# Copyright (c) Siemens AG, 2018 +# Copyright (c) Siemens AG, 2018-2019 + +def clean_applied_patches(applied_patches_dir): + import shutil + import subprocess + + if not os.path.exists(applied_patches_dir): + return + + cmds_file = applied_patches_dir + ".patch-commands" + if os.path.exists(cmds_file): + with open(cmds_file, "r") as cmds: + patch_commands = cmds.readlines() + patch_commands.reverse() + for patch in patch_commands: + cmd = patch.split() + cmd.append("-R") + cmdline = " ".join(cmd) + bb.note("Reverting: " + cmdline) + if subprocess.call(cmd) != 0: + bb.fatal("patch reverting failed") + + shutil.rmtree(applied_patches_dir) python do_patch() { + import shutil import subprocess - workdir = d.getVar("WORKDIR", True) + "/" - src_dir = d.getVar("S", True) + workdir = d.getVar("WORKDIR") + "/" + src_dir = d.getVar("S") + + applied_patches_dirs = [] - for src_uri in (d.getVar("SRC_URI", True) or "").split(): + for src_uri in (d.getVar("SRC_URI") or "").split(): try: fetcher = bb.fetch2.Fetch([src_uri], d) @@ -20,6 +45,18 @@ python do_patch() { continue patchdir = fetcher.ud[src_uri].parm.get("patchdir") or src_dir + applied_patches_dir = patchdir + "/.applied_patches/" + + if applied_patches_dir not in applied_patches_dirs: + clean_applied_patches(applied_patches_dir) + bb.utils.mkdirhier(applied_patches_dir) + applied_patches_dirs.append(applied_patches_dir) + + cmds = open(applied_patches_dir + ".patch-commands", "a") + + patch_file = applied_patches_dir + basename + shutil.copyfile(workdir + basename, patch_file) + striplevel = fetcher.ud[src_uri].parm.get("striplevel") or "1" cmd = [ @@ -27,11 +64,16 @@ python do_patch() { "--no-backup-if-mismatch", "-p", striplevel, "--directory", patchdir, - "--input", workdir + basename, + "--input", patch_file, ] - bb.note(" ".join(cmd)) + cmdline = " ".join(cmd) + + bb.note("Applying: " + cmdline) if subprocess.call(cmd) != 0: bb.fatal("patching failed") + + cmds.write(cmdline + "\n") + cmds.close() except bb.fetch2.BBFetchException as e: raise bb.build.FuncFailed(e) } -- 2.16.4