From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web12.2100.1584482273550111173 for ; Tue, 17 Mar 2020 14:57:53 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: nathaniel.l.desimone@intel.com) IronPort-SDR: dd4iOsKAJhbTtiNwNC270GqWvjEfD95/i1pruM7MvgYGuQFu1OUf7ja4+75pfFo4xpJnLNdQ5f 0/JSJAWbIeEg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2020 14:57:53 -0700 IronPort-SDR: Mapf9GfiwSUZGHV3Rwg78RaOjSK24HOyIYRmn5M+7rFhr5343r+lOQMmMlko6vrRQcBwwW00cR TbPqRDTngwyQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,565,1574150400"; d="scan'208";a="445639570" Received: from orsmsx104.amr.corp.intel.com ([10.22.225.131]) by fmsmga006.fm.intel.com with ESMTP; 17 Mar 2020 14:57:52 -0700 Received: from orsmsx163.amr.corp.intel.com (10.22.240.88) by ORSMSX104.amr.corp.intel.com (10.22.225.131) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 17 Mar 2020 14:57:51 -0700 Received: from orsmsx114.amr.corp.intel.com ([169.254.8.205]) by ORSMSX163.amr.corp.intel.com ([169.254.9.97]) with mapi id 14.03.0439.000; Tue, 17 Mar 2020 14:57:51 -0700 From: "Nate DeSimone" To: "devel@edk2.groups.io" , "Desimone, Ashley E" CC: "Pandya, Puja" , "Bjorge, Erik C" Subject: Re: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Initial commit of checkout pin Thread-Topic: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Initial commit of checkout pin Thread-Index: AQHV+78gGbsSZBAqc0arg+X9K+lkU6hNVqPA Date: Tue, 17 Mar 2020 21:57:51 +0000 Message-ID: <02A34F284D1DA44BB705E61F7180EF0AB5DF9355@ORSMSX114.amr.corp.intel.com> References: <20200316181652.29664-1-ashley.e.desimone@intel.com> In-Reply-To: <20200316181652.29664-1-ashley.e.desimone@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiOWI0Zjg2ZDctZGM1YS00ZmVmLWI0NDUtY2ZiMWJjYjExNTg4IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiXC9oZnNabG5XYnJrQVdJaWdDVnVSZExoRkhmSlFOWDFhbFBTdmdnSkRRa084bk5Mak52QmZaRzg4NTUxTGIzTDYifQ== x-ctpclassification: CTP_NT x-originating-ip: [10.22.254.140] MIME-Version: 1.0 Return-Path: nathaniel.l.desimone@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Nate DeSimone -----Original Message----- From: devel@edk2.groups.io On Behalf Of Desimone, A= shley E Sent: Monday, March 16, 2020 11:17 AM To: devel@edk2.groups.io Cc: Desimone, Nathaniel L ; Pandya, Puja <= puja.pandya@intel.com>; Bjorge, Erik C Subject: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Initial comm= it of checkout pin Command to allow a user to checkout the contents of a previously commited = PIN file. Signed-off-by: Ashley E Desimone Cc: Nate DeSimone Cc: Puja Pandya Cc: Erik Bjorge --- edkrepo/commands/arguments/checkout_pin_args.py | 11 +++ edkrepo/commands/checkout_pin_command.py | 106 +++++++++++++++++++= +++++ edkrepo/commands/humble/checkout_pin_humble.py | 14 ++++ edkrepo/common/edkrepo_exception.py | 4 + 4 files changed, 135 insertions(+) create mode 100644 edkrepo/commands/arguments/checkout_pin_args.py create mode 100644 edkrepo/commands/checkout_pin_command.py create mode 100644 edkrepo/commands/humble/checkout_pin_humble.py diff --git a/edkrepo/commands/arguments/checkout_pin_args.py b/edkrepo/com= mands/arguments/checkout_pin_args.py new file mode 100644 index 0000000..abd01b3 --- /dev/null +++ b/edkrepo/commands/arguments/checkout_pin_args.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 +# +## @file +# checkout_pin_args.py +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
#=20 +SPDX-License-Identifier: BSD-2-Clause-Patent # + +COMMAND_DESCRIPTION =3D ('Checks out the revisions described in a PIN fil= e in ' + 'an existing workpace of the same project') diff --git a/edkrepo/commands/checkout_pin_command.py b/edkrepo/commands/c= heckout_pin_command.py new file mode 100644 index 0000000..a2afc41 --- /dev/null +++ b/edkrepo/commands/checkout_pin_command.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +# +## @file +# checkout_pin_command.py +# +# Copyright (c) 2017 - 2020, Intel Corporation. All rights=20 +reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # + +import os + +from git import Repo + +from edkrepo.commands.edkrepo_command import EdkrepoCommand,=20 +OverrideArgument import edkrepo.commands.arguments.checkout_pin_args as= =20 +arguments import edkrepo.commands.humble.checkout_pin_humble as humble=20 +from edkrepo.common.common_repo_functions import=20 +sparse_checkout_enabled, reset_sparse_checkout, sparse_checkout from=20 +edkrepo.common.common_repo_functions import check_dirty_repos,=20 +checkout_repos from edkrepo.common.humble import SPARSE_CHECKOUT,=20 +SPARSE_RESET from edkrepo.common.edkrepo_exception import=20 +EdkrepoInvalidParametersException, EdkrepoProjectMismatchException from= =20 +edkrepo.config.config_factory import get_workspace_path,=20 +get_workspace_manifest from edkrepo_manifest_parser.edk_manifest import= =20 +ManifestXml + +class CheckoutPinCommand(EdkrepoCommand): + def __init__(self): + super().__init__() + + def get_metadata(self): + metadata =3D {} + metadata['name'] =3D 'checkout-pin' + metadata['help-text'] =3D arguments.COMMAND_DESCRIPTION + metadata['alias'] =3D 'chp' + args =3D [] + metadata['arguments'] =3D args + args.append({'name' : 'pinfile', + 'positional' : True, + 'position' : 0, + 'required' : True, + 'help-text' : arguments.PIN_FILE_HELP}) + args.append(OverrideArgument) + return metadata + + def run_command(self, args, config): + workspace_path =3D get_workspace_path() + manifest =3D get_workspace_manifest() + pin_path =3D self.__get_pin_path(args, workspace_path, config['cf= g_file'].manifest_repo_abs_local_path, manifest) + pin =3D ManifestXml(pin_path) + manifest_sources =3D manifest.get_repo_sources(manifest.general_c= onfig.current_combo) + check_dirty_repos(manifest, workspace_path) + for source in manifest_sources: + local_path =3D os.path.join(workspace_path, source.root) + repo =3D Repo(local_path) + origin =3D repo.remotes.origin + origin.fetch() + self.__pin_matches_project(pin, manifest, workspace_path) + manifest.write_current_combo(pin.general_config.current_combo) + sparse_enabled =3D sparse_checkout_enabled(workspace_path, manife= st_sources) + if sparse_enabled: + print(SPARSE_RESET) + reset_sparse_checkout(workspace_path, manifest_sources) + pin_repo_sources =3D pin.get_repo_sources(pin.general_config.curr= ent_combo) + try: + checkout_repos(args.verbose, args.override, pin_repo_sources,= workspace_path, manifest) + finally: + if sparse_enabled: + print(SPARSE_CHECKOUT) + sparse_checkout(workspace_path, pin_repo_sources,=20 + manifest) + + def __get_pin_path(self, args, workspace_path, manifest_repo_path, ma= nifest): + if os.path.isabs(args.pinfile) and os.path.isfile(args.pinfile): + return os.path.normpath(args.pinfile) + elif os.path.isfile(os.path.join(manifest_repo_path, os.path.norm= path(manifest.general_config.pin_path), args.pinfile)): + return os.path.join(manifest_repo_path, os.path.normpath(mani= fest.general_config.pin_path), args.pinfile) + elif os.path.isfile(os.path.join(manifest_repo_path, args.pinfile= )): + return os.path.join(manifest_repo_path, args.pinfile) + elif os.path.isfile(os.path.join(workspace_path, args.pinfile)): + return os.path.join(workspace_path, args.pinfile) + elif os.path.isfile(os.path.join(workspace_path, 'repo', args.pin= file)): + return os.path.join(workspace_path, 'repo', args.pinfile) + elif not os.path.isfile(os.path.join(workspace_path, args.pinfile= )) and os.path.dirname(args.pinfile) is None: + for dirpath, dirnames, filenames in os.walk(workspace_path): + if args.pinfile in filenames: + return os.path.join(dirpath, args.pinfile) + else: + raise EdkrepoInvalidParametersException(humble.NOT_FOUND) + + def __pin_matches_project(self, pin, manifest, workspace_path): + if pin.project_info.codename !=3D manifest.project_info.codename: + raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATC= H) + elif not set(pin.remotes).issubset(set(manifest.remotes)): + raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATC= H) + elif pin.general_config.current_combo not in [c.name for c in man= ifest.combinations]: + raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATC= H) + combo_name =3D pin.general_config.current_combo + pin_sources =3D pin.get_repo_sources(combo_name) + pin_root_remote =3D {source.root:source.remote_name for source in= pin_sources} + manifest_sources =3D manifest.get_repo_sources(combo_name) + manifest_root_remote =3D {source.root:source.remote_name for sour= ce in manifest_sources} + if set(pin_root_remote.items()).isdisjoint(set(manifest_root_remo= te.items())): + raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATC= H) + pin_root_commit =3D {source.root:source.commit for source in pin_= sources} + for source in pin_sources: + source_repo_path =3D os.path.join(workspace_path, source.root= ) + repo =3D Repo(source_repo_path) + if repo.commit(pin_root_commit[source.root]) is None: + raise EdkrepoProjectMismatchException(humble.NOT_FOUND) diff --git a/edkrepo/commands/humble/checkout_pin_humble.py b/edkrepo/comm= ands/humble/checkout_pin_humble.py new file mode 100644 index 0000000..b5a9cfb --- /dev/null +++ b/edkrepo/commands/humble/checkout_pin_humble.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +# +## @file +# checkout_pin_humble.py +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
#=20 +SPDX-License-Identifier: BSD-2-Clause-Patent # + +CHP_EXIT =3D 'Exiting without checkout out PIN data.' +NOT_FOUND =3D 'The selected PIN file was not found.' +MANIFEST_MISMATCH =3D ('The selected PIN file does not refer to the same = project ' + 'as the local manifest file. {}'.format(CHP_EXIT))= =20 +COMMIT_NOT_FOUND =3D 'The commit referenced by the PIN file does not=20 +exist. {}'.format(CHP_EXIT) \ No newline at end of file diff --git a/edkrepo/common/edkrepo_exception.py b/edkrepo/common/edkrepo_= exception.py index b6ea3dd..a56e709 100644 --- a/edkrepo/common/edkrepo_exception.py +++ b/edkrepo/common/edkrepo_exception.py @@ -58,6 +58,10 @@ class EdkrepoConfigFileReadOnlyException(EdkrepoExcepti= on): def __init__(self, message): super().__init__(message, 112) =20 +class EdkrepoProjectMismatchException(EdkrepoException): + def __init__(self, message): + super().__init__(message, 113) + class EdkrepoVerificationException(EdkrepoException): def __init__(self, message): super().__init__(message, 114) -- 2.16.2.windows.1