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

Bower #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cwd": "vendor",
"directory": "grammars"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ lib/linguist/samples.json
/node_modules
test/fixtures/ace_modes.json
/vendor/gems/
vendor/grammars
712 changes: 0 additions & 712 deletions .gitmodules

This file was deleted.

6 changes: 3 additions & 3 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ http://svn.textmate.org/trunk/Review/Bundles/VHDL.tmbundle:
- source.vhdl
http://svn.textmate.org/trunk/Review/Bundles/XQuery.tmbundle:
- source.xquery
https://bitbucket.org/Clams/sublimesystemverilog/get/default.tar.gz:
- source.systemverilog
- source.ucfconstraints
https://fan.googlecode.com/hg-history/Build%201.0.55/adm/tools/textmate/Fan.tmbundle/Syntaxes/Fan.tmLanguage:
- source.fan
vendor/grammars/Agda.tmbundle:
Expand Down Expand Up @@ -566,6 +563,9 @@ vendor/grammars/sublimeassembly/:
vendor/grammars/sublimeprolog/:
- source.prolog
- source.prolog.eclipse
vendor/grammars/sublimesystemverilog:
- source.systemverilog
- source.ucfconstraints
vendor/grammars/sublimetext-cuda-cpp:
- source.cuda-c++
vendor/grammars/swift.tmbundle:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"repository": "https://github.com/github/linguist",
"dependencies": {
"bower": "^1.7.9",
"season": "~>5.0"
},
"license": "MIT"
Expand Down
7 changes: 2 additions & 5 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ set -e
cd "$(dirname "$0")/.."

bundle config --local path vendor/gems

bundle check > /dev/null 2>&1 || bundle install

git submodule init
git submodule sync --quiet
script/fast-submodule-update
npm install
bower install
8 changes: 2 additions & 6 deletions script/travis/before_install
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@ set -ex
# Fetch all commits/refs needed to run our tests.
git fetch origin master:master v2.0.0:v2.0.0 test/attributes:test/attributes test/master:test/master

# Replace SSH links to submodules by HTTPS links.
sed -i 's/[email protected]:/https:\/\/github.com\//' .gitmodules

git submodule init
git submodule sync --quiet
script/fast-submodule-update
npm install
bower install
162 changes: 9 additions & 153 deletions test/test_grammars.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
require_relative "./helper"
require "json"

class TestGrammars < Minitest::Test
ROOT = File.expand_path("../..", __FILE__)

# List of projects that are allowed without licenses
PROJECT_WHITELIST = [
# Dual MIT and GPL license
"vendor/grammars/language-csharp",
"vendor/grammars/sublimeassembly"
].freeze

# List of allowed SPDX license names
LICENSE_WHITELIST = %w[
apache-2.0
bsd-2-clause
bsd-3-clause
isc
mit
mpl-2.0
public
textmate
unlicense
wtfpl
zlib
].freeze

def setup
@grammars = YAML.load(File.read(File.join(ROOT, "grammars.yml")))
end
Expand All @@ -35,29 +14,6 @@ def test_no_duplicate_scopes
assert duplicates.empty?, "The following scopes appear in grammars.yml more than once:\n#{duplicates.sort.join("\n")}"
end

def test_submodules_are_in_sync
# Strip off paths inside the submodule so that just the submodule path remains.
listed_submodules = @grammars.keys.grep(/vendor\/grammars/).map { |source| source[%r{vendor/grammars/[^/]+}] }

nonexistent_submodules = listed_submodules - submodule_paths
unlisted_submodules = submodule_paths - listed_submodules

message = ""
unless nonexistent_submodules.empty?
message << "The following submodules are listed in grammars.yml but don't seem to exist in the repository.\n"
message << "Either add them using `git submodule add` or remove them from grammars.yml.\n"
message << nonexistent_submodules.sort.join("\n")
end
unless unlisted_submodules.empty?
message << "\n" unless message.empty?
message << "The following submodules exist in the repository but aren't listed in grammars.yml.\n"
message << "Either add them to grammars.yml or remove them from the repository using `git rm`.\n"
message << unlisted_submodules.sort.join("\n")
end

assert nonexistent_submodules.empty? && unlisted_submodules.empty?, message
end

def test_local_scopes_are_in_sync
actual = YAML.load(`"#{File.join(ROOT, "script", "convert-grammars")}" --output - --no-install --no-remote`)
assert $?.success?, "script/convert-grammars failed"
Expand All @@ -71,116 +27,16 @@ def test_local_scopes_are_in_sync
end
end

def test_submodules_have_recognized_licenses
unrecognized = submodule_licenses.select { |k,v| v.nil? && Licensee::FSProject.new(k).license_file }
unrecognized.reject! { |k,v| PROJECT_WHITELIST.include?(k) }
message = "The following submodules have unrecognized licenses:\n* #{unrecognized.keys.join("\n* ")}\n"
message << "Please ensure that the project's LICENSE file contains the full text of the license."
assert_equal Hash.new, unrecognized, message
end

def test_submodules_have_licenses
unlicensed = submodule_licenses.select { |k,v| v.nil? }.reject { |k,v| PROJECT_WHITELIST.include?(k) }
message = "The following submodules don't have licenses:\n* #{unlicensed.keys.join("\n* ")}\n"
message << "Please ensure that the project has a LICENSE file, and that the LICENSE file contains the full text of the license."
assert_equal Hash.new, unlicensed, message
end

def test_submodules_have_approved_licenses
unapproved = submodule_licenses.reject { |k,v| LICENSE_WHITELIST.include?(v) || PROJECT_WHITELIST.include?(k) }.map { |k,v| "#{k}: #{v}"}
message = "The following submodules have unapproved licenses:\n* #{unapproved.join("\n* ")}\n"
message << "The license must be added to the LICENSE_WHITELIST in /test/test_grammars.rb once approved."
assert_equal [], unapproved, message
end

def test_submodules_whitelist_has_no_extra_entries
skip("Need to work out how to handle dual-licensed entities")
extra_whitelist_entries = PROJECT_WHITELIST - submodule_licenses.select { |k,v| v.nil? }.keys
not_present = extra_whitelist_entries.reject { |k,v| Dir.exist?(k) }
licensed = extra_whitelist_entries.select { |k,v| submodule_licenses[k] }

msg = "The following whitelisted submodules don't appear to be part of the project:\n* #{not_present.join("\n* ")}"
assert_equal [], not_present, msg

msg = "The following whitelisted submodules actually have licenses and don't need to be whitelisted:\n* #{licensed.join("\n* ")}"
assert_equal [], licensed, msg
end

def test_submodules_use_https_links
File.open(".gitmodules", "r") do |fh|
ssh_submodules = []
fh.each_line do |line|
if matches = line.match(/url = (git@.*)/)
submodule_link = matches.captures[0]
ssh_submodules.push(submodule_link)
end
def test_grammars_use_https_links
ssh_grammars = []
JSON.parse(File.read(File.join(ROOT, "vendor/bower.json")))["dependencies"].each do |dir, url|
if matches = url.match(/(git@.*)/)
submodule_link = matches.captures[0]
ssh_grammars.push(submodule_link)
end
msg = "The following submodules don't have an HTTPS link:\n* #{ssh_submodules.join("\n* ")}"
assert_equal [], ssh_submodules, msg
end
end

private

def submodule_paths
@submodule_paths ||= `git config --list --file "#{File.join(ROOT, ".gitmodules")}"`.lines.grep(/\.path=/).map { |line| line.chomp.split("=", 2).last }
end

# Returns a hash of submodules in the form of submodule_path => license
def submodule_licenses
@@submodule_licenses ||= begin
submodules = {}
submodule_paths.each { |submodule| submodules[submodule] = submodule_license(submodule) }
submodules
end
end

# Given the path to a submodule, return its SPDX-compliant license key
def submodule_license(submodule)
# Prefer Licensee to detect a submodule's license
project = Licensee::FSProject.new(submodule)
return project.license.key if project.license

# We know a license file exists, but Licensee wasn't able to detect the license,
# Let's try our own more permissive regex method
if project.license_file
path = File.expand_path project.license_file.path, submodule
license = classify_license(path)
return license if license
end

# Neither Licensee nor our own regex was able to detect the license, let's check the readme
files = Dir[File.join(ROOT, submodule, "*")]
if readme = files.find { |path| File.basename(path) =~ /\Areadme\b/i }
classify_license(readme)
end
end

def classify_license(path)
content = File.read(path)
return unless content =~ /\blicen[cs]e\b/i
if content.include?("Apache License") && content.include?("2.0")
"apache-2.0"
elsif content.include?("GNU") && content =~ /general/i && content =~ /public/i
if content =~ /version 2/i
"gpl-2.0"
elsif content =~ /version 3/i
"gpl-3.0"
end
elsif content.include?("GPL") && content.include?("http://www.gnu.org/licenses/gpl.html")
"gpl-3.0"
elsif content.include?("Creative Commons Attribution-Share Alike 3.0")
"cc-by-sa-3.0"
elsif content.include?("tidy-license.txt") || content.include?("If not otherwise specified (see below)") || content.include?("Permission to copy, use, modify, sell and distribute this")
"textmate"
elsif content.include?("Permission is hereby granted") || content =~ /\bMIT\b/
"mit"
elsif content.include?("This package is provided as-is and is placed in the Public Domain")
"public"
elsif content.include?("http://www.wtfpl.net/txt/copying/")
"wtfpl"
elsif content.include?("zlib") && content.include?("license") && content.include?("2. Altered source versions must be plainly marked as such")
"zlib"
end
msg = "The following submodules don't have an HTTPS link:\n* #{ssh_grammars.join("\n* ")}"
assert_equal [], ssh_grammars, msg
end
end
Loading