From nobody Mon Feb 9 00:14:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+56998+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+56998+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1586206761; cv=none; d=zohomail.com; s=zohoarc; b=fObTGkdLwRNuzR9TjuzqbuZzvP001mzjtpcABilWmGEdkieM91cSjp33NH2hL2X9ErnaihN+xWIxNXDzIz8//WGSZm42eoqqCxPHWzp/X4XFdOptrsm/+0a4LO0eC+yLBx9SWG4lrKqNavz1SQyUSSNQXciSoysJn9w8hpwYhI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586206761; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=xxMlyYj3LaC0XLxXN156ACl2rz3vagTYipsJ627LsZs=; b=I979YvShFFabXpuRFzrysL2ywmSktZvrnUmCRwSu7NQJMd23MYXuzbH2cTCMJzj9dZ/z/qVamEnjZ8Jy4GYddi0kT9tC+09KwpwwRsgTN6q9rJ9SrluZyo7WBkfUbDg3Z3H7TyFBtUKrrcSDEXB7P3Qj84OWiTO3C4rkEgz2ojo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+56998+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1586206761326988.9958393033746; Mon, 6 Apr 2020 13:59:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id twJAYY1788612xGS9DDHP0LN; Mon, 06 Apr 2020 13:59:21 -0700 X-Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web11.3166.1586206760313412158 for ; Mon, 06 Apr 2020 13:59:20 -0700 IronPort-SDR: suZXouFI3E7VqWOqZGMZDnREL/xA/rkwF9yOIHo0Ph/vI7G8PjxUg51/EmTL0OGWsEJmTttXR1 Uj5KdUMXDrAA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2020 13:59:18 -0700 IronPort-SDR: oEVZ4TwKWli1cvqDk2T+n646IC/DHSakQx0YP/nx2woAIO6uAtNI+JUTiJs6/5gX2531EgmFRV nKUR0eZyc2Dw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,352,1580803200"; d="scan'208";a="241889106" X-Received: from sravikum-mobl1.amr.corp.intel.com ([10.255.229.189]) by fmsmga007.fm.intel.com with ESMTP; 06 Apr 2020 13:59:18 -0700 From: "Nate DeSimone" To: devel@edk2.groups.io Cc: Ashley DeSimone , Puja Pandya , Erik Bjorge , Prince Agyeman , Bret Barkelew , Philippe Mathieu-Daude Subject: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Add Support for macOS Date: Mon, 6 Apr 2020 13:59:04 -0700 Message-Id: <20200406205904.27226-1-nathaniel.l.desimone@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,nathaniel.l.desimone@intel.com X-Gm-Message-State: cqYKpAEUWCPJTQb2T18hOKl7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1586206761; bh=1XGoUQ0Wqqwe4ZlyXr5VLT2ofgKGHqW045jjDTeRbzg=; h=Cc:Date:From:Reply-To:Subject:To; b=gkXmi+tOHtvBwS6cvQsGo+l6MFIzTM5G0YWDiJH2a4Np1lwJm3Pe016D9mC/J38Qulm 6J2O2p26eCrDVal88QRhKri2hI1ZFzPw/PL15t1mCwlPmpuCYqzu8paP9GeexNsHcbu11 z8nmE7tSPIoMrdZJW7BKC6Z1TfVfuZNwGUk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Signed-off-by: Nate DeSimone Cc: Ashley DeSimone Cc: Puja Pandya Cc: Erik Bjorge Cc: Prince Agyeman Cc: Bret Barkelew Cc: Philippe Mathieu-Daude Reviewed-by: Ashley DeSimone Reviewed-by: Erik Bjorge --- build-scripts/build_linux_installer.py | 2 + build-scripts/set_version_and_build_wheels.py | 10 +-- edkrepo/config/config_factory.py | 6 +- edkrepo_installer/linux-scripts/install.py | 65 +++++++++++++++++-- 4 files changed, 67 insertions(+), 16 deletions(-) diff --git a/build-scripts/build_linux_installer.py b/build-scripts/build_l= inux_installer.py index 0130552..11dd8d7 100755 --- a/build-scripts/build_linux_installer.py +++ b/build-scripts/build_linux_installer.py @@ -10,6 +10,7 @@ from argparse import ArgumentParser import fnmatch, os, shutil, subprocess, sys import set_version_and_build_wheels as build_edkrepo +import traceback def main(): parser =3D ArgumentParser() @@ -31,6 +32,7 @@ def main(): try: build_edkrepo.main() except: + traceback.print_exc() print('Failed to build edkrepo wheel') return 1 diff --git a/build-scripts/set_version_and_build_wheels.py b/build-scripts/= set_version_and_build_wheels.py index 42e58cc..7df0c84 100755 --- a/build-scripts/set_version_and_build_wheels.py +++ b/build-scripts/set_version_and_build_wheels.py @@ -3,7 +3,7 @@ ## @file # set_version_and_build_wheels.py # -# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -214,7 +214,7 @@ def build_wheels(extension_pkgs): def copy_wheels_and_set_xml(package_version, extension_pkgs): dir_path =3D os.path.join(os.path.dirname(os.path.abspath(os.path.dirn= ame(__file__))), "dist") dest_path =3D os.path.join(dir_path, "self_extract") - if ostype =3D=3D LINUX: + if ostype !=3D WIN: dest_path =3D os.path.join(dest_path, 'wheels') if not os.path.isdir(dest_path): os.makedirs(dest_path) @@ -241,9 +241,9 @@ def create_final_copy_script(version): f.write("pushd ..\\dist\n") f.write("ren \"setup.exe\" \"EdkRepoSetup-{}.exe\"\n".format(v= ersion)) f.write("popd\n") - elif ostype =3D=3D LINUX: + else: with open('final_copy.py', 'w') as f: - f.write('#!/usr/bin/python3\n') + f.write('#!/usr/bin/env python3\n') f.write('import os, shutil, sys\n') f.write('dist_name =3D "edkrepo-{{}}".format("{}")\n'.format(v= ersion)) f.write('installer_dir =3D "../dist/self_extract"\n') @@ -257,7 +257,7 @@ def _copy_file(source, destination): check_call("cp -f {} {}".format(source, destination), shell=3DTrue) def make_version_cfg_file(version): - if ostype =3D=3D LINUX: + if ostype !=3D WIN: cfg_src =3D os.path.join(os.path.dirname(os.path.abspath(os.path.d= irname(__file__))), 'edkrepo_installer', 'linux-scripts') install_cfg =3D configparser.ConfigParser(allow_no_value=3DTrue) install_cfg.read(os.path.join(cfg_src, 'install.cfg')) diff --git a/edkrepo/config/config_factory.py b/edkrepo/config/config_facto= ry.py index e3a437f..b86e0b8 100644 --- a/edkrepo/config/config_factory.py +++ b/edkrepo/config/config_factory.py @@ -3,7 +3,7 @@ ## @file # config_factory.py # -# Copyright (c) 2017- 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -30,9 +30,7 @@ def get_edkrepo_global_data_directory(): common_appdata =3D create_unicode_buffer(MAX_PATH) SHGetFolderPath(None, CSIDL_COMMON_APPDATA, None, SHGFP_TYPE_CURRE= NT, common_appdata) global_data_dir =3D os.path.join(common_appdata.value, "edkrepo") - elif sys.platform =3D=3D "darwin": - raise OSError("macOS support is in progress") - elif sys.platform.startswith("linux") or os.name =3D=3D "posix": + elif sys.platform =3D=3D "darwin" or sys.platform.startswith("linux") = or os.name =3D=3D "posix": global_data_dir =3D os.path.expanduser("~/.edkrepo") if not os.path.isdir(global_data_dir): if not os.path.exists(os.path.dirname(global_data_dir)): diff --git a/edkrepo_installer/linux-scripts/install.py b/edkrepo_installer= /linux-scripts/install.py index 52f0c52..099954d 100755 --- a/edkrepo_installer/linux-scripts/install.py +++ b/edkrepo_installer/linux-scripts/install.py @@ -23,6 +23,21 @@ import sys import traceback import xml.etree.ElementTree as et +# +# Environment detection +# +MAC =3D "mac" +LINUX =3D "linux" +if sys.platform =3D=3D "darwin": + ostype =3D MAC +elif sys.platform.startswith("linux"): + ostype =3D LINUX +elif os.name =3D=3D "posix": + print("Warning: Unrecognized UNIX OS... treating as Linux") + ostype =3D LINUX +else: + raise EnvironmentError("Unsupported OS") + tool_sign_on =3D 'Installer for edkrepo version {}\nCopyright(c) Intel Cor= poration, 2020' # Data here should be maintained in a configuration file @@ -31,6 +46,7 @@ directories_with_executables =3D ['git_automation'] cfg_src_dir =3D os.path.abspath('config') whl_src_dir =3D os.path.abspath('wheels') def_python =3D 'python3' +nfs_home_directory_data =3D re.compile(r"NFSHomeDirectory:\s*(\S+)") # ZSH Configuration options prompt_regex =3D re.compile(r"#\s+[Aa][Dd][Dd]\s+[Ee][Dd][Kk][Rr][Ee][Pp][= Oo]\s+&\s+[Gg][Ii][Tt]\s+[Tt][Oo]\s+[Tt][Hh][Ee]\s+[Pp][Rr][Oo][Mm][Pp][Tt]= ") @@ -63,7 +79,8 @@ def init_logger(verbose): def get_args(): parser =3D ArgumentParser() - parser.add_argument('-l', '--local', action=3D'store_true', default=3D= False, help=3D'Install edkrepo to the user directory instead of system wide= ') + if ostype !=3D MAC: + parser.add_argument('-l', '--local', action=3D'store_true', defaul= t=3DFalse, help=3D'Install edkrepo to the user directory instead of system = wide') parser.add_argument('-p', '--py', action=3D'store', default=3DNone, he= lp=3D'Specify the python command to use when installing') parser.add_argument('-u', '--user', action=3D'store', default=3DNone, = help=3D'Specify user account to install edkrepo support on') parser.add_argument('-v', '--verbose', action=3D'store_true', default= =3DFalse, help=3D'Enables verbose output') @@ -218,6 +235,18 @@ def _check_version(current, expected): return 1 return 0 +def get_user_home_directory(username): + if ostype =3D=3D MAC: + res =3D default_run(['dscl', '.', '-read', '/Users/{}'.format(user= name), 'NFSHomeDirectory']) + data =3D nfs_home_directory_data.match(res.stdout.strip()) + if data: + return data.group(1) + else: + raise ValueError("home directory not found") + else: + res =3D default_run(['getent', 'passwd', username]) + return res.stdout.strip().split(':')[5] + def get_site_packages_directory(): res =3D default_run([def_python, '-c', 'import site; print(site.getsit= epackages()[0])']) return res.stdout.strip() @@ -424,6 +453,9 @@ def do_install(): # Initialize information based on command line input username =3D args.user + install_to_local =3D False + if ostype !=3D MAC and args.local: + install_to_local =3D True try: cfg =3D configparser.ConfigParser(allow_no_value=3DTrue) @@ -449,7 +481,7 @@ def do_install(): # Determine the user running sudo log.info('\nCollecting system information:') - if not args.local: + if not install_to_local and ostype !=3D MAC: try: res =3D default_run(['id', '-u']) except: @@ -466,11 +498,21 @@ def do_install(): log.info('- Unable to determine current user. Run installer u= sing the --user flag and specify the correct user name.') return 1 try: - res =3D default_run(['getent', 'passwd', username]) - user_home_dir =3D res.stdout.strip().split(':')[5] + user_home_dir =3D get_user_home_directory(username) except: log.info('- Unable to determine users home directory') return 1 + if ostype =3D=3D MAC: + try: + res =3D default_run(['id', '-u']) + except: + log.info('- Failed to determine user ID') + return 1 + if res.stdout.strip() =3D=3D '0': + log.info('- Installer must NOT be run as root') + return 1 + if os.path.commonprefix([user_home_dir, sys.executable]) !=3D user= _home_dir: + install_to_local =3D True default_cfg_dir =3D os.path.join(user_home_dir, cfg_dir) get_add_prompt_customization(args, user_home_dir) log.info('+ System information collected') @@ -625,7 +667,7 @@ def do_install(): install_whl =3D wheels_to_install[whl_name]['install'] if install_whl: install_cmd =3D [def_python, '-m', 'pip', 'install'] - if args.local: + if install_to_local: install_cmd.append('--user') install_cmd.append(os.path.join(whl_src_dir, whl)) try: @@ -639,23 +681,32 @@ def do_install(): set_execute_permissions() log.info('+ Marked scripts as executable') + #If pyenv is being used, regenerate the pyenv shims + if shutil.which('pyenv') is not None: + try: + res =3D default_run(['pyenv', 'rehash']) + log.info('+ Generated pyenv shims') + except: + log.info('- Failed to generate pyenv shim') #Install the command completion script if shutil.which('edkrepo') is not None: - if args.local: + if install_to_local or ostype =3D=3D MAC: command_completion_script =3D os.path.join(default_cfg_dir, 'e= dkrepo_completions.sh') else: command_completion_script =3D os.path.join('/', 'etc', 'profil= e.d', 'edkrepo_completions.sh') try: res =3D default_run(['edkrepo', 'generate-command-completion-s= cript', command_completion_script]) - if args.local: + if install_to_local or ostype =3D=3D MAC: shutil.chown(command_completion_script, user=3Dusername) os.chmod(command_completion_script, 0o644) add_command_completions_to_shell(command_completion_script, ar= gs, username, user_home_dir) + log.info('+ Configured edkrepo command completion') except: log.info('- Failed to configure edkrepo command completion') if args.verbose: traceback.print_exc() + log.log(logging.PRINT, '\nInstallation complete\n') return 0 -- 2.25.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#56998): https://edk2.groups.io/g/devel/message/56998 Mute This Topic: https://groups.io/mt/72821480/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-