• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Origen-SDK / origen / 13122641880

30 Jan 2025 06:21PM UTC coverage: 74.921% (-0.02%) from 74.944%
13122641880

push

github

rlaj
Updated app version and history

6674 of 8908 relevant lines covered (74.92%)

2764.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

36.84
/lib/origen/application/workspace_manager.rb
1
module Origen
3✔
2
  class Application
3✔
3
    class WorkspaceManager
3✔
4
      # Returns the directory that contains the current application's revision control
5
      # root (basically just Origen.app.rc.root.parent)
6
      def container_directory
3✔
7
        if Origen.running_on_windows?
6✔
8
          dir = revision_control_root.parent
×
9
          Pathname.new(dir.to_s.sub(/\/$/, ''))
×
10
        else
11
          revision_control_root.parent
6✔
12
        end
13
      end
14

15
      # Returns the path to the root directory of the revision control system
16
      # that is managing the application.
17
      #
18
      # This may not necessarily be Origen.root if the application is embedded within
19
      # a larger project workspace (for example in tool_data/origen)
20
      def revision_control_root
3✔
21
        Origen.app.rc ? Origen.app.rc.root : Origen.root
12✔
22
      end
23

24
      # Origen.root may not necessarily be the same as the revision control root.
25
      # This method will return the relative path from the revision control root to
26
      # Origen.root.
27
      def path_to_origen_root
3✔
28
        path = Origen.root.to_s.sub(revision_control_root.to_s, '').sub(/^(\/|\\)/, '')
×
29
        path = '.' if path.empty?
×
30
        path
×
31
      end
32

33
      # Provides a proposal for where the reference workspace should live
34
      def reference_workspace_proposal
3✔
35
        "#{container_directory}/#{Origen.app.name}_reference"
×
36
      end
37

38
      # Returns the path to the actual reference workspace if it is set,
39
      # otherwise returns nil
40
      def reference_workspace
3✔
41
        if reference_workspace_set?
×
42
          dir = File.readlink(reference_dir)
×
43
          dir.gsub!('.ref', '')
×
44
          dir.gsub!(/#{Regexp.escape(path_to_origen_root)}\/?$/, '')
×
45
          Pathname.new(dir).cleanpath
×
46
        end
47
      end
48

49
      # Returns the path to the directory that will be used to contain
50
      # all imported application workspaces
51
      def imports_directory
3✔
52
        return @imports_directory if @imports_directory
×
53

54
        old = "#{container_directory}/#{revision_control_root.basename}_imports_DO_NOT_HAND_MODIFY"
×
55
        @imports_directory = "#{container_directory}/.#{revision_control_root.basename}_imports_DO_NOT_HAND_MODIFY"
×
56
        FileUtils.rm_rf(old) if File.exist?(old)
×
57
        @imports_directory
×
58
      end
59

60
      # Returns the path to the directory that will be used to contain
61
      # all remotes workspaces
62
      def remotes_directory
3✔
63
        return @remotes_directory if @remotes_directory
6✔
64

65
        old = "#{container_directory}/#{revision_control_root.basename}_remotes_DO_NOT_HAND_MODIFY"
3✔
66
        @remotes_directory = "#{container_directory}/.#{revision_control_root.basename}_remotes_DO_NOT_HAND_MODIFY"
3✔
67
        FileUtils.rm_rf(old) if File.exist?(old)
3✔
68
        @remotes_directory
3✔
69
      end
70

71
      # Returns true if the local reference directory is already
72
      # pointing to an external workspace.
73
      def reference_workspace_set?
3✔
74
        f = reference_dir
×
75
        File.exist?(f) && File.symlink?(f) &&
×
76
          File.exist?(File.readlink(f))
77
      end
78

79
      def set_reference_workspace(workspace)
3✔
80
        f = reference_dir
×
81
        if File.exist?(f)
×
82
          if File.symlink?(f)
×
83
            FileUtils.rm_f(f)
×
84
          else
85
            FileUtils.rm_rf(f)
×
86
          end
87
        end
88
        remote_ref = "#{origen_root(workspace)}/.ref"
×
89
        unless File.exist?(remote_ref)
×
90
          FileUtils.mkdir_p(remote_ref)
×
91
          `touch #{remote_ref}/dont_delete` # Make sure the pop does not blow this away
×
92
        end
93
        if Origen.running_on_windows?
×
94
          system("call mklink /h #{reference_dir} #{remote_ref}")
×
95
        else
96
          File.symlink(remote_ref, reference_dir)
×
97
        end
98
      end
99

100
      # Returns the full path to Origen.root within the given workspace
101
      def origen_root(workspace)
3✔
102
        Pathname.new("#{workspace}/#{path_to_origen_root}").cleanpath
×
103
      end
104

105
      def reference_dir
3✔
106
        "#{Origen.root}/.ref" # Should probably be set by a config parameter
×
107
      end
108

109
      # Builds a new workspace at the given path
110
      def build(path, options = {})
3✔
111
        options = {
112
          rc_url:        Origen.app.config.rc_url || Origen.app.config.vault,
×
113
          allow_rebuild: false
114
        }.merge(options)
115
        if File.exist?(path.to_s) && !options[:allow_rebuild]
×
116
          fail "Sorry but #{path} already exists!"
×
117
        end
118

119
        FileUtils.rm_rf(path.to_s) if File.exist?(path.to_s)
×
120
        rc = RevisionControl.new options.merge(remote: options[:rc_url], local: path.to_s)
×
121
        rc.build
×
122
      end
123

124
      # Switches the given workspace path to the given version tag
125
      def switch_version(workspace, tag, options = {})
3✔
126
        options = {
127
          origen_root_only: false # When true pop the Origen.root dir only instead
128
          # of the whole application workspace - these may or may
129
          # not be the same thing depending on the application.
130
        }.merge(options)
131
        version_file = "#{workspace}/.current_version"
×
132
        FileUtils.rm_f(version_file) if File.exist?(version_file)
×
133
        if options[:origen_root_only]
×
134
          dir = "#{workspace}/#{path_to_origen_root}"
×
135
        else
136
          dir = workspace
×
137
        end
138
        rc_url = Origen.app.config.rc_url || Origen.app.config.vault
×
139
        rc = RevisionControl.new remote: rc_url, local: dir.to_s
×
140
        rc.checkout version: tag, force: true
×
141
        File.open(version_file, 'w') do |f|
×
142
          f.puts tag
×
143
        end
144
      end
145

146
      def current_version_of(workspace)
3✔
147
        f = "#{workspace}/.current_version"
3✔
148
        if File.exist?(f)
3✔
149
          File.readlines(f).first.strip
3✔
150
        end
151
      end
152
    end
153
  end
154
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc