Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate omaha to brave_core #10

Merged
merged 1 commit into from Oct 27, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -19,6 +19,7 @@ omaha/common/omaha_customization_proxy_clsid.h
omaha/proxy_clsids.txt
omaha/*.idb
omaha/scons-out/**
omaha/standalone/*

# Ignore compiled Python files.
*.pyc
@@ -0,0 +1,6 @@
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
[submodule "third_party/breakpad"]
path = third_party/breakpad
url = https://chromium.googlesource.com/breakpad/breakpad
@@ -0,0 +1,58 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import("//brave/build/config.gni")

assert(is_win)

group("omaha") {
deps = [ ":build_omaha_installer" ]
}

action("build_omaha_installer") {
script="build_omaha.py"

inputs = [ "build_omaha.py" ]

sources = [ "$root_out_dir/$brave_installer_exe" ]

_install_switch = ""
_tag_app_name = "Brave-Release"
if (brave_channel == "beta") {
_install_switch = "--chrome-beta"
_tag_app_name = "Brave-Browser-Beta"
} else if (brave_channel == "dev") {
_install_switch = "--chrome-dev"
_tag_app_name = "Brave-Browser-Dev"
} else if (brave_channel == "nightly") {
_install_switch = "--chrome-sxs"
_tag_app_name = "Brave-Browser-Nightly"
} else {
assert(brave_channel == "", "Unknown channel name")
}

out_dir = rebase_path(root_out_dir)

args = [
"--root_out_dir=$out_dir",
"--brave_installer_exe=$brave_installer_exe",
"--stub_installer_exe=$brave_stub_installer_exe",
"--standalone_installer_exe=$brave_standalone_installer_exe",
"--guid=$brave_app_guid",
"--install_switch=$_install_switch",
"--tag_ap=$tag_ap",
"--tag_app_name=$_tag_app_name",
"--brave_full_version=$chrome_version_major.$brave_version_major.$brave_version_minor.$brave_version_build",
]

outputs = [
"$root_out_dir/$brave_stub_installer_exe",
"$root_out_dir/$brave_standalone_installer_exe",
]

deps = [
"//brave/build/win:create_signed_installer",
]
}

@@ -0,0 +1,163 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import argparse
import os
import os.path
import shutil
import subprocess as sp
import sys

# https://stackoverflow.com/a/33856172
import ctypes

def run_as_admin(argv=None, debug=False):
shell32 = ctypes.windll.shell32
if argv is None and shell32.IsUserAnAdmin():
return True

if argv is None:
argv = sys.argv
if hasattr(sys, '_MEIPASS'):
# Support pyinstaller wrapped program.
arguments = map(unicode, argv[1:])
else:
arguments = map(unicode, argv)
argument_line = u' '.join(arguments)
executable = unicode(sys.executable)
if debug:
print 'Command line: ', executable, argument_line
ret = shell32.ShellExecuteW(None, u"runas", executable, argument_line, None, 1)
if int(ret) <= 32:
return False
return None

def Build(args, omaha_dir):
os.chdir(omaha_dir)

command = ['git', 'submodule', 'update', '--init']
sp.check_call(command, stderr=sp.STDOUT)

# move to omaha/omaha and start build.
os.chdir(os.path.join(omaha_dir, 'omaha'))
command = ['hammer-brave.bat', 'MODE=all', '--all']

This comment has been minimized.

Copy link
@simonhong

simonhong Oct 25, 2018

Author Collaborator

certificate related commands should be added here. @mbacchi

sp.check_call(command, stderr=sp.STDOUT)

def PrepareStandalone(args, omaha_dir):
# copy brave installer to staing folder to create standalond installer.
installer_file = os.path.join(args.root_out_dir[0], args.brave_installer_exe[0])
shutil.copyfile(installer_file, os.path.join(omaha_dir, 'omaha', 'scons-out', 'opt-win', 'staging', args.brave_installer_exe[0]))
shutil.copyfile(installer_file, os.path.join(omaha_dir, 'omaha', 'scons-out', 'dbg-win', 'staging', args.brave_installer_exe[0]))

# prepare manifset file.
f = open(os.path.join(omaha_dir, 'manifest_template.gup'),'r')
filedata = f.read()
f.close()

newdata = filedata.replace("APP_GUID", args.guid[0])
newdata = newdata.replace("BRAVE_INSTALLER_EXE", args.brave_installer_exe[0])
newdata = newdata.replace("INSTALL_SWITCH", args.install_switch[0])

target_manifest_file = args.guid[0] + '.gup'
target_manifest_path = os.path.join(omaha_dir, 'omaha', 'standalone', 'manifests', target_manifest_file)
f = open(target_manifest_path,'w')
f.write(newdata)
f.close()

# update standalone_installers.txt.
installer_text = "('STANDALONE_FILE_NAME', 'STANDALONE_FILE_NAME', [('BRAVE_VERSION', '$STAGING_DIR/BRAVE_INSTALLER_EXE', 'APP_GUID')], None, None, None, False, '', '')"
installer_text = installer_text.replace("APP_GUID", args.guid[0])
installer_text = installer_text.replace("STANDALONE_FILE_NAME", os.path.splitext(args.standalone_installer_exe[0])[0])
installer_text = installer_text.replace("BRAVE_INSTALLER_EXE", args.brave_installer_exe[0])
installer_text = installer_text.replace("BRAVE_VERSION", args.brave_full_version[0])

target_installer_text_path = os.path.join(omaha_dir, 'omaha', 'standalone', 'standalone_installers.txt')
f = open(target_installer_text_path,'w')
f.write(installer_text)
f.close()

def Tagging(args, omaha_dir, debug):

This comment has been minimized.

Copy link
@simonhong

simonhong Oct 27, 2018

Author Collaborator

Also, I made some changes after reviewing.
--build_omaha command will create debug and release mode both.
Output would be like below.

./src/out/Release/BraveBrowserDevSetup_70_0_58_1.exe*
./src/out/Release/BraveBrowserStandaloneDevSetup_70_0_58_1.exe*
./src/out/Release/DebugBraveBrowserDevSetup_70_0_58_1.exe*
./src/out/Release/DebugBraveBrowserStandaloneDevSetup_70_0_58_1.exe*
last_win_dir = 'opt-win'
if debug:
last_win_dir = 'dbg-win'
omaha_out_dir = os.path.join(omaha_dir, 'omaha', 'scons-out', last_win_dir)
apply_tag_exe = os.path.join(omaha_out_dir, 'obj', 'tools', 'ApplyTag', 'ApplyTag.exe')

tag = 'appguid=APP_GUID&appname=TAG_APP_NAME&needsadmin=prefers&lang=en&ap=TAG_AP'
tag = tag.replace("APP_GUID", args.guid[0])
tag = tag.replace("TAG_APP_NAME", args.tag_app_name[0])
tag = tag.replace("TAG_AP", args.tag_ap[0])

source_standalone_installer = os.path.join(omaha_out_dir, 'Test_Installers', 'UNOFFICIAL_' + args.standalone_installer_exe[0])
target_standalone_installer_file = args.standalone_installer_exe[0]
if debug:
target_standalone_installer_file = 'Debug' + target_standalone_installer_file
target_standalone_installer = os.path.join(args.root_out_dir[0], target_standalone_installer_file)
command = [apply_tag_exe, source_standalone_installer, target_standalone_installer, tag]
sp.check_call(command, stderr=sp.STDOUT)

source_stub_installer = os.path.join(omaha_out_dir, 'staging', 'BraveUpdateSetup.exe')
target_stub_installer_file = args.stub_installer_exe[0]
if debug:
target_stub_installer_file = 'Debug' + target_stub_installer_file
target_stub_installer = os.path.join(args.root_out_dir[0], target_stub_installer_file)
command = [apply_tag_exe, source_stub_installer, target_stub_installer, tag]
sp.check_call(command, stderr=sp.STDOUT)
return

def ParseArgs():
parser = argparse.ArgumentParser(description='build omaha installer')
parser.add_argument('--root_out_dir',
nargs=1)
parser.add_argument('--brave_installer_exe',
nargs=1)
parser.add_argument('--stub_installer_exe',
nargs=1)
parser.add_argument('--standalone_installer_exe',
nargs=1)
parser.add_argument('--guid',
nargs=1)
parser.add_argument('--install_switch',
nargs=1)
parser.add_argument('--tag_ap',
nargs=1)
parser.add_argument('--tag_app_name',
nargs=1)
parser.add_argument('--brave_full_version',
nargs=1)
return parser.parse_args()

# Wait to see ths compile logs. If not, elevated python program will quit w/o
# any notice.
def WaitFromUser():
raw_input('\nPress ENTER to exit.')

def Main(args):
ret = run_as_admin()
if ret is True:

This comment has been minimized.

Copy link
@simonhong

simonhong Oct 26, 2018

Author Collaborator

This code runs in a separate admin process.
non admin process just returned here. So, create_dist process is quit but in a separate process & terminal, omaha build is in-progress.

print 'I have admin privilege.'
args = ParseArgs()
omaha_dir = os.path.join(args.root_out_dir[0], '..', '..', 'brave', 'vendor', 'omaha')

# To build standalone installer, brave_installer should be copied into
# scons-out/. However, this folder is created during the build.
# Because of this scons-out folder isn't existed at first.
# So, Build all except brave stub/standalone installer first, then copy
# them. And build again finally to make standalone installer.
# Second build only makes standalone. So, this isn't same build with first
# build.
Build(args, omaha_dir)
PrepareStandalone(args, omaha_dir)
Build(args, omaha_dir)
# Create both(debug/release) executables
Tagging(args, omaha_dir, True)
Tagging(args, omaha_dir, False)

WaitFromUser()

return 0


if __name__ == '__main__':
sys.exit(Main(sys.argv))
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<response protocol="3.0">
<app appid="APP_GUID" status="ok">
<updatecheck status="ok">
<urls>
<url codebase="http://dl.google.com/foo/${INSTALLER_VERSION}/"/>

This comment has been minimized.

Copy link
@emerick

emerick Oct 26, 2018

Collaborator

Wasn't sure if the "foo" here was intentional?

This comment has been minimized.

Copy link
@simonhong

simonhong Oct 27, 2018

Author Collaborator

I found that this url doesn't have much meaning in standalone installer.
In normal situation(application is installed/updated from update server), omaha client receives response and use it to get specific installer files. (ex, the target installer url would be codebase/installer_file).
In this case, http://dl.google.com/foo/xx.xx.xx.xx/installer.exe is it.

When standalone installer is used, installer exe file is already located in local machine's folder. So, this url isn't used.
Of course, if we can specify base url of installer file it would be good as a description.

</urls>
<manifest version="${INSTALLER_VERSION}">
<packages>
<package name="BRAVE_INSTALLER_EXE" hash_sha256="${INSTALLER_HASH_SHA256}" size="${INSTALLER_SIZE}" required="true"/>
</packages>
<actions>
<action event="install" run="BRAVE_INSTALLER_EXE" arguments="INSTALL_SWITCH" needsadmin="true"/>
</actions>
</manifest>
</updatecheck>
</app>
</response>
@@ -4,6 +4,9 @@
:: tests do.
set OMAHA_PSEXEC_DIR=%ProgramFiles(x86)%\pstools

:: Set VS environment variables.
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat"

setlocal

rem -- Set all environment variables used by Hammer and Omaha. --
Submodule breakpad updated from 33c247 to 66571f
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.