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

Auto-generate NTP backgrounds LICENSE file #8032

Merged
merged 1 commit into from
Feb 18, 2020
Merged
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
55 changes: 54 additions & 1 deletion 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') &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @fmarier better if this could be case insensitive. had to workaround in brave/brave-core#4864

(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