Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
package-renaming
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
François-René Rideau
package-renaming
Commits
08da2b23
Commit
08da2b23
authored
12 years ago
by
Francois-Rene Rideau
Browse files
Options
Downloads
Patches
Plain Diff
Documented an essential limitation to this package, and how to work around it.
parent
407aeb68
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README
+82
-8
82 additions, 8 deletions
README
package-renaming-test.asd
+3
-10
3 additions, 10 deletions
package-renaming-test.asd
package-renaming-test.lisp
+1
-1
1 addition, 1 deletion
package-renaming-test.lisp
with
86 additions
and
19 deletions
README
+
82
−
8
View file @
08da2b23
...
...
@@ -14,19 +14,93 @@ package-names
find-package-from-names
effect-package-renaming
effect-package-renamings
call-with-package-renamings
with-package-renamings
call-with-
effective-
package-renamings
with-
effective-
package-renamings
A typical use would be to use the following in your .asd file:
NB: any kind of package renaming is only safe when package operations
(including any use of the Lisp reader) are single-threaded.
(defun my-renamings (thunk)
(package-renaming:call-with-package-renamings '((:foo (:bar :baz)) (:quux :quuux)) thunk))
(asdf:defsystem blah
:around-compile my-renamings
==== Compile-time renaming via ASDF ====
with-effective-package-renamings and call-with-effective-package-renamings
are pretty low-level primitives that let you do what you need,
but require you to do a lot of the groundwork.
First, an important constraint to understand about building CL software.
By intentional design, ASDF only has an :around-compile hook,
but no :around-load hook around load,
or :around-build hook around both compile and load;
indeed, some implementations that rely on linking, such as ECL or GCL,
might not even allow any kind of useful hook around loading,
and some things one might want to do with fasls
(such as linking or concatenating them together into a big fasl)
might preclude any such hook.
Therefore, whatever renamings you do at compile-time
will NOT be done available at load-time.
When the fasl is loaded, only the non-renamed names are available,
and symbols, stored with the principal name of their package at compile-time,
will be resolved against the set of packages at load-time.
This imposes this important constraint on renamings that are admissible
in ASDF's :around-compile hook:
THE (PRINCIPAL) NAME OF A PACKAGE AS RENAMED AT COMPILE-TIME
*MUST* BE ONE OF THE NAMES OF THAT PACKAGE AT LOAD-TIME.
For instance, if your target package is COM.FOO.BLAH
and has nicknames CFBLAH and BLAH,
then during your rename, the main name of the package must be one of
COM.FOO.BLAH, CFBLAH or BLAH,
or the symbols will fail to resolve properly at load-time.
You can add as many new local nicknames as you want, and use them locally
in your files, you cannot delete all the original names,
and you must use the original names in any operation that will happen
at runtime or load-time, such as defpackage or find-symbol.
Now, if you want to use package-renaming
to locally override a package A with another B,
it is still possible; but you have to use further tricks.
The trick is to somehow ADD a new unique non-clashing nickname
to each of the packages that are involved in a clash,
at some point after they are defined and before they are used by your code.
For instance, give A the nickname A.at.runtime and B the nickname B.at.runtime.
Then, you can make B.at.runtime the principal name
of whatever renaming you make that targets B,
even with local nickname A,
whereas A is previously renamed away to A.at.runtime.
With this constraint in mind,
a typical way to use package-renaming would be
to use the following in your my-system.asd file:
(defsystem my-system
:depends-on (:my-system-meta)
:around-compile "my-system-meta::call-with-renamings"
...)
And in B-renaming.asd:
(defsystem my-system-meta
:depends-on (:package-renaming)
:components ((:file "renamings")))
And in renamings.lisp:
(defpackage :my-system-meta (:use :cl :package-renaming))
(effect-package-renaming
'((:A (:A :A.regular.nick :A.at.runtime))
(:B (:B :B.regular.nick :B.at.runtime))))
(defun with-renamings (thunk)
(call-with-package-renamings
'((:A :A.at.runtime)
(:B :B.at.runtime :A :B.other.nick))
thunk))
That's not all that simple, but at least it's possible.
If you implement an easier all-in-one solution based on this,
I'll happily merge it into this package-renaming.
NB: All this is only safe when package operations are single-threaded.
==== TO DO ====
...
...
This diff is collapsed.
Click to expand it.
package-renaming-test.asd
+
3
−
10
View file @
08da2b23
...
...
@@ -2,21 +2,14 @@
(
asdf:defsystem
:package-renaming-test
:description
"testing package-renaming"
;;
:around-compile "asdf::call-with-package-renaming-test-renamings"
:around-compile
"asdf::call-with-package-renaming-test-renamings"
:depends-on
(
:package-renaming
:hu.dwim.stefil
)
:components
((
:file
"package-renaming-test"
)))
#|
;; Oops, for this to work, we would need to:
;; 1- have an :around-load hook around load
;; so the packages are renamed the same while loading, or
;; 2- have an :around-build hook around both compilation and load,
;; so the packages are renamed the same while both compiling and loading.
;; In any case, the current ASDF hook (as of 2.20) is insufficient. Grrrrrr!
;; IMPORTANT: see the README about the constraints on compile-time renamings.
(
defun
asdf::call-with-package-renaming-test-renamings
(
thunk
)
(
funcall
(
asdf::find-symbol*
'
#:call-with-effective-package-renamings
:package-renaming
)
'
((
:stefil
:stefil.non-dwim
)
(:hu.dwim.stefil :stefil))
(
:hu.dwim.stefil
(
:hu.dwim.stefil
:stefil
))
)
thunk
))
|#
This diff is collapsed.
Click to expand it.
package-renaming-test.lisp
+
1
−
1
View file @
08da2b23
...
...
@@ -8,7 +8,7 @@
(
declaim
(
optimize
(
speed
1
)
(
debug
3
)
(
space
3
)))
(
defsuite*
(
test-suite
:in
root-suite
:in
stefil:
root-suite
;; THIS safely test the package renaming in our .asd
:documentation
"Testing package renaming"
))
(
deftest
test-renaming
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment