Skip to content

Commit

Permalink
Cleaning up global env code
Browse files Browse the repository at this point in the history
- Move include_dir inside build_dir
- Move some global variables from source code to rules
- Make adjustments for some commands to use the generated environment
  • Loading branch information
bazurbat committed Oct 20, 2021
1 parent e4e44fc commit 01a0ddb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
3 changes: 2 additions & 1 deletion env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jagen_debug="${jagen_debug-}"
jagen__src_dir="$jagen_dir/src"
jagen_root_lib_dir="$jagen_root_dir/lib"

jagen_include_dir="$jagen_root_dir/include"
jagen_build_dir="$jagen_root_dir/build"
jagen_include_dir="$jagen_build_dir/include"

jagen_build_verbose=${jagen_build_verbose-}

Expand Down
14 changes: 12 additions & 2 deletions lib/rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ config { 'self',
config { 'root',
dir = os.getenv('jagen_dir'),
root_dir = os.getenv('jagen_root_dir'),
build_dir = os.getenv('jagen_build_dir'),
include_dir = os.getenv('jagen_include_dir'),
bin_dir = '${root_dir}/bin',
build_dir = '${root_dir}/build',
dist_dir = '${root_dir}/dist',
include_dir = '${root_dir}/include',
lib_dir = '${root_dir}/lib',
log_dir = '${root_dir}/log',
src_dir = '${root_dir}/src',
build_file = '${build_dir}/build.ninja',
build_targets_file = '${build_dir}/.build-targets',
env = {
-- Disable passphrase querying.
GIT_SSH_COMMAND = 'ssh -o BatchMode=yes',
-- Do not prompt on the terminal (e.g. when asking for HTTP credentials).
GIT_TERMINAL_PROMPT = 0,
-- Never install the translations.
LINGUAS = '',
-- Do not run tools with an interactive graphical UI.
DISPLAY = ''
}
}

config { 'ccache',
Expand Down
4 changes: 0 additions & 4 deletions src/Ninja.lua
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,6 @@ function P.generate(rules, config, jagen)
}

local for_refresh = Command:new(jagen.cmd, 'find_for_refresh'):aslist()
local include_dir = config.include_dir
for pkg in each(rules) do
append(for_refresh, System.mkpath(include_dir, string.format('%s.sh', pkg.ref)))
end

append(lines, format_refresh(for_refresh))
-- append(lines, format_phony(for_refresh))
Expand Down
7 changes: 4 additions & 3 deletions src/Refresh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ function Refresh:run(args)

engine:finalize()

local include_dir = engine.config.root.include_dir

local self_config = engine.config.self
local root_config = engine.config.root

System.mkdir(root_config.build_dir, root_config.include_dir)
local build_dir = root_config.build_dir
local include_dir = root_config.include_dir

System.mkdir(build_dir, include_dir)

local targets = {}

Expand Down
11 changes: 5 additions & 6 deletions src/cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Ninja (https://ninja-build.org) to run the build system."
}

cmd_build() {
. "${jagen_include_dir:?}/self.config.sh"
. "${jagen_include_dir:?}/root.config.sh"

local IFS="$S"
local build_all no_rebuild follow_selected follow_all print_all is_quiet
local targets log logs err tries follow_pid pipe
Expand Down Expand Up @@ -208,18 +211,14 @@ echo_if_exists() {
}

cmd_find_for_refresh() {
. "$jagen_dir/src/common.sh" || return
local IFS="$jagen_S" paths='' dir
for dir in bin lib src; do
paths="${paths}${jagen_S}${jagen_dir}/${dir}"
done
if [ -d "$jagen_root_lib_dir" ]; then
paths="${paths}${jagen_S}${jagen_root_lib_dir}"
fi
paths=${paths#${jagen_S}}
paths="${paths}${jagen_S}${jagen_include_dir:?}"
paths="${paths#${jagen_S}}"
find $paths -type f -o -type d
echo "$jagen_root_dir"
echo_if_exists "$jagen_root_dir/config.sh"
echo_if_exists "$jagen_root_dir/env.sh"
echo_if_exists "$jagen_root_dir/jagen"
echo_if_exists "$jagen_root_dir/rules.lua"
Expand Down
7 changes: 4 additions & 3 deletions src/command/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,18 @@ function P:run(args)
end

local config = engine.config.root
local cmd = assert(engine.config.self.cmd)

write_targets(targets, args, config.build_targets_file)
write_targets(targets, args, assert(config.build_targets_file))

local args_path = System.mkpath(config.build_dir, '.build-args')
local args_path = System.mkpath(assert(config.build_dir), '.build-args')
local args_file = assert(io.open(args_path, 'w'))
if args._args then
args_file:write(table.concat(args._args, '\n'))
end
args_file:close()

local ok = Command:new(quote(config.cmd), 'build', tostring(args), unpack(table.keys(targets))):exec()
local ok = Command:new(quote(cmd), 'build', tostring(args), unpack(table.keys(targets))):exec()

-- io.open(args_path, 'w'):close()

Expand Down
9 changes: 0 additions & 9 deletions src/stages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@

. "$jagen_dir/env.sh" || { echo "Failed to load environment"; exit 1; }

# Disable passphrase querying
export GIT_SSH_COMMAND="ssh -o BatchMode=yes"
# Do not prompt on the terminal (e.g. when asking for HTTP credentials).
export GIT_TERMINAL_PROMPT=0
# Never install the translations.
export LINGUAS=""
# Do not allow to run tools with an interactive graphical UI
unset DISPLAY

jagen_build_args_file="${jagen_build_dir:?}/.build-args"

include "$jagen__src_dir/util"
Expand Down

0 comments on commit 01a0ddb

Please sign in to comment.