Skip to content

Commit

Permalink
Remove config generation from init, make root rules optional
Browse files Browse the repository at this point in the history
  • Loading branch information
bazurbat committed Nov 30, 2021
1 parent b6e8f04 commit ac9e997
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 73 deletions.
69 changes: 5 additions & 64 deletions init
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set -ef

jagen_url="https://github.com/bazurbat/jagen.git"
env_file="env.sh"
config_file="config.sh"
runner_script="jagen"

NL=$(printf '\n!'); NL=${NL%!}
Expand All @@ -13,7 +12,7 @@ show_usage() {
cat <<EOF
jagen-init
Initialize a directory as a Jagen build root or project
Initialize a directory as Jagen workspace
USAGE
Expand All @@ -24,10 +23,10 @@ USAGE
DESCRIPTION
The script sets up the current working directory to act as a Jagen workspace.
When piped to a shell it will clone the Jagen source repository on its own or
it can be run locally by reaching out with a relative path to an already
checked out Jagen source repository.
The script sets up the current working directory as Jagen workspace.
When piped to Shell it will clone the Jagen source repository into the
'.jagen' subdirectory. Alternatively, it can be run locally by reaching out
with a relative path to an already checked out Jagen source repository.
OPTIONS
Expand All @@ -37,7 +36,6 @@ OPTIONS
-j|--jagen-branch clone the specified Jagen branch
--root force init as a build root
--project force init as a project
--skip-config do not generate config.sh
-L add a directory to the layers search path
EOF
Expand Down Expand Up @@ -86,7 +84,6 @@ is_build_root() {
local dir="${1:-$PWD}"
[ -d "$dir" ] &&
[ -f "$dir/$env_file" ] &&
[ -f "$dir/$config_file" ] &&
[ -x "$dir/$runner_script" ]
}

Expand All @@ -108,8 +105,6 @@ parse_command_line() {
init_root=1 ;;
--project)
init_project=1 ;;
--skip-config)
init_skip_config=1 ;;
-L) [ "$2" ] || die "the -L option requires a directory argument"
init_layer_path="${init_layer_path}${NL}${2}"; shift ;;
-*) die "invalid option: $1" ;;
Expand Down Expand Up @@ -166,52 +161,6 @@ EOF
chmod +x "$runner_script"
}

write_config() {
cat >"$config_file" <<EOF
# jagen_root_dir - refers to the location of the current build root
EOF
if [ "$jagen_project_dir" ]; then
cat >>"$config_file" <<EOF
# A directory of the project associated with this root.
jagen_project_dir="$jagen_project_dir"
EOF
fi
if [ "$jagen_layers" ]; then
cat >>"$config_file" <<EOF
# A newline-separated list of directories with additional package definitions.
jagen_layers="$jagen_layers"
EOF
fi
if [ "$jagen_layer_path" ]; then
cat >>"$config_file" <<EOF
# A newline-separated list of directories to search for unqualified layers.
jagen_layer_path="$jagen_layer_path"
EOF
fi
cat >>"$config_file" <<EOF
# A directory for downloaded distribution files.
jagen_dist_dir="\$jagen_root_dir/dist"
# A directory for packages sources.
jagen_src_dir="\$jagen_root_dir/src"
# A space-separated list of optional features:
# ccache - wrap compilation commands with ccache
# offline - skip network operations
jagen_flags=""
# A space-separated list of package names excluded from cleaning and updating.
jagen_source_exclude=""
# The default build profile: release|debug|release_with_debug
jagen_build_profile="release"
EOF
}

main() {
local layer path item tmp_list
local layer_count=0 layer_path_count=0
Expand Down Expand Up @@ -329,14 +278,6 @@ main() {
write_env
write_runner

if [ -z "$init_skip_config" ]; then
if [ -f "$config_file" ]; then
say "backing up an existing ${config_file} as ${config_file}.bak"
cp -f "$config_file" "${config_file}.bak"
fi
write_config "$config_file"
fi

. ./env.sh
jagen refresh
}
Expand Down
17 changes: 9 additions & 8 deletions src/Engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ end
function Engine:load_rules()
Log.debug1('load rules')

local jagen_dir = os.getenv('jagen_dir')
local root_dir = os.getenv('jagen_root_dir')

local jagen = Module:load('jagen', System.mkpath(jagen_dir, 'lib', 'rules.lua'))
local root = Module:load('root', System.mkpath(root_dir, 'rules.lua'))
local jagen_rules = System.mkpath(os.getenv('jagen_dir'), 'lib', 'rules.lua')
local root_rules = System.mkpath(os.getenv('jagen_root_dir'), 'rules.lua')

local jagen = Module:load('jagen', jagen_rules)
append(self.path, jagen:basename(jagen.filename))
append(self.path, root:basename(root.filename))

self:process_module(jagen)
self:process_module(root)

if System.file_exists(root_rules) then
local root = Module:load('root', root_rules)
append(self.path, root:basename(root.filename))
self:process_module(root)
end

local cmake = Command:new('cmake', '--version')
if cmake:exists() then
Expand Down
4 changes: 3 additions & 1 deletion src/System.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ function P.exists(path)
end

function P.file_exists(path)
return P.exec('test -f "%s"', path)
local file = io.open(path, 'r+')
if file then file:close() end
return file ~= nil
end

function P.dir_exists(path)
Expand Down

0 comments on commit ac9e997

Please sign in to comment.