30 Commits
Author SHA1 Message Date
William Douglas 74c0833cf4 Remove ruby, golang and cargo build patterns
These patterns are being removed as they are not used or are going to
be reworked.

This change also removes support for multi-versioned packages which
were considered for go and cargo purposes.

Signed-off-by: William Douglas <william.douglas@intel.com>
2023-03-17 12:14:20 -07:00
Patrick McCarty 11b0d0feac tests: for every package URL, test all content states
The generated packageurl name/version tests were only testing one of
four content states, leading to a gap in test coverage, since some names
or versions might be mis-parsed in a state that was not tested.

Fix the issue by testing all content states for every package URL in the
tests/packageurls file. And ensure that test failure output remains
actionable by using a subTest() context manager and setting the `state`
argument, which will print the value of `state` in the test failure
output header.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2022-04-04 17:31:00 -07:00
William Douglas 38d66d6ae6 Create a new object for multi_version
When not handling a multiple version package, there was a case where if
the version wasn't set the multi_version map would be the
config.versions map and that's not intended to outside of multiple
version use case.

So to fix this, make a new map when setting a default version for the
multi_version map and keep config.versions as its own map.

Signed-off-by: William Douglas <william.douglas@intel.com>
2022-03-02 13:49:35 -08:00
William Douglas 71b7496fbc Fix pecl url builds
The pattern must be passed to the source class to handle pecl archive
files correctly. It would be good to have the configuration files be
loaded before the sources are processed but that's a later work item
and is unlikely to cause problems in this case.

Fixes #617.
2020-04-20 12:35:08 -07:00
William Douglas 0e412270aa Re-organize buildpattern function into config
The buildpattern is a bit of an odd standalone module that was a
vestiage of the pre-refactor days where modules owned global
data. These days are coming to a close so move this data to a more
sensible owner in config.

This resolves #612 though likely more will be done as part of #131.
2020-04-17 13:49:33 -07:00
William Douglas 4f90794393 Move target directory to Config
Many different components require the target download path and it is
needed early. Previously code existed to attempt to autodetect its
location and so defining the path was enforced later in the build
process. This created problems with ordering functions based on this
requirement but since the target path is now certain to be defined at
startup (due to previous changes) we can better align the location and
initialization of the data to the Config class.

As part of this change also avoid requiring the temporary working
directory to be setup as part of the Build class. This is done as a
cleanup due to the only real user of this location being the Content
class.

This also drops the stand-alone pkg_integrety main function that was
initially used as a one off test to avoid needing to run autospec to
validate the integrity of a package. This feature was seldom used and
doesn't function well without handling configuration so it was
dropped.
2020-04-14 14:14:14 -07:00
William Douglas 195b88e0ff Refactor build to remove remaining globals
The build module had a number of globals that were referenced by many
other modules and has ordering dependencies with the config and
tarball module for some values. This made deciding on where certain
values get initialized difficult but before the initialization can be
addressed a refactor is helpful.

This change moves the global state (and functions that needed to act
on that global state) into a Build class. The goal of this work is
to better track what can be updated by a particular function, load
data in a sensible order and have it owned by a sensible component.

Some of this data is likely to be removed from the build class in the
future as initialization of download and base paths should take place
in other modules most likely.
2020-04-01 14:59:44 -07:00
William Douglas ebf0a6988d Refactor tarball to remove remaining globals
The tarball module had a number of globals that were referenced by
many other modules and has ordering dependencies with the config
module for some values. This made deciding on where certain values get
initialized difficult but before the initialization can be addressed a
refactor is helpful.

This change moves the global state (and functions that needed to
act on that global state) into a Content class. The goal of this work
is to better track what can be updated by a particular function, load
data in a sensible order and have it owned by a sensible component.

I expect that future work will see the tarball, buildpattern and some
portions of the config moved around to better match what component
should own what data (and to better deliniate between the data that
has a similar use but comes from different sources).
2020-03-30 13:08:05 -07:00
William Douglas 54636b48dd Refactor the config into a class
The config module had a large amount of globals that were being
touched across many modules that would import. This made changes to
config very fragile as figuring out what would be modified in any
given call chain was difficult to diagnose.

It also made testing fragile as one would need to reset a given
module's config import to the best of their knowledge before rerunning
another test.

To get away from that (and to try and reduce the number of globally
modified variablies in autospec as a whole), refactor the config
module to provide its state as part config class. The long running
goal of changes like this is to better track what content can be
updated by a particular function (if a function would have access
to the config instance is now the hint rather than the config module
getting imported).
2020-03-24 18:05:27 -07:00
Athenas Jimenez 808b7d7224 Consolidate source management in Source class.
This patch consolidates the code that manages the sources
(.zip, .tar, etc) in Source class. This class is written in a way
that allows the reuse of code for all current supported types of
sources and at the same time, it allows the easy addition of new
ones.

Signed-off-by: Athenas Jimenez <athenas.jimenez.gonzalez@intel.com>
2020-02-21 16:15:22 -08:00
Athenas Jimenez d0b3aa3ac5 tarball: Simplify Go packages management.
Add a special archives list (go_archives), so we can remove Go specific
methods and simply make use of regular methods.

Signed-off-by: Athenas Jimenez <athenas.jimenez.gonzalez@intel.com>
2020-01-31 14:07:09 -08:00
Athenas Jimenez 5a4e7e66f9 tarball: Remove extract support for 7zip and gem
Clear is no longer using sources compressed using 7zip or gem.

Signed-off-by: Athenas Jimenez <athenas.jimenez.gonzalez@intel.com>
2020-01-23 13:42:19 -08:00
Athenas Jimenez 798d2a6b0d Refactoring tarball.build_untar()
- Make use of tarfile library
- Update test for this function adding multipl test cases.

Signed-off-by: Athenas Jimenez <athenas.jimenez.gonzalez@intel.com>
2019-11-25 09:57:37 -08:00
Athenas Jimenez e12a7149e8 Refactoring tarball.build_unzip()
- Make use of zipfile library.
- Update test for this function adding multiple test cases.

Signed-off-by: Athenas Jimenez <athenas.jimenez.gonzalez@intel.com>
2019-11-20 11:21:29 -08:00
William Douglas 54fd6e27aa Improve go ecosystem support
Update support for handling go packages by handling missing go
dependencies. Make use of go modules and the go proxy (see
https://tip.golang.org/cmd/go/#hdr-Module_proxy_protocol for more
details on the proxy implementation) to discover what artifacts are
needed.

A new go-dep build_pattern that will package all versions that the
go-proxy finds is also added as part of this change. Additional rework
of the golang build_pattern (and Makefile build_pattern as a number of
go packages use Makefiles) to use module vendoring when module
configuration is detected was added as well.

The new functionality is also intended to be used by a higher level
tool that will wrap autospec calls to build missing dependencies as
well as the requested package.
2019-07-19 15:10:48 -07:00
Brett T. Warden 06819ea152 Update UNZIP_OUT for build_zip unit tests
The actual output of the unzip -q -l commands used in build_zip()
doesn't include the archive name. Removing it from the mock UNZIP_OUT so
unit tests match reality.
2019-05-31 12:46:15 -07:00
Brett T. Warden 4d880499b3 Add unit test for build_un7z 2018-08-28 10:02:18 -07:00
William Douglas 688abd48a7 Enforce zipfile prefix to be valid
Autospec doesn't allow tarfiles to be missing a prefix so the same
should be done for zipfiles.
2018-07-20 12:29:18 -07:00
Matthew Johnson 79246f925a Deprecate Makefile writing
The package metadata is now written to options.conf so the Makefile
writing is no longer needed.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-11-14 10:17:07 -08:00
Brett T. Warden 7fa9e21b83 Add/enhance test cases for giturl
Add test cases for empty/null giturl. Add message to case when regex
fails to match.

Signed-off-by: Brett T. Warden <brett.t.warden@intel.com>
2017-10-26 14:34:08 -07:00
Brett T. Warden 0eb744f788 tarball: de-conflate github repo and package name
For github URLs, capture and identify repo name separately from package
name. This is a building block for resolving cases where the package
name is actually different than the github repo name.

Signed-off-by: Brett T. Warden <brett.t.warden@intel.com>
2017-10-26 14:34:08 -07:00
Brett T. Warden 5132520108 Add test for giturl generation
For github URLs in tests/packageurls, check that we produce a giturl
that looks reasonably correct.

Signed-off-by: Brett T. Warden <brett.t.warden@intel.com>
2017-10-26 14:34:08 -07:00
Matthew Johnson 2552c9786f Move test generators out of name guard
This allows python3 unittest to properly generate the tests when running
all the tests in the tests directory.

Also adds a fix to test_test.py to reset buildpattern.default_pattern
every test. This was a bug introduced by running all tests at once -
this was not being cleared correctly.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-09-26 15:30:34 -07:00
Matthew Johnson ddf7927c3c Update and add to tarball unit tests
Updates include generating an individual test for each url to be tested
instead of doing it all in one test and appending to an error list where
appropriate. This has the benefit of showing failures for each
individual test case in a recognizable manner.

Tests are also added for most of the remaining functions.

These tests do not pass without the accompanying tarball module cleanup
and restructure.
2017-07-13 09:14:45 -07:00
Matthew Johnson 1ecdc45959 Convert name argument from list to string
Due to an 'nargs' specification in the argument parser, the name
argument was being read as a list. The list was then always accessed as
name_argument[0] to access the name. This patch removes the 'nargs'
specifier so name is always a string and removes the logic to parse the
list.

If both version and name arguments exist, set them and skip automated
detection. If one is not set, continue with the automated detection
since the URL parsing for both are done together, override at the end.
2017-04-04 17:30:11 -07:00
Matthew Johnson 872a1d1e12 Add command-line version configuration
Autospec is unable to accurately parse every type of URL for the correct
name and version of the package. When this is the case, the detected
version can be overwritten by the --version argument on the command
line.
2017-04-04 17:30:11 -07:00
Matthew Johnson d497f7e2cb files: general cleanup of module
The files module was being treated like a class, in that it was
necessary to keep state throughout the entire autospec run. Convert the
files module to a class and make some other general clean ups. This
changed how the files module was instantiated and called by the main
autospec module and other modules such as tarball and config.

Test the files module with unit tests and add the target to the
makefile.
2017-03-28 22:35:11 -07:00
Matthew Johnson a0bad7923b Simplify version detection logic
Version detection could be considerably simplified using builtin python
functions such as strip, replace, and list comprehension. The logic was
also modified a bit to provide more consistent version strings
containing only numbers and periods '.'. More unit tested urls were
added to tests.

9.11.0-P1 -> 9.11.0.1
1.0.0-rc1 -> 1.0.0.1
7_4_2     -> 7.4.2
2.1-3     -> 2.1.3

Some non-digit strings are conserved for upstream version update detection:

2.1-beta1 -> 2.1.beta1
2.1-pre8  -> 2.1.pre8
3.5.0b2   -> 3.5.0b2
2017-03-07 13:39:34 -08:00
Matthew Johnson c4a2816cda Improve name/version detection to pass tests
Make several small improvements to package name and version detection.
Unit test now passes for a sampling of >100 package URLs. This patch
also adds several package URLs for testing.

Some of the improvements to name/version detection include:

- Reordering of patterns so specific patterns come first - these are our
  edge cases but they will not be checked if they are at the end of the
  list.
- Add conversion from 7_4_2 formatted versions to the more-common 7.4.2
  format.
- Remove release candidate tag (-rc#) from the end of version tags.
- Remove leading 'r' or 'v' even if it is capitalized.
- Remove package name from beginning of version if present.
2016-12-14 16:52:21 -08:00
Matthew Johnson e0111cc30e Add a unit test for version detection
This unit test reads test cases from tests/packageurls and attempts to
determine the version and name from the url specified. tests/packageurls
defines these cases and their expected results in the format:

<package url>,<expected name>,<expected version>

There are currently some test cases that fail. This unit test will make
it easier to make changes to the tarball.name_and_version() function.
2016-12-14 15:06:35 -08:00