-
Notifications
You must be signed in to change notification settings - Fork 75
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
first attempt at supporting opm build-install
#40
Conversation
bin/opm
Outdated
} | ||
|
||
sub do_build_install () { | ||
=pod |
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.
These comments should be comments instead of POD documentation. Also, they should appear before the sub prototype.
bin/opm
Outdated
my $ini_data = read_ini($dist_file); | ||
my $ini_default_sec = $ini_data->{default}; | ||
my $dist_name = $ini_default_sec->{name}; | ||
my $version = $ini_default_sec->{version}; |
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.
Bad indentation?
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.
We should use 4 space indentation consistently.
bin/opm
Outdated
my $default_sec = $data->{default}; | ||
$account = delete $default_sec->{github_account}; | ||
my ($rc_file, $rc_data) = get_rc_file(); | ||
my $rc_default_sec = $rc_data->{default}; |
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.
Please avoid such unrelated changes. I prefer minimal change sets in each PR. Thank you.
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.
Would you mind if I do a PR first that standardizes the variable names? This was a bit of a headache to unwind, because $data
and $default_sec
would be recycled from the rc file to the ini file.
bin/opm
Outdated
0 = build | ||
1 = server-build | ||
=cut | ||
my $_build_type = shift; |
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.
Please avoid local variable names led by _
.
bin/opm
Outdated
1 = server-build | ||
=cut | ||
my $_build_type = shift; | ||
my $server_build = ($_build_type == 1) ? 1 : 0; |
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.
Please avoid magical numbers in the build type values.
bin/opm
Outdated
if (!$dist_abstract) { | ||
err "$dist_file: key \"abstract\" not found in the default section.\n"; | ||
} | ||
|
||
check_utf8_field($dist_file, 'abstract', $dist_abstract); | ||
|
||
my $repo_link = delete $default_sec->{repo_link}; | ||
my $repo_link = delete $ini_default_sec->{repo_link}; |
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.
Please avoid such unrelated changes. Thank you.
bin/opm
Outdated
} | ||
|
||
|
||
sub install_distribution($$$){ |
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.
Need a space before {
and (
.
bin/opm
Outdated
* do_build_install 0 | ||
* do_remove 0 | ||
* do_upgrade 1 | ||
* do_update 1 |
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.
Remaining this back-reference list is quite a burden. Better avoid it.
I'll work on all the changes tomorrow. Sorry for the whitespace issues, my editor didn't pick up Perl and auto-expand the tabs (it does for .py and .pl files) |
77c9bc7
to
a8bb6db
Compare
I had to do a manual rebase and force-push, but I've got this working again. |
bin/opm
Outdated
opm server-build | ||
install $dist_name-$version.opm.tar.gz # psuedocode | ||
=end comment | ||
=cut |
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.
Better put blank lines around POD directives.
bin/opm
Outdated
$remove_old = 1; | ||
} | ||
|
||
# package_ctx is needed to get the directories right for `install_distribution` |
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.
Bad indentation?
@@ -12,7 +12,7 @@ use File::Find (); | |||
use File::Path qw( make_path ); | |||
use File::Spec (); | |||
use Config (); | |||
use Cwd qw( realpath cwd ); | |||
use Cwd qw( realpath cwd getcwd ); |
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.
Why import getcwd
? Why not just use cwd
?
bin/opm
Outdated
|
||
# phase 2b - `cd ` | ||
my $versioned_directory = "$dist_name-$version"; | ||
chdir $versioned_directory; |
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.
Should check if chdir
fails.
bin/opm
Outdated
# for `build-install`: | ||
# *always* `remove_old` if the `meta_file` exists, regardless of version | ||
# however, `get` will still need to compare version numbers | ||
$remove_old = 1; |
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.
We should use 4-space indentations.
bin/opm
Outdated
This installs a distribution file (.tar.gz) | ||
=end comment | ||
=cut | ||
sub install_distribution($$$) { |
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.
Style: need a space before (
.
@@ -1406,7 +1527,7 @@ sub install_target ($$) { | |||
err "no library files found in $dist_dir/.\n"; | |||
} | |||
|
|||
if ($remove_old) { | |||
if ($package_ctx->{remove_old}) { |
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.
We should avoid such immediate hash table look ups since when there is a typo in the hash table key here, it is hard to detect and debug.
054e796
to
ba45825
Compare
1a8ae86
to
91c2d25
Compare
changed source argument to `install_file`; now a full path (not local) altered `remove_target` to chdir back to the opening directory (not install directory) standardized the directory start logic
91c2d25
to
7e19d31
Compare
Sorry for the delay in response, I was on vacation. I've pushed the changes, and will address everything above here:
Looking at this with some fresh eyes (and a little more familiarity with Perl), in the current changeset I also altered a few things. I didn't quite understand how/why some things originally worked with the chdirs -- but now do (I think) and so I tried to more clearly convey what is going on. The functions now note the "start" directory before chdiring, and then explicitly return to that 'start' directory (instead of the "install" directory). This loosely emulates a context manager, and makes chaining or stacking functions a lot easier. |
@jvanasco Some comments:
|
|
@jvanasco Yes, Perl has similar tools as well. You can dig them up if you like. We do prepare our own static analysis toolsets for OpenResty's C components and Lua components. But not yet for Perl. |
@ktalebian I am closing this PR. There were several changes to OpenResty in the months after I first wrote it, which would have required far too much work to rebase or merge with, and I never had time to revisit this since. someone else will need to create this functionality. |
This is my first attempt at handling #39
I haven't touched Perl in years so apologies in advance.
It seems to work, but there aren't any tests to plug into. I documented new functions inline, and also added docs for existing functions too.
Notes:
The command is invoked as
opm build-install
as it wraps the build process and installs locally (as requested)A new core subroutine of
do_build_install
was created, which handles most of the overall logicbuild-install will always remove an existing version, it will not compare revisions.
Variable names were standardized for easier maintenance:
$rcfile
->$rc_file
(same style as$ini_file
)$data
->$rc_data
,$ini_data
$default_sec
->$rc_default_sec
,$ini_default_sec
I noted what the arguments meant to various subroutines, both when invoked and in the subroutine iteself
I tried to leverage existing code, and am not thrilled with my approach (but it does work)
install_target
was dropped into two routines:install_target
andinstall_distribution
.install_distribution
handles installing the actual distribution file. Most metadata is calculated ininstall_target
ordo_build_install
init_package_ctx
. It's used alongside the existinginit_installation_ctx
, but is limited to the current package info, and mostly used for specifying the cache directory vs the current directory.