Skip to content

Commit

Permalink
Merge pull request #1 from brave/master
Browse files Browse the repository at this point in the history
Rebase
  • Loading branch information
Akarshan Biswas authored Aug 21, 2019
2 parents 7f75ea2 + bfecdc6 commit f4e78eb
Show file tree
Hide file tree
Showing 18 changed files with 1,346 additions and 176 deletions.
25 changes: 19 additions & 6 deletions build/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ const checkVersionsMatch = () => {
const found = versionData.match(re)
const braveVersionFromChromeFile = `${found[2]}.${found[3]}.${found[4]}`
if (braveVersionFromChromeFile !== config.braveVersion) {
// Only a warning. The CI environment will choose to proceed or not within its own script.
console.warn(`Version files do not match!\nsrc/chrome/VERSION: ${braveVersionFromChromeFile}\nbrave-browser package.json version: ${config.braveVersion}`)
if (config.buildConfig === 'Release') {
process.exit(1)
}
}
}

Expand All @@ -96,9 +94,24 @@ const build = (buildConfig = config.defaultBuildConfig, options) => {
touchOverriddenVectorIconFiles()
util.updateBranding()

util.buildTarget()
if (config.shouldSign()) {
util.signApp()
if (config.xcode_gen_target) {
util.generateXcodeWorkspace()
} else {
util.buildTarget()
if (config.shouldSign()) {
util.signApp()
}

if (process.platform === 'win32') {
// Sign only binaries for widevine sig generation.
// Other binaries will be done during the create_dist.
// Then, both are merged whenarchive for installer is created.
util.signWinBinaries()

if (config.brave_enable_cdm_host_verification) {
util.generateWidevineSigFiles()
}
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions build/lib/calculateFileChecksum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2019 The Brave Authors. All rights reserved.
// 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/.

const crypto = require('crypto')
const fs = require('fs')

module.exports = function CalculateFileChecksum(filePath, algorithm = 'sha256') {
return new Promise((resolve, reject) => {
try {
const checksumGenerator = crypto.createHash(algorithm);
const fileStream = fs.createReadStream(filePath)
fileStream.on('error', function (err) {
err.message = `CalculateFileChecksum error in FileStream at path "${filePath}": ${err.message}`
reject(err)
})
checksumGenerator.once('readable', function () {
const checksum = checksumGenerator.read().toString('hex')
resolve(checksum)
})
fileStream.pipe(checksumGenerator)
} catch (err) {
err.message = `CalculateFileChecksum error using algorithm "${algorithm}" at path "${filePath}": ${err.message}`
reject(err);
}
});
}
45 changes: 45 additions & 0 deletions build/lib/calculateFileChecksum.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const path = require('path')
const fs = require('fs-extra')
const os = require('os')
const calculateFileChecksum = require('./calculateFileChecksum')

const dirPrefixTmp = 'brave-browser-test-calculate-file-checksum-'
const testFile1Name = 'file1'
const testFile1InitialContent = 'this is a test'
const encoding = 'utf8'
let testDirPath, testFile1Path

beforeEach(async function () {
// Test directory
testDirPath = await fs.mkdtemp(path.join(os.tmpdir(), dirPrefixTmp))
// Initial test file
testFile1Path = path.join(testDirPath, testFile1Name)
await fs.writeFile(testFile1Path, testFile1InitialContent, encoding)
})

afterEach(async function () {
// Remove test directory
try {
await fs.remove(testDirPath)
} catch (err) {
console.warn('Test cleanup: could not remove temp directory at ' + testDirPath)
}
})

test('generates a checksum', async function () {
const checksum1 = await calculateFileChecksum(testFile1Path)
expect(checksum1).toBeTruthy()
})

test('checksum is stable', async function () {
const checksum1 = await calculateFileChecksum(testFile1Path)
const checksum2 = await calculateFileChecksum(testFile1Path)
expect(checksum2).toBe(checksum1)
})

test('checksum changes when file contents change', async function () {
const checksum1 = await calculateFileChecksum(testFile1Path)
await fs.writeFile(testFile1Path, testFile1InitialContent + testFile1InitialContent, encoding)
const checksum2 = await calculateFileChecksum(testFile1Path)
expect(checksum2).not.toBe(checksum1)
})
Loading

0 comments on commit f4e78eb

Please sign in to comment.