diff mbox series

[v3,2/2] install-buildtools: add --local-file option

Message ID 20260625170620.81300-3-jaipaul.cheernam@est.tech
State New
Headers show
Series install-buildtools: add --local-file option | expand

Commit Message

Jaipaul Cheernam June 25, 2026, 5:06 p.m. UTC
Add --local-file so that bitbake-setup (or any other caller that
already fetched and verified the installer) can pass a local path
directly without re-downloading.

Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
Reviewed-by: Daniel Turull <daniel.turull@ericsson.com>
---
 scripts/install-buildtools | 40 +++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

Comments

Alexander Kanavin June 25, 2026, 5:17 p.m. UTC | #1
Thanks, this looks good.

Alex

On Thu, 25 Jun 2026 at 19:06, Jaipaul Cheernam via
lists.openembedded.org
<jaipaul.cheernam=est.tech@lists.openembedded.org> wrote:
>
> Add --local-file so that bitbake-setup (or any other caller that
> already fetched and verified the installer) can pass a local path
> directly without re-downloading.
>
> Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
> Reviewed-by: Daniel Turull <daniel.turull@ericsson.com>
> ---
>  scripts/install-buildtools | 40 +++++++++++++++++++++++++++-----------
>  1 file changed, 29 insertions(+), 11 deletions(-)
>
> diff --git a/scripts/install-buildtools b/scripts/install-buildtools
> index b438d7a359..4e6f6e25d7 100755
> --- a/scripts/install-buildtools
> +++ b/scripts/install-buildtools
> @@ -176,6 +176,10 @@ def main():
>          description="Buildtools installation helper",
>          add_help=False,
>          formatter_class=argparse.RawTextHelpFormatter)
> +    parser.add_argument('--local-file',
> +                        help='path to a pre-downloaded buildtools installer file.\n'
> +                             'Cannot be combined with --url or --filename.',
> +                        action='store')
>      parser.add_argument('-u', '--url',
>                          help='URL from where to fetch buildtools SDK installer, not '
>                               'including filename (optional)\n'
> @@ -289,21 +293,35 @@ def main():
>      os.makedirs(sdk_dir, exist_ok=True)
>      try:
>          # Fetch installer
> -        tmpbuildtools = fetch_buildtools(buildtools_url, filename, sdk_dir, args.check)
> -        if tmpbuildtools is None:
> -            return 1
> -
> -        # Make installer executable
> -        logger.info("Making installer executable")
> -        st = os.stat(tmpbuildtools)
> -        os.chmod(tmpbuildtools, st.st_mode | stat.S_IEXEC)
> -        logger.debug(os.stat(tmpbuildtools))
> +        if args.local_file:
> +            if args.url or args.filename:
> +                parser.error("--local-file cannot be combined with --url or --filename")
> +            tmpbuildtools = os.path.abspath(args.local_file)
> +            if not os.path.exists(tmpbuildtools):
> +                logger.error("Local file not found: %s" % tmpbuildtools)
> +                return 1
> +            filename = os.path.basename(tmpbuildtools)
> +        else:
> +            tmpbuildtools = fetch_buildtools(buildtools_url, filename, sdk_dir, args.check)
> +            if tmpbuildtools is None:
> +                return 1
> +
> +        # Run installer
> +        if args.local_file:
> +            # Avoid mutating caller-owned file; invoke via /bin/sh instead
> +            cmd = ["/bin/sh", tmpbuildtools]
> +        else:
> +            logger.info("Making installer executable")
> +            st = os.stat(tmpbuildtools)
> +            os.chmod(tmpbuildtools, st.st_mode | stat.S_IEXEC)
> +            logger.debug(os.stat(tmpbuildtools))
> +            cmd = [tmpbuildtools]
>          if args.directory:
>              install_dir = os.path.abspath(args.directory)
> -            ret = subprocess.call([tmpbuildtools, "-d", install_dir, "-y"])
> +            ret = subprocess.call(cmd + ["-d", install_dir, "-y"])
>          else:
>              install_dir = "/opt/poky/%s" % args.installer_version
> -            ret = subprocess.call([tmpbuildtools, "-y"])
> +            ret = subprocess.call(cmd + ["-y"])
>          if ret != 0:
>              logger.error("Could not run buildtools installer")
>              return ret
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#239584): https://lists.openembedded.org/g/openembedded-core/message/239584
> Mute This Topic: https://lists.openembedded.org/mt/119977011/1686489
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/scripts/install-buildtools b/scripts/install-buildtools
index b438d7a359..4e6f6e25d7 100755
--- a/scripts/install-buildtools
+++ b/scripts/install-buildtools
@@ -176,6 +176,10 @@  def main():
         description="Buildtools installation helper",
         add_help=False,
         formatter_class=argparse.RawTextHelpFormatter)
+    parser.add_argument('--local-file',
+                        help='path to a pre-downloaded buildtools installer file.\n'
+                             'Cannot be combined with --url or --filename.',
+                        action='store')
     parser.add_argument('-u', '--url',
                         help='URL from where to fetch buildtools SDK installer, not '
                              'including filename (optional)\n'
@@ -289,21 +293,35 @@  def main():
     os.makedirs(sdk_dir, exist_ok=True)
     try:
         # Fetch installer
-        tmpbuildtools = fetch_buildtools(buildtools_url, filename, sdk_dir, args.check)
-        if tmpbuildtools is None:
-            return 1
-
-        # Make installer executable
-        logger.info("Making installer executable")
-        st = os.stat(tmpbuildtools)
-        os.chmod(tmpbuildtools, st.st_mode | stat.S_IEXEC)
-        logger.debug(os.stat(tmpbuildtools))
+        if args.local_file:
+            if args.url or args.filename:
+                parser.error("--local-file cannot be combined with --url or --filename")
+            tmpbuildtools = os.path.abspath(args.local_file)
+            if not os.path.exists(tmpbuildtools):
+                logger.error("Local file not found: %s" % tmpbuildtools)
+                return 1
+            filename = os.path.basename(tmpbuildtools)
+        else:
+            tmpbuildtools = fetch_buildtools(buildtools_url, filename, sdk_dir, args.check)
+            if tmpbuildtools is None:
+                return 1
+
+        # Run installer
+        if args.local_file:
+            # Avoid mutating caller-owned file; invoke via /bin/sh instead
+            cmd = ["/bin/sh", tmpbuildtools]
+        else:
+            logger.info("Making installer executable")
+            st = os.stat(tmpbuildtools)
+            os.chmod(tmpbuildtools, st.st_mode | stat.S_IEXEC)
+            logger.debug(os.stat(tmpbuildtools))
+            cmd = [tmpbuildtools]
         if args.directory:
             install_dir = os.path.abspath(args.directory)
-            ret = subprocess.call([tmpbuildtools, "-d", install_dir, "-y"])
+            ret = subprocess.call(cmd + ["-d", install_dir, "-y"])
         else:
             install_dir = "/opt/poky/%s" % args.installer_version
-            ret = subprocess.call([tmpbuildtools, "-y"])
+            ret = subprocess.call(cmd + ["-y"])
         if ret != 0:
             logger.error("Could not run buildtools installer")
             return ret