Skip to content

Commit

Permalink
Auto-generate NTP backgrounds LICENSE file (fixes brave/brave-browser…
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarier committed Feb 17, 2020
1 parent d679ca6 commit b7ce0a7
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion build/lib/licensing.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,56 @@ const listSubComponents = (baseDir) => {
return subComponents
}

const listNtpBackgrounds = (metadataFile) => {
const metadata = fs.readFileSync(metadataFile).toString()
let images = []
// Hack to import this TypeScript file in Node:
eval(metadata.replace('export const images: NewTab.Image[]', 'images'))
return images
}

const getValidatedComponentField = (component, fieldName) => {
const fieldValue = component[fieldName]
if (!fieldValue) {
console.error('Missing' + fieldName + ' for background image ' + component['name'])
process.exit(1)
}
return fieldValue
}

const generateNtpBackgroundsLicense = (preamble, components) => {
let componentNotices = ''

for (let component of components) {
if (componentNotices.length != 0) {
componentNotices += '\n'
}

const fileName = getValidatedComponentField(component, 'source')
const authorName = getValidatedComponentField(component, 'author')
const authorLink = getValidatedComponentField(component, 'link')
const originalUrl = getValidatedComponentField(component, 'originalUrl')
const license = getValidatedComponentField(component, 'license')
if ((license != 'used with permission') &&
(license.substr(0, 8) != 'https://') && (license.substr(0, 7) != 'http://')) {
console.error('Invalid license for background image ' + component['name'] + '. It needs to be a URL or the string "used with permission".')
process.exit(1)
}

componentNotices += 'File: ' + fileName + '\n' +
'Author: ' + authorName + ' (' + authorLink + ')\n' +
'URL: ' + originalUrl + '\n' +
'License: ' + license + '\n'
}

return preamble + '\n\n' + componentNotices
}

const licensing = {
updateLicenses: () => {
console.log('regenerating LICENSE files...')
const braveComponentsThirdPartyDir = path.join(config.projects['brave-core'].dir, 'components', 'third_party')
const braveComponentsDir = path.join(config.projects['brave-core'].dir, 'components')
const braveComponentsThirdPartyDir = path.join(braveComponentsDir, 'third_party')

// Brave Ad Block component
const braveAdBlockDir = path.join(braveComponentsThirdPartyDir, 'adblock')
Expand All @@ -154,6 +200,13 @@ const licensing = {
let localDataLicense = generateExternalComponentLicenseFile(localDataPreamble, localDataComponents)
fs.writeFileSync(path.join(braveComponentsThirdPartyDir, 'local_data', 'LICENSE'), localDataLicense)
console.log(' - ' + localDataComponents.length + ' sub-components added in local_data/LICENSE')

const braveNtpDataDir = path.join(braveComponentsDir, 'brave_new_tab_ui', 'data')
let ntpBackgroundsPreamble = 'These licenses do not apply to any of the code shipped with the Brave Browser and instead apply to background images used on the new tab page. The Brave Browser and such data files are separate and independent works.'
const ntpBackgrounds = listNtpBackgrounds(path.join(braveNtpDataDir, 'backgrounds.ts'))
let ntpBackgroundsLicense = generateNtpBackgroundsLicense(ntpBackgroundsPreamble, ntpBackgrounds)
fs.writeFileSync(path.join(braveNtpDataDir, 'LICENSE'), ntpBackgroundsLicense)
console.log(' - ' + ntpBackgrounds.length + ' sub-components added in brave_new_tab_ui/data/LICENSE')
}
}

Expand Down

0 comments on commit b7ce0a7

Please sign in to comment.