Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 80 additions & 48 deletions infra/portable/make_portable_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import shutil
import subprocess
import sys
import time
import zipfile


Expand All @@ -24,77 +23,110 @@ def try_run(command):

def display_help():
print("\nScript to make a portable Thorium .zip for Windows.\n")
print("\nPlease place the thorium_mini_installer.exe file in this directory before running.\n")

if '--help' in sys.argv:

if "--help" in sys.argv:
display_help()
sys.exit(0)


def copy_installer():
cr_src_dir = os.getenv('CR_DIR', r'C:/src/chromium/src')
src_path = os.path.normpath(os.path.join(cr_src_dir, 'out', 'thorium', 'thorium_mini_installer.exe'))
dest_path = os.path.normpath(os.path.join(os.getcwd(), 'thorium_mini_installer.exe'))

if not os.path.exists(src_path):
fail(f"thorium_mini_installer.exe not found at {src_path}")

print(f"Copying thorium_mini_installer.exe from {src_path} to {dest_path}...\n")
shutil.copy(src_path, dest_path)


def extract_and_copy_files():
# Extract and copy files
os.makedirs('./temp/USER_DATA', exist_ok=True)
try_run('7z x thorium_mini_installer.exe')
try_run('7z x chrome.7z')
shutil.move('Chrome-bin', './temp/BIN')
shutil.copy('./README.win', './temp/README.txt')
shutil.copy('./THORIUM.BAT', './temp/')
shutil.copy('./THORIUM_SHELL.BAT', './temp/')

def zip_files():
# Create zip archive
with zipfile.ZipFile('thorium_portable.zip', 'w', zipfile.ZIP_DEFLATED) as zf:
for root, _, files in os.walk('./temp'):
cr_src_dir = os.getenv("CR_DIR", r"C:/src/chromium/src")
installer_files = [
"thorium_mini_installer.exe",
"thorium_AVX_mini_installer.exe",
"thorium_AVX2_mini_installer.exe",
"thorium_SSE3_mini_installer.exe",
"thorium_SSE4_mini_installer.exe",
]

existing_files = [
installer_file
for installer_file in installer_files
if os.path.exists(os.path.join(os.getcwd(), installer_file))
]

if existing_files:
print(f"Skipping copy for existing files: {', '.join(existing_files)}\n")
print("Starting portable version creation.")
return existing_files[0]

for installer_file in installer_files:
src_path = os.path.normpath(
os.path.join(cr_src_dir, "out", "thorium", installer_file)
)
dest_path = os.path.normpath(os.path.join(os.getcwd(), installer_file))

if os.path.exists(src_path):
print(f"Copying {installer_file} from {src_path} to {dest_path}...\n")
shutil.copy(src_path, dest_path)
return installer_file

fail("No installer file found.")


def extract_and_copy_files(installer_name):
os.makedirs("./temp/USER_DATA", exist_ok=True)
try_run(f"7z x {installer_name}")
try_run("7z x chrome.7z")
shutil.move("Chrome-bin", "./temp/BIN")
shutil.copy("./README.win", "./temp/README.txt")
shutil.copy("./THORIUM.BAT", "./temp/")
shutil.copy("./THORIUM_SHELL.BAT", "./temp/")


def zip_files(installer_name):
version = "130.0.6723.174"

if "AVX2" in installer_name:
zip_filename = f"Thorium_AVX2_{version}.zip"
elif "AVX" in installer_name:
zip_filename = f"Thorium_AVX_{version}.zip"
elif "SSE3" in installer_name:
zip_filename = f"Thorium_SSE3_{version}.zip"
elif "SSE4" in installer_name:
zip_filename = f"Thorium_SSE4_{version}.zip"
else:
zip_filename = f"thorium_portable.zip"

with zipfile.ZipFile(zip_filename, "w", zipfile.ZIP_DEFLATED) as zf:
for root, _, files in os.walk("./temp"):
if not files:
zf.write(root, os.path.relpath(root, "./temp"))
for file in files:
file_path = os.path.join(root, file)
zf.write(file_path, os.path.relpath(file_path, './temp'))
zf.write(file_path, os.path.relpath(file_path, "./temp"))

print(f"Created zip archive: {zip_filename}")


def clean_up():
# Cleanup extracted files
try:
os.remove('chrome.7z')
shutil.rmtree('temp')
os.remove("chrome.7z")
shutil.rmtree("temp")
except FileNotFoundError:
pass

def main():

print("\nNOTE: You must place the thorium .exe file in this directory before running.")
print(" AND you must have 7-Zip installed and in your PATH.")
print(" Make sure to rename the .zip properly as per the release instructions.")
print(" AND make sure to edit the THORIUM_SHELL.BAT to match the version number of this release.\n")

copy_installer()
def main():
print(
"\nNOTE: Place the Thorium .exe in this directory and ensure 7-Zip is in PATH.\n"
)

installer_name = copy_installer()
input("Press Enter to continue or Ctrl + C to abort.")

print("Extracting & Copying files from thorium .exe file...\n")
time.sleep(2)

extract_and_copy_files()
print("Extracting files from installer file...\n")
extract_and_copy_files(installer_name)

print("\nZipping up...\n")
zip_files()
zip_files(installer_name)

print("\nCleaning up...\n")
time.sleep(2)

clean_up()

print("\nDone! Zip is at ./thorium_portable.zip")
print("Remember to rename it with the version before distributing it.\n")
print("\nDone! Zip is at //infra/portable.\n")


if __name__ == "__main__":
main()
10 changes: 6 additions & 4 deletions win_scripts/build_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import sys

# Error handling functions


def fail(msg):
# Print error message and exit
print(f"{sys.argv[0]}: {msg}", file=sys.stderr)
Expand All @@ -23,6 +25,7 @@ def display_help():
print("\nScript to build Thorium for Windows.\n")
print("Usage: python win_scripts\build_win.py # (where # is number of jobs)\n")


if '--help' in sys.argv:
display_help()
sys.exit(0)
Expand All @@ -40,9 +43,8 @@ def display_help():

try_run(f'autoninja -C out/thorium thorium_all -j{jobs}')

# Move the installer
installer_src = os.path.normpath(os.path.join(cr_src_dir, 'out', 'thorium', 'mini_installer.exe'))
installer_dest = os.path.normpath(os.path.join(cr_src_dir, 'out', 'thorium', 'thorium_mini_installer.exe'))
os.rename(installer_src, installer_dest)
try_run(f'autoninja -C out/thorium setup mini_installer -j{jobs}')

installer_dest = os.path.normpath(os.path.join(cr_src_dir, 'out', 'thorium'))

print(f"Build Completed. Installer at '{installer_dest}'")
58 changes: 45 additions & 13 deletions win_scripts/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import subprocess


def fail(msg):
print(f"{sys.argv[0]}: {msg}", file=sys.stderr)
sys.exit(111)
Expand All @@ -23,42 +24,73 @@ def try_run(command):


def clean_files(directory):
deleted = False
for filename in os.listdir(directory):
file_path = os.path.join(directory, filename)
if os.path.isfile(file_path):
try:
os.remove(file_path)
deleted = True
print(f"Removed: {file_path}")
except Exception as e:
fail(f"Failed to remove {file_path}: {e}")
return deleted


def delete_directory(directory):
if os.path.exists(directory):
try:
shutil.rmtree(directory)
print(f"Removed directory: {directory}")
return True
except Exception as e:
fail(f"Failed to remove directory {directory}: {e}")
return False


def display_help():
print("\nScript to remove unneeded artifacts\n")

if '--help' in sys.argv:

if "--help" in sys.argv:
display_help()
sys.exit(0)


# Set chromium/src dir from Windows environment variable
cr_src_dir = os.getenv('CR_DIR', r'C:/src/chromium/src')

print("\nCleaning up unneeded artifacts\n")

profiles_dir = os.path.normpath(os.path.join(cr_src_dir, "chrome", "build", "pgo_profiles"))
clean_files(profiles_dir)

thorium_dir = os.path.normpath(os.path.join(cr_src_dir, "out", "thorium"))
delete_directory(thorium_dir)

print("\nDone cleaning artifacts\n")
def main():
cr_src_dir = os.getenv("CR_DIR", r"C:\src\chromium\src")
profiles_dir = os.path.normpath(
os.path.join(cr_src_dir, "chrome", "build", "pgo_profiles")
)
thorium_dir = os.path.normpath(os.path.join(cr_src_dir, "out", "thorium"))

cleanup_needed = any(
[
(
os.path.isdir(profiles_dir)
and any(
os.path.isfile(os.path.join(profiles_dir, filename))
for filename in os.listdir(profiles_dir)
)
),
os.path.exists(thorium_dir),
]
)

if cleanup_needed:
print("\nCleaning up unneeded artifacts\n")

files_deleted = (
clean_files(profiles_dir) if os.path.isdir(profiles_dir) else False
)
dir_deleted = (
delete_directory(thorium_dir) if os.path.exists(
thorium_dir) else False
)

if files_deleted or dir_deleted:
print("\nDone cleaning unneeded artifacts\n")


if __name__ == "__main__":
main()
42 changes: 22 additions & 20 deletions win_scripts/reset_depot_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# TODO(gz83): Suppress false positives during operation?

import os
import shutil
import subprocess
import sys

Expand Down Expand Up @@ -42,20 +41,18 @@ def remove(item_path):


def unlock_and_delete(path):
"""Attempts to unlock and delete a directory using cmd commands."""
if sys.platform == "win32":
# Use the Windows command line tools to unlock the directory
try:
# Use the command 'del' to delete all files recursively
subprocess.run(f'del /S /Q "{path}\\*"', shell=True, check=True)
# Use the command 'rmdir' to delete the directory
subprocess.run(f'rmdir /S /Q "{path}"', shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Failed to unlock and delete directory '{path}' via CMD: {e}")
raise PermissionError(f"Failed to unlock and delete directory '{path}' via CMD: {e}")
else:
# For other platforms, just use shutil.rmtree
shutil.rmtree(path)
"""Attempts to unlock and delete a directory using Windows cmd commands."""
# Use the Windows command line tools to unlock the directory
try:
# Use the command 'del' to delete all files recursively
subprocess.run(f'del /S /Q "{path}\\*"', shell=True, check=True)
# Use the command 'rmdir' to delete the directory
subprocess.run(f'rmdir /S /Q "{path}"', shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Failed to unlock and delete directory '{path}' via CMD: {e}")
raise PermissionError(
f"Failed to unlock and delete directory '{path}' via CMD: {e}"
)


def display_help():
Expand All @@ -64,14 +61,18 @@ def display_help():
print("from your disk, and then re-clone depot_tools.")
print("\n")

if '--help' in sys.argv:

if "--help" in sys.argv:
display_help()
sys.exit(0)


depot_tools_dir = os.getenv('DEPOT_TOOLS_DIR', r"C:\src\depot_tools")
gsutil_dir = os.path.expandvars(os.getenv('GSUTIL_DIR', r'%USERPROFILE%\.gsutil'))
vpython_root_dir = os.path.expandvars(os.getenv('VPYTHON_ROOT_DIR', r'%LOCALAPPDATA%\.vpython-root'))
depot_tools_dir = os.getenv("DEPOT_TOOLS_DIR", r"C:\src\depot_tools")
gsutil_dir = os.path.expandvars(
os.getenv("GSUTIL_DIR", r"%USERPROFILE%\.gsutil"))
vpython_root_dir = os.path.expandvars(
os.getenv("VPYTHON_ROOT_DIR", r"%LOCALAPPDATA%\.vpython-root")
)

print("\nRemoving depot_tools, etc\n")

Expand All @@ -84,5 +85,6 @@ def display_help():
os.chdir(os.path.dirname(depot_tools_dir))
try_run(f"git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git")

print(f"\nCompleted. You can now use the depot_tools installed at: {depot_tools_dir}\n")
print(
f"\nCompleted. You can now use the depot_tools installed at: {depot_tools_dir}\n")
print("\nYou can now run trunk.py\n")
Loading