From 9e900d3b79c6640b15eb5045f1c7ec9b829367e9 Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Sun, 3 Aug 2025 14:47:59 +0200 Subject: [PATCH] save --- lib/make.rb | 17 ++++++++++++++--- lib/system/debian.rb | 7 +++++++ lib/system/macos.rb | 7 +++++++ recipes/dry-run.yml | 2 +- recipes/python.yml | 9 ++++++--- recipes/ruby/macos.yml | 2 +- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lib/make.rb b/lib/make.rb index be1d190..e36943f 100644 --- a/lib/make.rb +++ b/lib/make.rb @@ -56,7 +56,9 @@ module Make @steps = makefile["steps"] || [] @environment = ENV.to_h.merge( - "PREFIX" => get_prefix + "PREFIX" => get_prefix, + "CPUS" => System.cpus.to_s, + "SUDO" => (@target == :user ? "" : "sudo") ) environment = makefile["environment"] @@ -69,13 +71,22 @@ module Make end def get_prefix + sys_prefix = case System.os_name + when :macos + "/usr" + else + "" + end + case @target when :user "#{ENV["HOME"]}/.local" when :package - "/pkg/#{@name}/#{@repository.branch}" + "#{sys_prefix}/pkg/#{@name}/#{@repository.branch}" when :system - "/" + "#{sys_prefix}/" + else + raise "Unknown target: #{@target.inspect}" end end diff --git a/lib/system/debian.rb b/lib/system/debian.rb index 61170c8..6504a2f 100644 --- a/lib/system/debian.rb +++ b/lib/system/debian.rb @@ -1,8 +1,15 @@ +require 'open3' + module DebianSystem def os_name "Debian Linux" end + def cpus + stdout, stderr, status = Open3.capture3("nproc") + stdout.strip.to_i + end + def install(packages) missing_packages = packages.reject { |pkg| package_installed?(pkg) } diff --git a/lib/system/macos.rb b/lib/system/macos.rb index 7cacd3d..b2a6a22 100644 --- a/lib/system/macos.rb +++ b/lib/system/macos.rb @@ -1,8 +1,15 @@ +require 'open3' + module MacOSSystem def os_name "macOS" end + def cpus + stdout, stderr, status = Open3.capture3("sysctl -n hw.ncpu") + stdout.strip.to_i + end + def install(packages) missing_packages = packages.reject { |pkg| package_installed?(pkg) } diff --git a/recipes/dry-run.yml b/recipes/dry-run.yml index f5258b5..77e8509 100644 --- a/recipes/dry-run.yml +++ b/recipes/dry-run.yml @@ -9,7 +9,7 @@ repository: branch: main steps: - - echo installing in $PREFIX + - echo installing in $PREFIX and cpus $CPUS - cd $WORK_DIR - ls diff --git a/recipes/python.yml b/recipes/python.yml index e476fd0..c25a402 100644 --- a/recipes/python.yml +++ b/recipes/python.yml @@ -18,6 +18,9 @@ repository: branch: v3.13.5 steps: - - ./configure --enable-optimizations --prefix=$HOME/.local - - make -j"$(nproc)" - - make install +# dat make -t pkg --cache --name python +# - ./configure --enable-optimizations --prefix=$HOME/.local +# - make -j"$(nproc)" + - ./configure --enable-optimizations --prefix=$PREFIX + - make -j$CPUS + - $SUDO make install diff --git a/recipes/ruby/macos.yml b/recipes/ruby/macos.yml index f55ec6e..c628e74 100644 --- a/recipes/ruby/macos.yml +++ b/recipes/ruby/macos.yml @@ -19,4 +19,4 @@ steps: # --with-readline-dir=$(brew --prefix readline) # --with-yaml-dir=$(brew --prefix libyaml) - make -j$(sysctl -n hw.ncpu) - - make install \ No newline at end of file + - make install