mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-09 15:37:56 -05:00
crew: Isolate package classes from global scope (#7283)
* crew: Isolate package classes from global scope * Use `require_relative` * Fix typo * Prevent duplicate loading packages * Bump version
This commit is contained in:
14
bin/crew
14
bin/crew
@@ -14,6 +14,7 @@ require_relative '../lib/util'
|
|||||||
require_relative '../lib/convert_size'
|
require_relative '../lib/convert_size'
|
||||||
require_relative '../lib/downloader'
|
require_relative '../lib/downloader'
|
||||||
require_relative '../lib/deb_utils'
|
require_relative '../lib/deb_utils'
|
||||||
|
require_relative '../lib/package'
|
||||||
|
|
||||||
# Add lib to LOAD_PATH
|
# Add lib to LOAD_PATH
|
||||||
$LOAD_PATH.unshift "#{CREW_LIB_PATH}lib"
|
$LOAD_PATH.unshift "#{CREW_LIB_PATH}lib"
|
||||||
@@ -185,21 +186,12 @@ end
|
|||||||
|
|
||||||
def set_package(pkgName, pkgPath)
|
def set_package(pkgName, pkgPath)
|
||||||
begin
|
begin
|
||||||
require_relative pkgPath
|
@pkg = Package.load_package(pkgPath, pkgName)
|
||||||
rescue SyntaxError => e
|
rescue SyntaxError => e
|
||||||
puts "#{e.class}: #{e.message}".red
|
warn "#{e.class}: #{e.message}".red
|
||||||
end
|
end
|
||||||
|
|
||||||
# add `PKG_` to the beginning of class name if it starts with a digit
|
|
||||||
if pkgName =~ /^[0-9]/
|
|
||||||
className = 'PKG_' + pkgName
|
|
||||||
else
|
|
||||||
className = pkgName.capitalize
|
|
||||||
end
|
|
||||||
|
|
||||||
@pkg = Object.const_get(className)
|
|
||||||
@pkg.build_from_source = true if @opt_recursive
|
@pkg.build_from_source = true if @opt_recursive
|
||||||
@pkg.name = pkgName
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_packages
|
def list_packages
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Defines common constants used in different parts of crew
|
# Defines common constants used in different parts of crew
|
||||||
|
|
||||||
CREW_VERSION = '1.24.0'
|
CREW_VERSION = '1.25.0'
|
||||||
|
|
||||||
ARCH_ACTUAL = `uname -m`.chomp
|
ARCH_ACTUAL = `uname -m`.chomp
|
||||||
# This helps with virtualized builds on aarch64 machines
|
# This helps with virtualized builds on aarch64 machines
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'package_helpers'
|
require_relative 'package_helpers'
|
||||||
|
|
||||||
class Package
|
class Package
|
||||||
property :description, :homepage, :version, :license, :compatibility,
|
property :description, :homepage, :version, :license, :compatibility,
|
||||||
@@ -6,7 +6,7 @@ class Package
|
|||||||
:git_branch, :git_hashtag
|
:git_branch, :git_hashtag
|
||||||
|
|
||||||
boolean_property = %i[conflicts_ok git_fetchtags gnome is_fake is_musl
|
boolean_property = %i[conflicts_ok git_fetchtags gnome is_fake is_musl
|
||||||
is_static no_compile_needed no_env_options no_fhs
|
is_static no_compile_needed no_env_options no_fhs
|
||||||
no_patchelf no_zstd patchelf git_clone_deep
|
no_patchelf no_zstd patchelf git_clone_deep
|
||||||
no_git_submodules]
|
no_git_submodules]
|
||||||
|
|
||||||
@@ -25,6 +25,20 @@ class Package
|
|||||||
attr_accessor :name, :is_dep, :in_build, :build_from_source, :in_upgrade
|
attr_accessor :name, :is_dep, :in_build, :build_from_source, :in_upgrade
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.load_package ( pkgFile, pkgName = File.basename(pkgFile, '.rb') )
|
||||||
|
# self.load_package: load a package under 'Package' class scope
|
||||||
|
#
|
||||||
|
className = pkgName.capitalize
|
||||||
|
|
||||||
|
# read and eval package script under 'Package' class
|
||||||
|
class_eval( File.read(pkgFile), pkgFile ) unless const_defined?("Package::#{className}")
|
||||||
|
|
||||||
|
pkgObj = const_get(className)
|
||||||
|
pkgObj.name = pkgName
|
||||||
|
|
||||||
|
return pkgObj
|
||||||
|
end
|
||||||
|
|
||||||
def self.dependencies
|
def self.dependencies
|
||||||
# We need instance variable in derived class, so not define it here,
|
# We need instance variable in derived class, so not define it here,
|
||||||
# base class. Instead of define it, we initialize it in a function
|
# base class. Instead of define it, we initialize it in a function
|
||||||
@@ -47,7 +61,7 @@ class Package
|
|||||||
# highlight_build_deps: include corresponding symbols in return value, you can convert it to actual ascii color codes later
|
# highlight_build_deps: include corresponding symbols in return value, you can convert it to actual ascii color codes later
|
||||||
# exclude_buildessential: do not insert `buildessential` dependency automatically
|
# exclude_buildessential: do not insert `buildessential` dependency automatically
|
||||||
#
|
#
|
||||||
# top_level: if set to true, return satisfied dependencies
|
# top_level: if set to true, return satisfied dependencies
|
||||||
# (dependencies that might be a sub-dependency of a dependency that checked before),
|
# (dependencies that might be a sub-dependency of a dependency that checked before),
|
||||||
# always set to false if this function is called in recursive loop (see `expandedDeps` below)
|
# always set to false if this function is called in recursive loop (see `expandedDeps` below)
|
||||||
#
|
#
|
||||||
@@ -56,7 +70,7 @@ class Package
|
|||||||
# add current package to @checked_list for preventing extra checks
|
# add current package to @checked_list for preventing extra checks
|
||||||
@checked_list.merge!({ pkgName => pkgTags })
|
@checked_list.merge!({ pkgName => pkgTags })
|
||||||
|
|
||||||
pkgObj = Object.const_get(pkgName.capitalize)
|
pkgObj = load_package("#{CREW_PACKAGES_PATH}/#{pkgName}.rb")
|
||||||
is_source = pkgObj.is_source?(ARCH.to_sym) or pkgObj.build_from_source
|
is_source = pkgObj.is_source?(ARCH.to_sym) or pkgObj.build_from_source
|
||||||
deps = pkgObj.dependencies
|
deps = pkgObj.dependencies
|
||||||
|
|
||||||
@@ -81,7 +95,6 @@ class Package
|
|||||||
tags = (pkgTags.include?(:build)) ? pkgTags : depTags
|
tags = (pkgTags.include?(:build)) ? pkgTags : depTags
|
||||||
|
|
||||||
if @checked_list.keys.none?(dep)
|
if @checked_list.keys.none?(dep)
|
||||||
require_relative "#{CREW_PACKAGES_PATH}/#{dep}.rb"
|
|
||||||
# check dependency by calling this function recursively
|
# check dependency by calling this function recursively
|
||||||
next send(__method__, dep,
|
next send(__method__, dep,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
|
|||||||
@@ -20,9 +20,10 @@ A simple example of a test script called `my_test` is below:
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
# Makes sure buildessential package depends on gcc
|
# Makes sure buildessential package depends on gcc
|
||||||
|
require_relative "../lib/package"
|
||||||
|
|
||||||
|
pkg = Package.load_package('../package/buildessential.rb')
|
||||||
|
|
||||||
require_relative("../packages/buildessential")
|
|
||||||
pkg = Object.const_get('Buildessential')
|
|
||||||
if pkg.dependencies and pkg.dependencies.has_key?('gcc') then
|
if pkg.dependencies and pkg.dependencies.has_key?('gcc') then
|
||||||
puts "Everything works properly.".lightgreen
|
puts "Everything works properly.".lightgreen
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
require 'find'
|
require 'find'
|
||||||
require_relative '../lib/const'
|
require_relative '../lib/const'
|
||||||
require_relative '../lib/color'
|
require_relative '../lib/color'
|
||||||
|
require_relative '../lib/package'
|
||||||
|
|
||||||
@all_pkgs = {}
|
@all_pkgs = {}
|
||||||
|
|
||||||
@@ -13,11 +14,9 @@ $LOAD_PATH.unshift '../lib'
|
|||||||
puts "Running dependency cycle tests...\n".yellow
|
puts "Running dependency cycle tests...\n".yellow
|
||||||
|
|
||||||
# Loads all packages
|
# Loads all packages
|
||||||
Dir.glob('../packages/*.rb').each do |filename|
|
Dir['../packages/*.rb'].each do |filename|
|
||||||
name = File.basename(filename, '.rb')
|
name = File.basename(filename, '.rb')
|
||||||
require_relative("../packages/#{name}")
|
pkg = Package.load_package(filename, name)
|
||||||
pkg = Object.const_get(name.capitalize)
|
|
||||||
pkg.name = name
|
|
||||||
@all_pkgs[name] = pkg
|
@all_pkgs[name] = pkg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user