Skip to contentSkip to conversation

install-buildtools: add --local-file option

PATCH Superseded Jaipaul Cheernam 2 participants 6 messages Jun 25

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 install-buildtools: add --local-file option

When buildtools are fetched externally (e.g. by bitbake-setup using bb.fetch with checksum verification), install-buildtools does not need to download or verify the file again.

Add --local-file to accept a path to a pre-downloaded installer, skipping the download and checksum steps. The existing standalone download behaviour is preserved in the else branch.

---
 scripts/install-buildtools | 109 +++++++++++++++++++++----------------
 1 file changed, 62 insertions(+), 47 deletions(-)
scripts/install-buildtools +62 -47
index 723edd793e..943770c84c 100755
@@ -130,6 +130,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'
@@ -243,62 +247,73 @@ def main():
     os.makedirs(sdk_dir, exist_ok=True)
     try:
         # Fetch installer
-        logger.info("Fetching buildtools installer")
-        tmpbuildtools = os.path.join(sdk_dir, filename)
-        with open(os.path.join(sdk_dir, 'buildtools_url'), 'w') as f:
-            f.write(buildtools_url)
-        ret = subprocess.call("wget -q -O %s %s" %
-                              (tmpbuildtools, buildtools_url), shell=True)
-        if ret != 0:
-            logger.error("Could not download file from %s" % buildtools_url)
-            return ret
-
-        # Verify checksum
-        if args.check:
-            logger.info("Fetching buildtools installer checksum")
-            checksum_type = "sha256sum"
-            checksum_url = "{}.{}".format(buildtools_url, checksum_type)
-            checksum_filename = "{}.{}".format(filename, checksum_type)
-            tmpbuildtools_checksum = os.path.join(sdk_dir, checksum_filename)
-            with open(os.path.join(sdk_dir, 'checksum_url'), 'w') as f:
-                f.write(checksum_url)
-            ret = subprocess.call("wget -q -O %s %s" %
-                                    (tmpbuildtools_checksum, checksum_url), shell=True)
+        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:
+            logger.info("Fetching buildtools installer")
+            tmpbuildtools = os.path.join(sdk_dir, filename)
+            with open(os.path.join(sdk_dir, 'buildtools_url'), 'w') as f:
+                f.write(buildtools_url)
+            ret = subprocess.call(["wget", "-q", "-O", tmpbuildtools, buildtools_url])
             if ret != 0:
-                logger.error("Could not download file from %s" % checksum_url)
+                logger.error("Could not download file from %s" % buildtools_url)
                 return ret
-            regex = re.compile(r"^(?P<checksum>[0-9a-f]+)\s+(?P<path>.*/)?(?P<filename>.*)$")
-            with open(tmpbuildtools_checksum, 'rb') as f:
-                original = f.read()
-                m = re.search(regex, original.decode("utf-8"))
-                logger.debug("checksum regex match: %s" % m)
-                logger.debug("checksum: %s" % m.group('checksum'))
-                logger.debug("path: %s" % m.group('path'))
-                logger.debug("filename: %s" % m.group('filename'))
-                if filename != m.group('filename'):
-                    logger.error("Filename does not match name in checksum")
+
+            # Verify checksum
+            if args.check:
+                logger.info("Fetching buildtools installer checksum")
+                checksum_type = "sha256sum"
+                checksum_url = "{}.{}".format(buildtools_url, checksum_type)
+                checksum_filename = "{}.{}".format(filename, checksum_type)
+                tmpbuildtools_checksum = os.path.join(sdk_dir, checksum_filename)
+                with open(os.path.join(sdk_dir, 'checksum_url'), 'w') as f:
+                    f.write(checksum_url)
+                ret = subprocess.call(["wget", "-q", "-O", tmpbuildtools_checksum, checksum_url])
+                if ret != 0:
+                    logger.error("Could not download file from %s" % checksum_url)
+                    return ret
+                regex = re.compile(r"^(?P<checksum>[0-9a-f]+)\s+(?P<path>.*/)?(?P<filename>.*)$")
+                with open(tmpbuildtools_checksum, 'rb') as f:
+                    original = f.read()
+                    m = re.search(regex, original.decode("utf-8"))
+                    logger.debug("checksum regex match: %s" % m)
+                    logger.debug("checksum: %s" % m.group('checksum'))
+                    logger.debug("path: %s" % m.group('path'))
+                    logger.debug("filename: %s" % m.group('filename'))
+                    if filename != m.group('filename'):
+                        logger.error("Filename does not match name in checksum")
+                        return 1
+                    checksum = m.group('checksum')
+                checksum_value = sha256_file(tmpbuildtools)
+                if checksum == checksum_value:
+                        logger.info("Checksum success")
+                else:
+                    logger.error("Checksum %s expected. Actual checksum is %s." %
+                                 (checksum, checksum_value))
                     return 1
-                checksum = m.group('checksum')
-            checksum_value = sha256_file(tmpbuildtools)
-            if checksum == checksum_value:
-                    logger.info("Checksum success")
-            else:
-                logger.error("Checksum %s expected. Actual checksum is %s." %
-                             (checksum, checksum_value))
-                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:
+            # 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("%s -d %s -y" %
-                                  (tmpbuildtools, install_dir), shell=True)
+            ret = subprocess.call(cmd + ["-d", install_dir, "-y"])
         else:
             install_dir = "/opt/poky/%s" % args.installer_version
-            ret = subprocess.call("%s -y" % tmpbuildtools, shell=True)
+            ret = subprocess.call(cmd + ["-y"])
         if ret != 0:
             logger.error("Could not run buildtools installer")
             return ret
Signature · 1 line
2.34.1
#1 lore raw

This is really hard to review. You need to split this up: first move the existing code into its own function (or functoins) in a separate commit, then add the new logic in a second commit.

Alex

Quoted 163 lines · Jaipaul Cheernam via lists.openembedded.org

When buildtools are fetched externally (e.g. by bitbake-setup using bb.fetch with checksum verification), install-buildtools does not need to download or verify the file again.

Add --local-file to accept a path to a pre-downloaded installer, skipping the download and checksum steps. The existing standalone download behaviour is preserved in the else branch.

---
 scripts/install-buildtools | 109 +++++++++++++++++++++----------------
 1 file changed, 62 insertions(+), 47 deletions(-)
scripts/install-buildtools +62 -48
index 723edd793e..943770c84c 100755
@@ -130,6 +130,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'
@@ -243,62 +247,73 @@ def main():
     os.makedirs(sdk_dir, exist_ok=True)
     try:
         # Fetch installer
-        logger.info("Fetching buildtools installer")
-        tmpbuildtools = os.path.join(sdk_dir, filename)
-        with open(os.path.join(sdk_dir, 'buildtools_url'), 'w') as f:
-            f.write(buildtools_url)
-        ret = subprocess.call("wget -q -O %s %s" %
-                              (tmpbuildtools, buildtools_url), shell=True)
-        if ret != 0:
-            logger.error("Could not download file from %s" % buildtools_url)
-            return ret
-
-        # Verify checksum
-        if args.check:
-            logger.info("Fetching buildtools installer checksum")
-            checksum_type = "sha256sum"
-            checksum_url = "{}.{}".format(buildtools_url, checksum_type)
-            checksum_filename = "{}.{}".format(filename, checksum_type)
-            tmpbuildtools_checksum = os.path.join(sdk_dir, checksum_filename)
-            with open(os.path.join(sdk_dir, 'checksum_url'), 'w') as f:
-                f.write(checksum_url)
-            ret = subprocess.call("wget -q -O %s %s" %
-                                    (tmpbuildtools_checksum, checksum_url), shell=True)
+        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:
+            logger.info("Fetching buildtools installer")
+            tmpbuildtools = os.path.join(sdk_dir, filename)
+            with open(os.path.join(sdk_dir, 'buildtools_url'), 'w') as f:
+                f.write(buildtools_url)
+            ret = subprocess.call(["wget", "-q", "-O", tmpbuildtools, buildtools_url])
             if ret != 0:
-                logger.error("Could not download file from %s" % checksum_url)
+                logger.error("Could not download file from %s" % buildtools_url)
                 return ret
-            regex = re.compile(r"^(?P<checksum>[0-9a-f]+)\s+(?P<path>.*/)?(?P<filename>.*)$")
-            with open(tmpbuildtools_checksum, 'rb') as f:
-                original = f.read()
-                m = re.search(regex, original.decode("utf-8"))
-                logger.debug("checksum regex match: %s" % m)
-                logger.debug("checksum: %s" % m.group('checksum'))
-                logger.debug("path: %s" % m.group('path'))
-                logger.debug("filename: %s" % m.group('filename'))
-                if filename != m.group('filename'):
-                    logger.error("Filename does not match name in checksum")
+
+            # Verify checksum
+            if args.check:
+                logger.info("Fetching buildtools installer checksum")
+                checksum_type = "sha256sum"
+                checksum_url = "{}.{}".format(buildtools_url, checksum_type)
+                checksum_filename = "{}.{}".format(filename, checksum_type)
+                tmpbuildtools_checksum = os.path.join(sdk_dir, checksum_filename)
+                with open(os.path.join(sdk_dir, 'checksum_url'), 'w') as f:
+                    f.write(checksum_url)
+                ret = subprocess.call(["wget", "-q", "-O", tmpbuildtools_checksum, checksum_url])
+                if ret != 0:
+                    logger.error("Could not download file from %s" % checksum_url)
+                    return ret
+                regex = re.compile(r"^(?P<checksum>[0-9a-f]+)\s+(?P<path>.*/)?(?P<filename>.*)$")
+                with open(tmpbuildtools_checksum, 'rb') as f:
+                    original = f.read()
+                    m = re.search(regex, original.decode("utf-8"))
+                    logger.debug("checksum regex match: %s" % m)
+                    logger.debug("checksum: %s" % m.group('checksum'))
+                    logger.debug("path: %s" % m.group('path'))
+                    logger.debug("filename: %s" % m.group('filename'))
+                    if filename != m.group('filename'):
+                        logger.error("Filename does not match name in checksum")
+                        return 1
+                    checksum = m.group('checksum')
+                checksum_value = sha256_file(tmpbuildtools)
+                if checksum == checksum_value:
+                        logger.info("Checksum success")
+                else:
+                    logger.error("Checksum %s expected. Actual checksum is %s." %
+                                 (checksum, checksum_value))
                     return 1
-                checksum = m.group('checksum')
-            checksum_value = sha256_file(tmpbuildtools)
-            if checksum == checksum_value:
-                    logger.info("Checksum success")
-            else:
-                logger.error("Checksum %s expected. Actual checksum is %s." %
-                             (checksum, checksum_value))
-                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:
+            # 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("%s -d %s -y" %
-                                  (tmpbuildtools, install_dir), shell=True)
+            ret = subprocess.call(cmd + ["-d", install_dir, "-y"])
         else:
             install_dir = "/opt/poky/%s" % args.installer_version
-            ret = subprocess.call("%s -y" % tmpbuildtools, shell=True)
+            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 (#239551): https://lists.openembedded.org/g/openembedded-core/message/239551
Mute This Topic: https://lists.openembedded.org/mt/119970828/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw

v3 cover install-buildtools: add --local-file option

In reply to Jaipaul Cheernam

Split the --local-file addition into two patches as requested:

1/2: Refactor — extract fetch_buildtools(), drop shell=True 2/2: Add --local-file option

Changes since v2:
- Split into two commits for easier review
- Avoid mutating caller-owned file (use /bin/sh instead of chmod)
- Remove shell=True from subprocess calls

Jaipaul Cheernam (2):
install-buildtools: refactor fetch and install logic
install-buildtools: add --local-file option

 scripts/install-buildtools | 123 ++++++++++++++++++++++---------------
 1 file changed, 73 insertions(+), 50 deletions(-)
Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 1/2 install-buildtools: refactor fetch and install logic

Pull the download and checksum code into fetch_buildtools() and switch subprocess calls from shell=True to list form.

No functional change.

---
 scripts/install-buildtools | 97 ++++++++++++++++++++------------------
 1 file changed, 51 insertions(+), 46 deletions(-)
scripts/install-buildtools +51 -46
index 723edd793e..b438d7a359 100755
@@ -114,6 +114,52 @@ def remove_quotes(var):
     return var
 
 
+def fetch_buildtools(buildtools_url, filename, sdk_dir, check):
+    """Download the buildtools installer and optionally verify its checksum."""
+    logger.info("Fetching buildtools installer")
+    tmpbuildtools = os.path.join(sdk_dir, filename)
+    with open(os.path.join(sdk_dir, 'buildtools_url'), 'w') as f:
+        f.write(buildtools_url)
+    ret = subprocess.call(["wget", "-q", "-O", tmpbuildtools, buildtools_url])
+    if ret != 0:
+        logger.error("Could not download file from %s" % buildtools_url)
+        return None
+
+    if check:
+        logger.info("Fetching buildtools installer checksum")
+        checksum_type = "sha256sum"
+        checksum_url = "{}.{}".format(buildtools_url, checksum_type)
+        checksum_filename = "{}.{}".format(filename, checksum_type)
+        tmpbuildtools_checksum = os.path.join(sdk_dir, checksum_filename)
+        with open(os.path.join(sdk_dir, 'checksum_url'), 'w') as f:
+            f.write(checksum_url)
+        ret = subprocess.call(["wget", "-q", "-O", tmpbuildtools_checksum, checksum_url])
+        if ret != 0:
+            logger.error("Could not download file from %s" % checksum_url)
+            return None
+        regex = re.compile(r"^(?P<checksum>[0-9a-f]+)\s+(?P<path>.*/)?(?P<filename>.*)$")
+        with open(tmpbuildtools_checksum, 'rb') as f:
+            original = f.read()
+            m = re.search(regex, original.decode("utf-8"))
+            logger.debug("checksum regex match: %s" % m)
+            logger.debug("checksum: %s" % m.group('checksum'))
+            logger.debug("path: %s" % m.group('path'))
+            logger.debug("filename: %s" % m.group('filename'))
+            if filename != m.group('filename'):
+                logger.error("Filename does not match name in checksum")
+                return None
+            checksum = m.group('checksum')
+        checksum_value = sha256_file(tmpbuildtools)
+        if checksum == checksum_value:
+            logger.info("Checksum success")
+        else:
+            logger.error("Checksum %s expected. Actual checksum is %s." %
+                         (checksum, checksum_value))
+            return None
+
+    return tmpbuildtools
+
+
 def main():
     global DEFAULT_INSTALL_DIR
     global DEFAULT_BASE_URL
@@ -243,49 +289,9 @@ def main():
     os.makedirs(sdk_dir, exist_ok=True)
     try:
         # Fetch installer
-        logger.info("Fetching buildtools installer")
-        tmpbuildtools = os.path.join(sdk_dir, filename)
-        with open(os.path.join(sdk_dir, 'buildtools_url'), 'w') as f:
-            f.write(buildtools_url)
-        ret = subprocess.call("wget -q -O %s %s" %
-                              (tmpbuildtools, buildtools_url), shell=True)
-        if ret != 0:
-            logger.error("Could not download file from %s" % buildtools_url)
-            return ret
-
-        # Verify checksum
-        if args.check:
-            logger.info("Fetching buildtools installer checksum")
-            checksum_type = "sha256sum"
-            checksum_url = "{}.{}".format(buildtools_url, checksum_type)
-            checksum_filename = "{}.{}".format(filename, checksum_type)
-            tmpbuildtools_checksum = os.path.join(sdk_dir, checksum_filename)
-            with open(os.path.join(sdk_dir, 'checksum_url'), 'w') as f:
-                f.write(checksum_url)
-            ret = subprocess.call("wget -q -O %s %s" %
-                                    (tmpbuildtools_checksum, checksum_url), shell=True)
-            if ret != 0:
-                logger.error("Could not download file from %s" % checksum_url)
-                return ret
-            regex = re.compile(r"^(?P<checksum>[0-9a-f]+)\s+(?P<path>.*/)?(?P<filename>.*)$")
-            with open(tmpbuildtools_checksum, 'rb') as f:
-                original = f.read()
-                m = re.search(regex, original.decode("utf-8"))
-                logger.debug("checksum regex match: %s" % m)
-                logger.debug("checksum: %s" % m.group('checksum'))
-                logger.debug("path: %s" % m.group('path'))
-                logger.debug("filename: %s" % m.group('filename'))
-                if filename != m.group('filename'):
-                    logger.error("Filename does not match name in checksum")
-                    return 1
-                checksum = m.group('checksum')
-            checksum_value = sha256_file(tmpbuildtools)
-            if checksum == checksum_value:
-                    logger.info("Checksum success")
-            else:
-                logger.error("Checksum %s expected. Actual checksum is %s." %
-                             (checksum, checksum_value))
-                return 1
+        tmpbuildtools = fetch_buildtools(buildtools_url, filename, sdk_dir, args.check)
+        if tmpbuildtools is None:
+            return 1
 
         # Make installer executable
         logger.info("Making installer executable")
@@ -294,11 +300,10 @@ def main():
         logger.debug(os.stat(tmpbuildtools))
         if args.directory:
             install_dir = os.path.abspath(args.directory)
-            ret = subprocess.call("%s -d %s -y" %
-                                  (tmpbuildtools, install_dir), shell=True)
+            ret = subprocess.call([tmpbuildtools, "-d", install_dir, "-y"])
         else:
             install_dir = "/opt/poky/%s" % args.installer_version
-            ret = subprocess.call("%s -y" % tmpbuildtools, shell=True)
+            ret = subprocess.call([tmpbuildtools, "-y"])
         if ret != 0:
             logger.error("Could not run buildtools installer")
             return ret
Signature · 1 line
2.34.1
#4 lore raw

PATCH v3 2/2 install-buildtools: add --local-file option

In reply to Jaipaul Cheernam

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.

---
 scripts/install-buildtools | 40 +++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
scripts/install-buildtools +29 -11
index b438d7a359..4e6f6e25d7 100755
@@ -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
Signature · 1 line
2.34.1
#5 lore raw

Thanks, this looks good.

Alex

Quoted 85 lines · Jaipaul Cheernam via lists.openembedded.org

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.

---
 scripts/install-buildtools | 40 +++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
scripts/install-buildtools +29 -12
index b438d7a359..4e6f6e25d7 100755
@@ -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: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-