-
Notifications
You must be signed in to change notification settings - Fork 307
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
feat: Build system handles dynamic deps first class. #2283
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,44 @@ if [ $(jq "has(\"$REPO\")" $MANIFEST) == "false" ]; then | |
exit 1 | ||
fi | ||
|
||
function addRebuildPatterns { | ||
local TYPE=$(jq -r ".\"$1\".rebuildPatterns | type" $MANIFEST) | ||
if [ "$TYPE" == "string" ]; then | ||
local FILE=$(jq -r ".\"$1\".rebuildPatterns" $MANIFEST) | ||
local BUILD_DIR=$($0 buildDir $1) | ||
PATTERNS=(${PATTERNS[@]} $(cat $BUILD_DIR/$FILE)) | ||
elif [ "$TYPE" == "array" ]; then | ||
PATTERNS=(${PATTERNS[@]} $(jq -r ".\"$1\".rebuildPatterns | .[]" $MANIFEST)) | ||
else | ||
>&2 echo "Missing rebuildPatterns property. Either filename as string, or patterns as array." | ||
function get_deps { | ||
local TYPE=$(jq -r ".\"$1\".dependencies | type" $MANIFEST) | ||
if [ "$TYPE" == "string" ]; then | ||
# Execute string as command relative to buildDir to retrieve dependencies. | ||
local CMD=$BUILD_DIR/$(jq -r ".\"$1\".dependencies") | ||
if [ ! -f "$CMD" ]; then | ||
>&2 echo "Dependency script not found: $CMD" | ||
exit 1 | ||
fi | ||
DEPS=($($CMD $1)) | ||
elif [ "$TYPE" == "null" ]; then | ||
# Execute default script relative to buildDir to retrieve dependencies. | ||
local CMD=$BUILD_DIR/scripts/get_dependencies.sh | ||
if [ ! -f "$CMD" ]; then | ||
>&2 echo "Dependency script not found: $CMD" | ||
exit 1 | ||
fi | ||
DEPS=($($CMD $1)) | ||
elif [ "$TYPE" == "array" ]; then | ||
DEPS=($(jq -r ".\"$1\".dependencies // [] | .[]" $MANIFEST)) | ||
else | ||
>&2 echo "dependencies must be a array, string or null." | ||
exit 1 | ||
fi | ||
} | ||
|
||
function add_rebuild_patterns { | ||
local TYPE=$(jq -r ".\"$1\".rebuildPatterns | type" $MANIFEST) | ||
if [ "$TYPE" == "string" ]; then | ||
local FILE=$(jq -r ".\"$1\".rebuildPatterns" $MANIFEST) | ||
local BUILD_DIR=$($0 buildDir $1) | ||
PATTERNS=(${PATTERNS[@]} $(cat $BUILD_DIR/$FILE)) | ||
elif [ "$TYPE" == "array" ]; then | ||
PATTERNS=(${PATTERNS[@]} $(jq -r ".\"$1\".rebuildPatterns | .[]" $MANIFEST)) | ||
else | ||
>&2 echo "Missing rebuildPatterns property. Either filename as string, or patterns as array." | ||
exit 1 | ||
fi | ||
} | ||
|
||
case "$CMD" in | ||
|
@@ -46,13 +72,15 @@ case "$CMD" in | |
jq -r ".\"$REPO\".projectDir // .\"$REPO\".buildDir" $MANIFEST | ||
;; | ||
dependencies) | ||
BUILD_DIR=$($0 buildDir $REPO) | ||
declare -A ALL_DEPS | ||
add_deps() { | ||
if [[ -v ALL_DEPS[$1] ]]; then | ||
return | ||
fi | ||
ALL_DEPS["$1"]=1 | ||
DEPS=($(jq -r ".\"$1\".dependencies // [] | .[]" $MANIFEST)) | ||
get_deps $1 | ||
# DEPS=($(jq -r ".\"$1\".dependencies // [] | .[]" $MANIFEST)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented out line |
||
for DEP in "${DEPS[@]}"; do | ||
add_deps $DEP | ||
done | ||
|
@@ -65,9 +93,9 @@ case "$CMD" in | |
rebuildPatterns) | ||
DEPS=($($0 dependencies $REPO)) | ||
PATTERNS=() | ||
addRebuildPatterns $REPO | ||
add_rebuild_patterns $REPO | ||
for DEP in "${DEPS[@]}"; do | ||
addRebuildPatterns $DEP | ||
add_rebuild_patterns $DEP | ||
done | ||
printf "%s\n" "${PATTERNS[@]}" | sort | uniq | ||
;; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on this logic being in JS in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd ask, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More scrutable scripting language for most our devs - jq is its own DSL, basically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh. Work for works sake. With chatgpt this took me 5 minutes and 1 line of jq. Glorious!