Skip to content

Commit

Permalink
Merge pull request #61 from brave/reduce-rebuild-size
Browse files Browse the repository at this point in the history
actually write to the output dir so we don't rebuild every time
  • Loading branch information
bbondy authored Sep 8, 2018
2 parents 55f68be + 4958049 commit 4829386
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 43 deletions.
39 changes: 23 additions & 16 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@ action("brave-extension") {
"app/braveShieldsPanel.tsx",
]
script = "py-scripts/build-brave-extension.py"
args = [ rebase_path("../.."), rebase_path(root_build_dir) ]

build_dir = "${root_gen_dir}/brave_extension"

args = [ "--output_dir", rebase_path("//brave/browser/resources/brave_extension"),
"--brave_extension_dir", rebase_path("."),
"--build_dir", rebase_path(build_dir) ]

outputs = [
"$target_gen_dir/brave_extension/build/background.html",
"$target_gen_dir/brave_extension/build/js/background.bundle.js",
"$target_gen_dir/brave_extension/build/js/content.bundle.js",
"$target_gen_dir/brave_extension/build/js/braveShieldsPanel.bundle.js",
"$target_gen_dir/brave_extension/build/braveShieldsPanel.html",
"$target_gen_dir/brave_extension/build/bravelizer.css",
"$target_gen_dir/brave_extension/build/img/icon-16.png",
"$target_gen_dir/brave_extension/build/img/icon-32.png",
"$target_gen_dir/brave_extension/build/img/icon-48.png",
"$target_gen_dir/brave_extension/build/img/icon-64.png",
"$target_gen_dir/brave_extension/build/img/icon-128.png",
"$target_gen_dir/brave_extension/build/img/icon-256.png",
"$target_gen_dir/brave_extension/build/img/icon.svg",
"$target_gen_dir/brave_extension/build/img/icon-off.svg",
"$target_gen_dir/brave_extension/build/_locales/en_US/messages.json",
"$build_dir/background.html",
"$build_dir/manifest.json",
"$build_dir/js/background.bundle.js",
"$build_dir/js/content.bundle.js",
"$build_dir/js/braveShieldsPanel.bundle.js",
"$build_dir/braveShieldsPanel.html",
"$build_dir/bravelizer.css",
"$build_dir/img/icon-16.png",
"$build_dir/img/icon-32.png",
"$build_dir/img/icon-48.png",
"$build_dir/img/icon-64.png",
"$build_dir/img/icon-128.png",
"$build_dir/img/icon-256.png",
"$build_dir/img/icon.svg",
"$build_dir/img/icon-off.svg",
"$build_dir/_locales/en_US/messages.json",
]

# For macOS deps is bounded in //chrome:chrome_framework
Expand Down
33 changes: 17 additions & 16 deletions py-scripts/build-brave-extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import argparse
import os
import sys
import shutil
Expand All @@ -10,21 +10,27 @@


def main():
brave_extension_dir = os.path.realpath(os.path.dirname(
os.path.dirname(os.path.realpath(__file__))))
brave_core_dir = os.path.dirname(os.path.dirname(brave_extension_dir))
brave_core_src_dir = sys.argv[1]
brave_extension_browser_resources_dir = os.path.join(brave_core_src_dir, 'browser', 'resources', 'brave_extension')
parser = argparse.ArgumentParser(description='Build Brave extension')
parser.add_argument('--output_dir')
parser.add_argument('--brave_extension_dir')
parser.add_argument('--build_dir')
args = parser.parse_args()

brave_extension_dir = os.path.abspath(args.brave_extension_dir)
build_dir = os.path.abspath(args.build_dir)
output_dir = os.path.abspath(args.output_dir)

os.chdir(brave_extension_dir)
build_extension('.')
build_dir_path = os.path.join(brave_extension_dir, 'build')
copy_output(build_dir_path, brave_extension_browser_resources_dir)
build_extension('.', build_dir)
copy_output(build_dir, output_dir)

def build_extension(dirname, env=None):

def build_extension(dirname, build_dir, env=None):
if env is None:
env = os.environ.copy()

env["TARGET_GEN_DIR"] = os.path.abspath(build_dir)

args = [NPM, 'run', 'build']
with scoped_cwd(dirname):
execute_stdout(args, env)
Expand All @@ -36,12 +42,7 @@ def copy_output(build_dir, output_dir):
os.rmdir(output_dir)
except:
pass
try:
os.mkdir(DIST_DIR)
copy_app_to_dist()
except:
pass
shutil.copytree('build', output_dir)
shutil.copytree(build_dir, output_dir)

if __name__ == '__main__':
sys.exit(main())
4 changes: 3 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

const tasks = require('./tasks')

const buildDir = process.env.TARGET_GEN_DIR

tasks.replaceWebpack()
console.log('[Copy assets]')
console.log('-'.repeat(80))
tasks.copyAssets('build')
tasks.copyAssets('build', buildDir)

console.log('[Webpack Build]')
console.log('-'.repeat(80))
Expand Down
14 changes: 7 additions & 7 deletions scripts/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ exports.replaceWebpack = () => {
replaceTasks.forEach(task => cp(task.from, task.to))
}

exports.copyAssets = (type) => {
exports.copyAssets = (type, outputDir) => {
const env = type === 'build' ? 'prod' : type
rm('-rf', type)
mkdir(type)
cp(`app/manifest.${env}.json`, `${type}/manifest.json`)
cp('-R', 'app/_locales/', type)
cp('-R', 'app/assets/*', type)
exec(`pug -O "{ env: '${env}' }" -o ${type} app/views/`)
rm('-rf', outputDir)
mkdir(outputDir)
cp(`app/manifest.${env}.json`, `${outputDir}/manifest.json`)
cp('-R', 'app/_locales/', outputDir)
cp('-R', 'app/assets/*', outputDir)
exec(`pug -O "{ env: '${env}' }" -o ${outputDir} app/views/`)
}
2 changes: 1 addition & 1 deletion webpack/dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const baseDevConfig = () => ({
path: '/js/__webpack_hmr'
},
output: {
path: path.join(__dirname, '../dev/js'),
path: path.join(process.env.TARGET_GEN_DIR, 'js'),
filename: '[name].bundle.js',
chunkFilename: '[id].chunk.js'
},
Expand Down
4 changes: 2 additions & 2 deletions webpack/prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
]
},
output: {
path: path.join(__dirname, '../build/js'),
path: path.join(process.env.TARGET_GEN_DIR, 'js'),
filename: '[name].bundle.js',
chunkFilename: '[id].chunk.js'
},
Expand Down Expand Up @@ -63,4 +63,4 @@ module.exports = {
]
}]
}
}
}

0 comments on commit 4829386

Please sign in to comment.